0
votes

I'm working with prcomp() function in R. I was wondering if there is any easy way to see variables contribution for each principal components.

Or, if prcomp isn't designed for that, which pca analysis (or pca "like") I can use to answer this question:

Which variables in the raw data are the most discriminant?

How to see the contribution of raw data variables in all principal components

Or, for each principal components:

PC1 = Var55 + Var2000 ( or 78% Var55 + 22% Var2000)
PC2 = Var19 + Var32 + Var45
PC3 = ...
1
Have you check the summary for the prcomp output? e.g. pc1 <- prcomp(USArrests); summary(pc1)Adam Quek
Did you check the $loadings attribute of your model?tushaR
There is no $loading from prcomp() returned list.Olorin.G
summary(pc1) only give standard deviation for each principal components, which doesn't answer my questionOlorin.G
colSums(abs(pc1$rotation)) might give you some idea. (summary also gives the rotations.)Axeman

1 Answers

0
votes

As @Axeman mentioned, you can look at the rotation

if you have this PCA:

pcaRes <- prcomp(df, scale. = TRUE)

Then, look at the rotations

loadings <- pcaRes$rotation

This should show how the variables contribute to the PCA axes. e.g., negative values indicate negative relationship.

If you want the relative contribution of each variable, you can sum the total loadings for each PC axis (use absolute value for negatives) then divide each value with the column sum

#You can do this quick and dirty way
t(t(abs(loadings))/rowSums(t(abs(loadings))))*100

# or this sweet function
sweep(x = abs(loadings), MARGIN = 2, 
  STATS = colSums(abs(loadings)), FUN = "/")*100