This is an example for PCA(Principal Component Analysis) with R program.
Randomly generating samples followed normal distribution
x1=rnorm(25, mean=5, sd=1) # create 25 samples followed normal distribution
x2=rnorm(25, mean=5, sd=1) # create 25 samples followed normal distribution
x3=x1+x2 # x3 is a linear combination with x1 and x2
x4=3*x1+2*x2 # x4 is a linear combination with x1 and x2
Y = data.frame(x1, x2, x3, x4)
head(Y)
## x1 x2 x3 x4
## 1 2.851685 3.655225 6.506910 15.86551
## 2 5.203775 5.084123 10.287898 25.77957
## 3 3.738282 5.598599 9.336882 22.41205
## 4 5.513047 3.553016 9.066063 23.64517
## 5 4.272709 4.991327 9.264036 22.80078
## 6 6.318924 4.673949 10.992872 28.30467
Since x3 and x4 are both linear combinations with x1 and x2, the rank of matrix Y will be 2.
That is, we can expect that the number of eigenvalues for Y is 2.
# PCA
PCA = prcomp(Y, cor=TRUE)
# Eigenvalues
PCA$sdev^2
## [1] 2.039483e+01 1.236666e+00 1.423426e-30 1.703155e-31
# Eigenvectors
head(PCA$rotation)
## PC1 PC2 PC3 PC4
## x1 0.2022702 -0.55859462 -0.34745288 0.7254897
## x2 0.1478756 0.79069061 0.05082732 0.5919103
## x3 0.3501457 0.23209599 -0.84738773 -0.3247514
## x4 0.9025617 -0.09440263 0.39828020 -0.1335794
summary(PCA)
## Importance of components:
## PC1 PC2 PC3 PC4
## Standard deviation 4.5161 1.11205 1.193e-15 4.127e-16
## Proportion of Variance 0.9428 0.05717 0.000e+00 0.000e+00
## Cumulative Proportion 0.9428 1.00000 1.000e+00 1.000e+00
(Additional)
The difference between prcomp and princomp():
http://stats.stackexchange.com/questions/20101/what-is-the-difference-between-r-functions-prcomp-and-princomp