[R] Principal component analysis PCA

Thomas Lumley tlumley at u.washington.edu
Thu Feb 14 22:28:16 CET 2008


On Thu, 14 Feb 2008, SNN wrote:

>
> Thanks for the advice.
>
> I tried to find the cov of my matrix using R and it ran out of memory.

How did you do this? The covariance matrix is only 115x115, so it 
shouldn't run out of memory
   cov(t(code))
should work

If that doesn't work then
   tcrossprod(code)/300000 - tcrossprod(rowMeans(code))
might.

> I am
> not sure how to do double loop to create the covariace matrix?  Also is
> doing prcomp( covariace matrix) the same as finding
> prcomp( original data ,matrix of snps)?

That's the point of the paper behind the EIGENSTRAT software, which is 
worth reading.  The eigenvalues are the same and the eigenvectors are 
related.  One way around gives the left singular vectors of the data 
matrix, the other gives the right singular vectors.


 	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-help mailing list