[R] extract prop. of. var in pca

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Fri Jul 8 21:29:25 CEST 2005


On Fri, 8 Jul 2005, K. Steinmann wrote:

> Dear R-helpers,
>
> Using the package Lattice, I performed a PCA.

In my R installation, the function princomp() is contained in the stats
package, not lattice (sic!).

> For example
> pca.summary <- summary(pc.cr <- princomp(USArrests, cor = TRUE))
>
> The Output of "pca.summary" looks as follows:
>
> Importance of components:
>                           Comp.1    Comp.2    Comp.3     Comp.4
> Standard deviation     1.5748783 0.9948694 0.5971291 0.41644938
> Proportion of Variance 0.6200604 0.2474413 0.0891408 0.04335752
> Cumulative Proportion  0.6200604 0.8675017 0.9566425 1.00000000
>
> How can I extract the proportion of variance?

The standard deviations are in
  pc.cr$sdev
(see also ?princomp), thus the variances are the squared values and the
proportions can be computed as
  pc.cr$sdev^2/sum(pc.cr$sdev^2)
and by taking the cumsum() the cumulative proportion can be computed. This
is exactly what the the print method for "summary.princomp" objects does
(see stats:::print.summary.princomp).

Best,
Z

> Since names(pca.summary) or str(pca.summary) do not contain the proportion of
> variance,
> it seems I can not use something similar like pca.summary[[2]]$Comp.1[3].
> I can't see how the values are stored.
>
>
> Thanks in advance.
>
> K. St.
>
> ______________________________________________
> R-help at 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
>




More information about the R-help mailing list