[R] PCA prcomp problem
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 9 14:25:02 CET 2004
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
More information about the R-help
mailing list