作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以测试 PCA 图上 2 个已知组之间聚类的显着性?测试它们的接近程度或传播量(方差)和聚类之间的重叠量等。
最佳答案
这是一种使用 ggplot(...)
的定性方法。在簇周围绘制 95% 置信椭圆。请注意 stat_ellipse(...)
使用二元 t 分布。
library(ggplot2)
df <- data.frame(iris) # iris dataset
pca <- prcomp(df[,1:4], retx=T, scale.=T) # scaled pca [exclude species col]
scores <- pca$x[,1:3] # scores for first three PC's
# k-means clustering [assume 3 clusters]
km <- kmeans(scores, centers=3, nstart=5)
ggdata <- data.frame(scores, Cluster=km$cluster, Species=df$Species)
# stat_ellipse is not part of the base ggplot package
source("https://raw.github.com/low-decarie/FAAV/master/r/stat-ellipse.R")
ggplot(ggdata) +
geom_point(aes(x=PC1, y=PC2, color=factor(Cluster)), size=5, shape=20) +
stat_ellipse(aes(x=PC1,y=PC2,fill=factor(Cluster)),
geom="polygon", level=0.95, alpha=0.2) +
guides(color=guide_legend("Cluster"),fill=guide_legend("Cluster"))
ggdata$Clusters
和
ggdata$Species
显示 setosa 完美映射到集群 1,而 versicolor 在集群 2 中占主导地位,而 virginica 在集群 3 中占主导地位。 然而,集群 2 和 3 之间存在显着重叠。
ggplot
在github上。
关于r - 在 PCA 图上测试聚类的显着性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20260434/
我是一名优秀的程序员,十分优秀!