prcomp(x, retx=T)
The estimates are made via the singular value decomposition of the input x. The standard deviations are the singular values divided by one less than the number of observations.
If ret <- prcomp(dat), then ret$x == dat %*% ret$rotation up to numerical precision.
Principal component analysis is often used as a data reduction technique, sometimes in conjunction with regression. Typically it is advisable to scale the columns of the input before performing the principal component analysis since a variable with large variance relative to the others will dominate the first principal component.
Dillon, W. R. and Goldstein, M. (1984). Multivariate Analysis, Methods and Applications. Wiley, New York.
Johnson, R. A. and Wichern, D. W. (1982). Applied Multivariate Statistical Analysis. Prentice-Hall, Englewood Cliffs, New Jersey.
Mardia, K. V., Kent, J. T. and Bibby, J. M. (1979). Multivariate Analysis. Academic Press, London.
# principal components of the prim4 data prim.pr <- prcomp(prim4) # plot of first and second principal components plot(prim.pr$x[,1], prim.pr$x[,2]) # variance explained by first k principal components cumsum(prim.pr$sdev^2/sum(prim.pr$sdev^2))# scree plot barplot(prim.pr$sdev^2/sum(prim.pr$sdev^2), density=20, ylim=c(0, .8), ylab="fraction of variance explained", xlab="principal component", names=as.character(1:4))