[R] vector length help using prcomp

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Apr 4 17:32:34 CEST 2010



On 02.04.2010 23:37, JRsalvelinus wrote:
>
> Hi
>
> I am doing PCA using prcomp and when I try to get predicted values for the
> different PC's the number of data points is always one less than in my
> original data set.  This is a problem because it prevents me from doing any
> post-hoc analysis due to the fact that my dependent variables are one entry
> longer than my PC's.  I have checked for missing data to see if it is
> omitting any but it is not.  It seems like it is always omitting the first
> data point because the output for the predicted PC values always starts at 2
> not 1.  Other than that the results of the analysis make sense and it
> appears to be working correctly.
>
> If anyone has any idea why this may be happening I would appreciate some
> help.
>
> This is the script I am using.
>
> chemPR1<- prcomp(~ ANC + color + CA + pH + TP + volume + maxdepth +
> meandepth + elevation
> + surface + shoreline + littoral , center = TRUE, scale=TRUE, scores=TRUE,
> cor=TRUE)
>
> PC1<-(predict(ALSC1)[,1])

We do not have the data, hence cannot reproduce your problem. I suspect 
you are storing the prcomp results in object chemPR1 but really running 
the predict() step on the ALSC1 object which does not only differ by name?

Uwe Ligges



> Thanks.
>
> Jason



More information about the R-help mailing list