Re: [R] prcomp eigenvalues

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Wed 03 Aug 2005 - 12:56:52 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 03 13:01:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:39 EST