Marc,

I see no danger. When you predict with 'newdata', that 'newdata' should have no influence on the original PCA. You can use predict(..., newdata) for cross validation.  If you look at the code of stats:::predict.prcomp, you see that the prediction is only (i) scaling and centring your new data with the means and scale of the original data, and (ii) rotation of these scaled values to the original PCs. This is the last line of stats:::predict.prcomp:

scale(newdata, object$center, object$scale) %*% object$rotation

The PCA result 'object' saves the original 'center' and 'scale' (which can be FALSE or SD of variables) of your original variables, and applies those to your 'newdata' before rotating to PCs.

Cheers, Jari Oksanen
________________________________
From: Marc Taylor [marchtaylor@gmail.com]
Sent: 23 May 2012 11:55
To: Jari Oksanen
Cc: r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] PCA as a predictive model

Hi Jari - one more question if you don't mind. Since the weights of the PCs are related to the the amount of variance that they explain in the original data - is it problematic to predict the PC scores with a second data set that has a different amount of variance (e.g. due to differing number of samples)? In both the 1st and 2nd data sets I have been using scaled values for the variables (mean=0 and sd=1 for each sample).
Cheers,
Marc


On Wed, May 23, 2012 at 9:59 AM, Marc Taylor <marchtaylor@gmail.com<mailto:marchtaylor@gmail.com>> wrote:
Hi Jari,

That's good to hear - I hadn't made the connection to cca/rda. This will help me find pertinent literature as well.

Many thanks,
Marc


On Wed, May 23, 2012 at 9:33 AM, Jari Oksanen <jari.oksanen@oulu.fi<mailto:jari.oksanen@oulu.fi>> wrote:
Marc,

Basic R stats functions like prcomp have a predict method that can be used to "predict" (calculate) scores with 'newdata'. This is standard, and has been in R for ever. Most textbooks of multivariate analysis should handle this issue.

In community ecological context, see functions predict.cca and predict.rda in vegan. These take argument 'newdata' which can be new community data -- depending on what you want to predict (argument 'type'). Function calibrate.cca documented in the same help page can be used to predict values of constraining variables in constrained ordination (CCA, RDA) from community composition, also with 'newdata' communities.

Cheers, Jari Oksanen

________________________________________
From: r-sig-ecology-bounces@r-project.org<mailto:r-sig-ecology-bounces@r-project.org> [r-sig-ecology-bounces@r-project.org<mailto:r-sig-ecology-bounces@r-project.org>] on behalf of Marc Taylor [marchtaylor@gmail.com<mailto:marchtaylor@gmail.com>]
Sent: 23 May 2012 10:19
To: r-sig-ecology@r-project.org<mailto:r-sig-ecology@r-project.org>
Subject: [R-sig-eco] PCA as a predictive model

Hello R-sig-ecology group,

I was wondering if anyone is aware of an example where PCA is used as a
predictive model? A community analysis example might be to predict the PC
values of a sample given its community composition. I had thrown this
question up on a statistics forum (
http://stats.stackexchange.com/questions/28916/can-empirical-orthogonal-function-eof-analysis-be-used-as-a-predictive-model)
but have gotten hardly any response. I imagined that there are some folks
here that would have some insight into this problem.

Many thanks,
Marc

       [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org<mailto:R-sig-ecology@r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



	[[alternative HTML version deleted]]

