关于pca
# Load the base dataset attitude to work with.
data(attitude)
# Compute eigenvalues and eigenvectors of the correlation matrix.
pfa.eigen<-eigen(cor(attitude))
# Print and note that eigenvalues are those produced by SPSS.
# Also note that SPSS will extract 2 components as eigenvalues > 1 = 2
pfa.eigen$values
# set a value for the number of factors (for clarity)
factors<-2
# Extract and transform two components.
pfa.eigen$vectors [ , 1:factors ]
%*%
diag ( sqrt (pfa.eigen$values [ 1:factors ] ),factors,factors )
#下面一行是构建一个对角矩阵factors个行factors个列
评论