I was assuming you had the data in my earlier reply. You could also look at the covmat= argument in princomp():
# Create some random data > set.seed(42) > dat <- mapply(rnorm, n=rep(100, 5), mean=(1:5)*5, sd=1:5) # Construct covariance and correlation matrices > dat.cov <- cov(dat) > dat.cor <- cor(dat) # Covariance matrix > dat.cov.pca <- princomp(covmat=dat.cov) > dat.cov.pca$loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 [1,] 0.997 [2,] -0.994 [3,] 0.269 -0.958 [4,] -0.220 -0.941 -0.253 [5,] -0.973 0.200 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 SS loadings 1.0 1.0 1.0 1.0 1.0 Proportion Var 0.2 0.2 0.2 0.2 0.2 Cumulative Var 0.2 0.4 0.6 0.8 1.0 # Correlation matrix > dat.cor.pca <- princomp(covmat=dat.cor) > dat.cor.pca$loadings Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 [1,] -0.453 -0.486 0.234 0.619 0.348 [2,] 0.262 -0.193 0.851 -0.409 [3,] 0.279 0.691 0.313 0.374 0.455 [4,] -0.559 0.159 0.351 -0.629 0.377 [5,] -0.579 0.472 0.281 -0.602 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 SS loadings 1.0 1.0 1.0 1.0 1.0 Proportion Var 0.2 0.2 0.2 0.2 0.2 Cumulative Var 0.2 0.4 0.6 0.8 1.0 ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Wednesday, November 9, 2016 10:58 AM To: T.Riedle Cc: R-help@r-project.org Subject: Re: [R] prcomp() on correlation matrix Well, it seems you can't -- prcomp() seems to want the data matrix. But it would be trivial using svd() -- or possibly even eigen() -- if you understand the underlying linear algebra. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Nov 9, 2016 at 4:45 AM, T.Riedle <tr...@kent.ac.uk> wrote: > Dear R users, > > I am trying to do a Principal Components Analysis using the prcomp() function > based on the correlation matrix. How can I determine to calculate PCA on a > correlation or covariance matrix using prcomp()? > > > Thanks in advance. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.