[R] question about Principal Component Analysis in R?

From: Michael <comtech.usa_at_gmail.com>
Date: Mon 27 Feb 2006 - 20:00:06 EST


Hi all,

I am wondering in R, suppose I did the principal component analysis on training data set and obtain the rotation matrix, via:

> pca=prcomp(training_data, center=TRUE, scale=FALSE, retx=TRUE);

Then I want to rotate the test data set using the

> d1=scale(test_data, center=TRUE, scale=FALSE) %*% pca$rotation;
> d2=predict(pca, test_data, center=TRUE, scale=FALSE);

these two values are different

> min(d2-d1)

[1] -1.976152
> max(d2-d1)

[1] 1.535222

However, if I do these on the training data:

> d1=scale(training_data, center=TRUE, scale=FALSE) %*% pca$rotation;
> d2=predict(pca, training_data, center=TRUE, scale=FALSE);
> d3=pca$x;

Then the d1, d2, d3 are all the same...


So now I am confused... why does the test data have two different rotated matrix value?

Thanks a lot!

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Feb 27 20:10:09 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:45 EST