I've just starting using the prcomp function, and I want to be able to extract individual principal components (e.g. PC1, PC2) in vector format. I haven't been able to find any documentation that explains how to do this (or even if it is possible). Any help on the subject would be greatly appreciated. Many thanks Deirdre Toher Teagasc National Food Centre
PCA prcomp problem
2 messages · Deirdre Toher, Brian Ripley
On Tue, 9 Nov 2004, Deirdre Toher wrote:
I've just starting using the prcomp function, and I want to be able to extract individual principal components (e.g. PC1, PC2) in vector format. I haven't been able to find any documentation that explains how to do this (or even if it is possible). Any help on the subject would be greatly appreciated.
Depends of course what you mean: do you want the coefficients or the data predicted onto principal components? The coefficients are component `rotation' of the result (see the help page). Projections onto the PCs is component `x' of the result (see the help page). E.g. fit <- prcomp(USArrests, scale = TRUE, ret.x = TRUE) PC1 <- fit$x[, 1] PC2 <- fit$x[, 2] OR predict(fit) gives the projections of old (or new, with newdata) data onto the PCs.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595