[R] prcomp eigenvalues
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Wed Aug 3 04:56:52 CEST 2005
Rebecca Young wrote:
> Hello,
>
> Can you get eigenvalues in addition to eigevectors using prcomp? If so how?
> I am unable to use princomp due to small sample sizes.
> Thank you in advance for your help!
> Rebecca Young
>
Hi, Rebecca,
From ?prcomp:
The calculation is done by a singular value decomposition of the
(centered and possibly scaled) data matrix, not by using 'eigen'
on the covariance matrix. This is generally the preferred method
for numerical accuracy. ...
So you can get the singular values, but not the eigenvalues. You could
use ?princomp if you really want the eigenvalues. In either case, you
read the code to see how this is done.
x <- matrix(rnorm(1000), 100, 10)
# eigenvalues
v <- cov.wt(x)
ev <- eigen(v$cov * (1 - 1/v$n.obs), symmetric = TRUE)$values
ev[ev < 0] <- 0
princomp(x)$sdev
sqrt(ev)
# singular values
sv <- svd(scale(x, center = TRUE, scale = FALSE), nu = 0)
prcomp(x)$sdev
sv$d/sqrt(max(1, nrow(x) - 1))
HTH,
--sundar
More information about the R-help
mailing list