PCA in R: How to Determine the Contribution of Each Variable to a PC Score
I am doing PCA in R as shown below.
# Load data
data(mtcars)
# Run PCA
car.pca <- prcomp(mtcars, scale = TRUE, center = TRUE)
I get PC estimates for each car using car.pca$x
. So, for example, I know that for a Mazda RX4, the PC1 value is -0.6468627420. I would like to know how can I calculate the contribution of each variable to reaching this value? I know it car.pca$rotation
will give me variable loads. So I expect something like mtcars[1,] * car.pca$rotation[, 1]
to work (i.e. PC1 loads times data for Mazda RX4), however I don't think this will account for the fact that the data has been centered and scaled using the function prcomp
. How will I do the calculation when considering centering and scaling?
source to share