[R] Principal Component Analysis
Sarah Goslee
sarah.goslee at gmail.com
Wed Feb 29 16:01:07 CET 2012
Hi,
On Wed, Feb 29, 2012 at 9:52 AM, Blaz Simcic <blazsimcic at yahoo.com> wrote:
> Dear R buddies,
> I’m trying to run Principal Component Analysis, package
> princomp: http://stat.ethz.ch/R-manual/R-patched/library/stats/html/princomp.html.
I'm going to assume you actually mean the princomp() function.
> My question is: why do I get different results with pca =
> princomp (x, cor = TRUE) and pca = princomp (x, cor = FALSE) even when I
> standardize variables in my matrix?
Because you didn't use the standardization that's used in princomp, most likely,
but you don't include reproducible code so it's impossible to actually
answer your
question. Look at this for ideas, though. Using scale() is equivalent
to using cor=TRUE.
> data(iris)
> iris.pcaCOR <- princomp(iris[,1:4], cor=TRUE)
> iris.pcaSCALE <- princomp(scale(iris[,1:4]), cor=TRUE)
>
> summary(iris.pcaCOR)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4
Standard deviation 1.7083611 0.9560494 0.38308860 0.143926497
Proportion of Variance 0.7296245 0.2285076 0.03668922 0.005178709
Cumulative Proportion 0.7296245 0.9581321 0.99482129 1.000000000
> summary(iris.pcaSCALE)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4
Standard deviation 1.7083611 0.9560494 0.38308860 0.143926497
Proportion of Variance 0.7296245 0.2285076 0.03668922 0.005178709
Cumulative Proportion 0.7296245 0.9581321 0.99482129 1.000000000
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list