Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex. 14.15 #50

Closed
szcf-weiya opened this issue Jan 20, 2018 · 3 comments
Closed

Ex. 14.15 #50

szcf-weiya opened this issue Jan 20, 2018 · 3 comments
Labels
exercise FA Factor Analysis PCA principal component analysis and principal component regression solved
Milestone

Comments

@szcf-weiya
Copy link
Owner

selection_560

@szcf-weiya
Copy link
Owner Author

szcf-weiya commented Jan 20, 2018

R代码如下

N = 200
X1 = rnorm(N)
X2 = X1 + 0.001*rnorm(N)
X3 = 10*rnorm(N)
X = cbind(X1, X2, X3)
X.pca = princomp(X)
summary(X.pca)

结果为
selection_559
从上述结果可以看出,前两个主成分便解释了所有的方差。
我们有两种方式得到主成分,一种是直接对协方差矩阵进行分解:

Sigma = cov(X)
eigen(Sigma)

结果为
selection_561
可以看出第一主成分为X3,第二主成分为-0.707(X1+X2)
另一种是

loadings(X.pca)

结果为
selection_562
同样得出第一主成分为X3
PNG image
PNG image
the proportion of explained variance can be calculated as

> lambdas = c(100, 1 + (0.001^2 + sqrt(0.001^2 + 4)) / 2, 1 + (0.001^2 - sqrt(0.001^2 + 4)) / 2)
> lambdas
[1] 1.000000e+02 2.000001e+00 3.750000e-07
> cumsum(lambdas) / sum(lambdas)
[1] 0.9803921 1.0000000 1.0000000

same with the above simulation!!

@szcf-weiya
Copy link
Owner Author

szcf-weiya commented Jan 20, 2018

而对于因子分析,我们有

library(psych)
X.fa = fa(X)
loadings(X.fa)

selection_563
可以看出,第一因子取X1+X2,而直接忽略了X3
PNG image
PNG image
PNG image

@szcf-weiya szcf-weiya added this to the Solutions 14 milestone Mar 23, 2018
@szcf-weiya szcf-weiya added PCA principal component analysis and principal component regression FA Factor Analysis labels Apr 28, 2018
@szcf-weiya
Copy link
Owner Author

Related discussion of PCA on the covariance or correlation can be found in https://stats.stackexchange.com/questions/53/pca-on-correlation-or-covariance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exercise FA Factor Analysis PCA principal component analysis and principal component regression solved
Projects
None yet
Development

No branches or pull requests

1 participant