Re: [R] prcomp eigenvalues

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed 03 Aug 2005 - 17:01:48 EST

The eigenvalues are the squares of the singular values (although you need to watch the scalings used, in particular n vs n-1). (This is standard theory.)

Since both are non-negative, given one you can get the other.

On Tue, 2 Aug 2005, Sundar Dorai-Raj wrote:

>
>
> 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
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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 17:07:13 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:02:16 EST