I have been able to calculate covariance for my large data set with:
cov(MyMatrix, use="pairwise.complete.obs",method="pearson")
This provided the covariance table I was looking for, as well as dealing with the NA issues that are throughout my data. For a deeper analysis, however, I want to create covariance matrices that deal separately with the 800+ groups I have in my data set (some have 40+ observations, others only 1). I tried (from http://www.mail-archive.com/[email protected]/msg86328.html):
lapply(list(cov), by, data = MyMatrix[8:13], INDICES = MyMatrix["Group"])
Which gave me the following error:
Error in tapply(seq_len(6L), list(
MyMatrix["Group"]= NA_real_), function (x) : arguments must have same length
This made me think the issue with the code involved the missing NA data, so I tried incorporating the "use="pairwise.complete.obs",method="pearson"" phrase into the lapply code and can't get it to work. I'm not sure the best place for it, so I tried sticking it everywhere:
lapply(list(cov), use="pairwise.complete.obs",method="pearson"),by,data=MyMatrix[8:13], INDICES = MyMatrix["Group"])
lapply(list(cov),by,data=PhenoMtrix[8:13], INDICES = PhenoMtrix["Group"], use="pairwise.complete.obs",method="pearson")
This is obviously sloppy and doesn't work, so I'm a little stuck. Thanks in advance for your help!
My data is formatted as such:
Group HML RML FML TML FHD BIB
1 323.50 248.75 434.50 355.75 46.84 NA 2 NA 238.50 441.50 353.00 45.83 277.0 2 309.50 227.75 419.00 332.25 46.39 284.0