Jase Villam Jase Villam - 1 year ago 274
R Question

How to reverse PCA in prcomp to get original data

I want to reverse the PCA calculated from prcomp to get back to my original data.

I thought something like the following would work:

pca$x %*% t(pcal$rotation)

but it doesn't.

The following link shows how to get back the original data from PCs, but explains it only for PCA using eigen on the covariance matrix

prcomp doesn't calcluate PCs that way.

"The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix." -prcomp

Answer Source

prcomp will center the variables so you need to add the subtracted means back

t(t(pca$x %*% t(pca$rotation)) + pca$center)

If pca$scale is TRUE you will also need to re-scale

t(t(pca$x %*% t(pca$rotation)) * pca$scale + pca$center)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download