比较PCA I的每组的质心向量,寻找计算每个PC和组的质心的方法。不是特别的图形,而是在MWE中包含一个图表,使其更具描述性。
library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, center = TRUE, scale. = TRUE)
print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))
答案 0 :(得分:1)
此示例提供了一个数据框,其中包含来自PCA的质心坐标,然后可用于计算PC内质心之间的距离
library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, center = TRUE, scale. = TRUE)
df.wine.x <- as.data.frame(wine.pca$x)
df.wine.x$groups <- wine.class
pca.centroids <- aggregate(df.wine.x[,1:13], list(Type = df.wine.x$groups), mean)
前两个PC的barolo和grignolino之间的欧氏距离可以计算如下:
dist(rbind(pca.centroids[pca.centroids$Type == "barolo",2:3],pca.centroids[pca.centroids$Type == "grignolino",2:3]), method = "euclidean")