I have a dataframe that represents the correlation matrix of a large data set:

> data
   V1    V2    V3    V4    V5    V6    V7    V8
1 1.000 0.846 0.805 0.859 0.473 0.398 0.301 0.382
2 0.846 1.000 0.881 0.826 0.376 0.326 0.277 0.415
3 0.805 0.881 1.000 0.801 0.380 0.319 0.237 0.345
4 0.859 0.826 0.801 1.000 0.436 0.329 0.327 0.365
5 0.473 0.376 0.380 0.436 1.000 0.762 0.730 0.629
6 0.398 0.326 0.319 0.329 0.762 1.000 0.583 0.577
7 0.301 0.277 0.237 0.327 0.730 0.583 1.000 0.539
8 0.382 0.415 0.345 0.365 0.629 0.577 0.539 1.000

I want to do principal component analysis using the princomp() in {stats} I tried reading the documentation available, and got:

myPCA <- princomp(~V1+V2+V3+V4+V5+V6+V7+V8, data=data, covmat=data)

But this does not do anything different than when I left off the last argument. Please advise on the correct way to use the princomp() parameters.

有帮助吗?

解决方案

You may want to try using the principal function under psych package. https://personality-project.org/r/html/principal.html.

Below is an excerpt from http://www.statmethods.net/advstats/factor.html

 # Principal Axis Factor Analysis
 library(psych)
 fit <- principal(mydata, nfactors=5, rotate="varimax")
 fit # print results

mydata can be a raw data matrix or a covariance matrix.

其他提示

You might consider using the eigen function, which will produce both the eigenvalues of the correlation matrix (equivalent to the squares of the sdevs produced by princomp) as well as the eigenvectors (equivalent to the loadings produced by princomp).

The call would simply be:

myPCA <- eigen(data)
myPCA$values
myPCA$vectors
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top