[R] simple (NEWBIE) question re: prcomp or princomp
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sat Dec 2 07:33:43 CET 2000
On Fri, 1 Dec 2000, Oy Leuangthong wrote:
> I am a new user of R, and apologize beforehand for the simplistic
nature of this question:
> I ran prcomp on a data set with 4 variables, and am able to see
the summary information (variance contribution, rotation matrix,
plots, etc.). However, I'd also like to extract the actual values of
the principal components (PC) corresponding to each sample. I've
looked in the help, on-line manuals, FAQs, archived e-mails from
this list, but have been unsuccessful in finding the solution.
They are component `x' of the result, if retx is true (the default).
It is in the help. One problem might be what you mean by the PCs:
variously people mean the coefficients, the rotated basis or the
projection onto the rotated basis, and (see below) what you do about
centring and scaling.
For princomp, just use the predict method. In general, I suggest using
princomp not prcomp.
> Alternatively, I saved the prcomp output to an ascii file, and
then used the rotation matrix out of R and calculated the
principal components in Excel... but these values do not match the
prcomp output (at least the series of values that I assume are the PC values).
You need to centre the data (remove the means) first. The rotation is
about the overall mean.
> If someone could shed some light, I'd greatly appreciate it.
> Thanks in advance.
> Oy Leuangthong
> Department of Civil & Environmental Engineering
> University of Alberta
> (780) 492-3337
> oy at ualberta.ca
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help