Thursday, March 26, 2009

R语言主成份分析(Principal Component Analysis)语句

predata = read.table("file", header=TRUE) #读入数据文件,若无header,则header=FALSE

data = scale(data, center = TRUE, scale = TRUE)
#若只标准化不中心化,则为center = FALSE, scale = TRUE, vice versa

R commands for PCA

Here are some R commands for PCA

pcdat = princomp(data) - It does actual job and put the results to pcdat. It will use covariance matrix

pcdat = princomp(data,cor=TRUE) - It will use correlation matrix

summary(pcdat) - It will print standard deviation and proportion of variances for each component

screeplot(pcdat) - It will plot screeplt

biplot(pcdat) or biplot.princomp(pcdat,scale=1) - It will give you biplot

loadings(pcdat) - it will give information how much each variable contribute to each component. For principal components you can ignore loading subsection of the output from this command

pcdat$scores - It will plot scores of each observation for each variable

For further details about this and other R commands type

help.start()

No comments:

Post a Comment