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
另外,还有一个专门作PCA分析的包:
pcaMethods
函数介绍
下面这一段来自 CRAN Task View: Chemometrics and Computational Physics
http://cran.r-project.org/web/views/ChemPhys.html
Principal Component Analysis
* Principal component analysis (PCA) is in the package stats as functions princomp(). Some graphical PCA representations can be found in the psy package.
* The homals package provides nonlinear PCA and, by defining sets, nonlinear canonical correlation analysis (models of the Gifi-family).
* A desired number of robust principal components can be computed with the pcaPP package. The package elasticnet is applicable to sparse PCA. The package fpca can be applied to restricted MLE for functional PCA.
* See the Multivariate task view for further packages dealing with PCA and other projection methods.
下面这一段来自:
http://cran.r-project.org/web/views/Multivariate.html
Principal components: these can be fitted with prcomp() (based on svd(), preferred) as well as princomp() (based on eigen() for compatibility with S-PLUS) from stats. sca provides simple components. pc1() in Hmisc provides the first principal component and gives coefficients for unscaled data. Additional support for an assessment of the scree plot can be found in nFactors, whereas paran provides routines for Horn's evaluation of the number of dimensions to retain. pcurve provides Principal Curve analysis and visualisation as well as a further principal component method. For wide matrices, gmodels provides fast.prcomp() and fast.svd(). kernlab uses kernel methods to provide a form of non-linear principal components with kpca(). pcaPP provides robust principal components by means of projection pursuit. amap provides further robust and parallelised methods such as a form of generalised and robust principal component analysis via acpgen() and acprob() respectively. Further options for principal components in an ecological setting are available within ade4 and in a sensory setting in SensoMineR. psy provides a variety of routines useful in psychometry, in this context these include sphpca() which maps onto a sphere and fpca() where some variables may be considered as dependent as well as scree.plot() which has the option of adding simulation results to help assess the observed data. PTAk provides principal tensor analysis analagous to both PCA and correspondence analysis. smatr provides standardised major axis estimation with specific application to allometry.