Coder Social home page Coder Social logo

Ex. 14.15 about esl-cn HOT 3 CLOSED

szcf-weiya avatar szcf-weiya commented on August 23, 2024
Ex. 14.15

from esl-cn.

Comments (3)

szcf-weiya avatar szcf-weiya commented on August 23, 2024

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!!

from esl-cn.

szcf-weiya avatar szcf-weiya commented on August 23, 2024

而对于因子分析,我们有

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

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

from esl-cn.

szcf-weiya avatar szcf-weiya commented on August 23, 2024

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

from esl-cn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.