PCA space 和 'feature-space' 中的质心距离计算发散

Centroid distance calculation in PCA space and in 'feature-space' diverge

我正在测量跨越约 20 个处理和 3 个组的 PCA-space 和 'feature-space' 的质心。如果我正确理解我的数学老师,他们之间的距离应该是相同的。然而,在我计算它们的方式中,它们不是,我想知道我计算的方式是否有误。

我使用臭名昭著的葡萄酒数据集作为我的例子method/MWE:

library(ggbiplot)
data(wine)
treatments <- 1:2 #treatments to be considerd for this calculation
wine.pca <- prcomp(wine[treatments], scale. = TRUE)
#calculate the centroids for the feature/treatment space and the pca space
df.wine.x <- as.data.frame(wine.pca$x)
df.wine.x$groups <- wine.class
wine$groups <- wine.class
feature.centroids <- aggregate(wine[treatments], list(Type = wine$groups), mean)
pca.centroids <- aggregate(df.wine.x[treatments], list(Type = df.wine.x$groups), mean)
pca.centroids
feature.centroids
#calculate distance between the centroids of barolo and grignolino
dist(rbind(feature.centroids[feature.centroids$Type == "barolo",][-1],feature.centroids[feature.centroids$Type == "grignolino",][-1]), method = "euclidean")
dist(rbind(pca.centroids[pca.centroids$Type == "barolo",][-1],pca.centroids[pca.centroids$Type == "grignolino",][-1]), method = "euclidean")

最后两行return1.468087为特征中的距离-space和pca-space中的1.80717,表示有一个美中不足...

这是因为缩放和居中,如果不缩放和居中,原始特征和 PCA 特征中的距离将完全相同 space。

wine.pca <- prcomp(wine[treatments], scale=FALSE, center=FALSE)

dist(rbind(feature.centroids[feature.centroids$Type == "barolo",][-1],feature.centroids[feature.centroids$Type == "grignolino",][-1]), method = "euclidean")
#         1
# 2 1.468087
dist(rbind(pca.centroids[pca.centroids$Type == "barolo",][-1],pca.centroids[pca.centroids$Type == "grignolino",][-1]), method = "euclidean")
#         1
# 2 1.468087

获得相同结果的另一种方法是缩放/居中原始数据,然后应用具有缩放/居中的 PCA,如下所示:

wine[treatments] <- scale(wine[treatments], center = TRUE)
wine.pca <- prcomp(wine[treatments], scale = TRUE)

dist(rbind(feature.centroids[feature.centroids$Type == "barolo",][-1],feature.centroids[feature.centroids$Type == "grignolino",][-1]), method = "euclidean")
#        1
# 2 1.80717
dist(rbind(pca.centroids[pca.centroids$Type == "barolo",][-1],pca.centroids[pca.centroids$Type == "grignolino",][-1]), method = "euclidean")
#        1
# 2 1.80717