0

I would like to get/plot the contribution of the features for each type of wine class(barolo, grignolino, barbera). With fviz_contrib I get the contribution over all classes, as shown in the MWE below. However I was wondering if and how it is possible to calculate/plot them individually filtered by classes/groups.

library(ggbiplot)
library(factoextra)

data(wine)

wine.pca <- prcomp(wine, scale. = TRUE)

# plot the PCA 
print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))

# plot the contributions of the features for all wine classes
g.contr <- fviz_contrib(wine.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
raumkundschafter
  • 429
  • 1
  • 8
  • 24

1 Answers1

0

If you calculate the pca for each class separatly:

barolo.pca <- prcomp(wine[wine.class=="barolo", ], scale. = TRUE)
grignolino.pca <- prcomp(wine[wine.class=="grignolino", ], scale. = TRUE)
barbera.pca <- prcomp(wine[wine.class=="barbera", ], scale. = TRUE)
# plot the contributions of the features for each wine classes

g.contr <- fviz_contrib(barolo.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)

g.contr <- fviz_contrib(grignolino.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)

g.contr <- fviz_contrib(barbera.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)
timat
  • 1,480
  • 13
  • 17
  • Thanks for your quick response @timat. Your indication reassemble my first intuition. However afaik this methods results in each having a own PCA space. They therefore are not reflecting the values from the 'original' PCA space based on all 3 groups, which in my particular case is of importance. – raumkundschafter Nov 01 '16 at 16:51
  • @sesselastronaut I don't understand what information you are looking for, and how to interpret it..As I understand the notion of contribution is link directly to the whole "PCA space", I don't think it mathematiccaly possible to filter this distribution.Won't make sens for me – timat Nov 01 '16 at 17:19
  • Indeed you're right. Got someone explaining it to me yesterday. – raumkundschafter Nov 02 '16 at 10:46
  • @sesselastronaut mark it as resolved or delete the question then – timat Nov 09 '16 at 13:45