Skip to content
Prev 65238 / 398506 Next

Reconstructing Datasets

On Tue, 2005-03-01 at 20:30 +0000, Laura Quinn wrote:
It's not in the R help, but in the books about PCA in help references. 

This can be done, not quite directly. Most of the hassle comes from the
centring, and I guess in your case, from scaling of the results. I guess
it is best to first scale the results like PCA would do, then make the
low-rank approximation, and then de-scale:

x <- scale(x, scale = TRUE)
pc <- prcomp(x)

Full rank will be:

xfull <- pc$x %*% pc$rotation

The eigenvalues already are incorporated in pc$x, and you don't have to
care about them.

Then rank=3 approximation will be:

x3 <- pc$x[,1:3] %*% pc$rotation[,1:3]

Then you have to "de-scale":

x3 <- sweep(x3, 2, attr(x, "scaled:scale", "*")
x3 <- sweep(x3, 2, attr(x, "scaled:center", "+")

And here you are. I wouldn't call this a smoothing, though.

Library 'vegan' can do this automatically for PCA run with function
'rda', but there the scaling of raw results is non-conventional (though
"biplot").

cheers, jari oksanen