基于 group/class 的 PCA 特征贡献

Contributions of features in PCA based on group/class

我想 get/plot 每种葡萄酒的特征贡献 class(barolo、grignolino、barbera)。使用 fviz_contrib 我得到了所有 classes 的贡献,如下面的 MWE 所示。 但是我想知道是否以及如何 calculate/plot 它们分别由 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)

如果您分别计算每个 class 的主成分分析:

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)