[R] Using napredict in prcomp

Alain Paquette alain.paquette at gmail.com
Tue Mar 10 22:20:54 CET 2009

Hello all,

I wish to compute site scores using PCA (prcomp) on a matrix with 
missing values, for example:

    Drain    Slope    OrgL
a    4    1    NA
b    2.5    39    6
c    6    8    45
d    3    9    12
e    3    16    4

Where a,b... are sites.
The command
 > pca<-prcomp(~ Drain + Slope + OrgL, data = t, center = TRUE, scale = 
TRUE, na.action=na.exclude)
works great, and from
 > pca$x
I can get site scores, e.g.

                       PC1          PC2          PC3
a          NA           NA           NA
b -2.10475208 -2.315128625 -0.885197753
c  5.01177388 -1.778786252 -0.193285051
d  0.28638602  0.298315086  0.386113799
e -0.58861254  0.089498632 -0.434951813

Easy enough...
But how do I use the "napredict" argument? Is it intended as an argument 
to be used in the prcomp line (as suggested in ?prcomp), or is it to be 
used by itself, to replace NAs in the above site score matrix (which is 
what I really want to do).

Thank you,

Alain Paquette, Ph.D.
alain.paquette at gmail.com

Centre d'étude de la forêt (CEF)
Université du Québec à Montréal

alain.paquette at projettriade.ca

More information about the R-help mailing list