我可以对R中的方法使用一些建议来确定最佳簇数,然后用不同的统计标准描述簇。我是R的新手,具有关于聚类分析统计基础的基本知识。
确定集群数量的方法: 在文献中,一种常用的方法是所谓的“弯头标准”,它比较不同群集解决方案的平方差异和(SSD)。因此,SSD在分析中针对Cluster的数量绘制,并且通过识别图中的“肘”来确定最佳簇数(例如,这里: https://en.wikipedia.org/wiki/File:DataClustering_ElbowCriterion.JPG) 这种方法是获得主观印象的第一种方法。因此,我想在R中实现它。互联网上的信息很少。这里有一个很好的例子: http://www.mattpeeples.net/kmeans.html 作者还做了一个有趣的迭代方法,看看在多次重复聚类过程之后肘是否在某种程度上是稳定的(尽管它是用于分区聚类方法而不是分层)。 文献中的其他方法包括所谓的“停止规则”。 MILLIGAN&COOPER在他们的论文“检查确定数据集中簇数量的程序”中比较了其中30个停止规则(可在此处获得: http://link.springer.com/article/10.1007%2FBF02294245)发现Calinski和Harabasz的停止规则在蒙特卡罗评估中提供了最好的结果。在R中实现这一点的信息甚至更为稀疏。 因此,如果有人曾经实施过这个或另一个停止规则(或其他方法),那么一些建议会非常有用。
统计描述群集:为了描述我想到的使用均值和某种方差标准的聚类。我的数据是关于农业用地的数据,并显示了每个市的不同作物的产量数量。我的目标是在我的数据集中找到类似的土地利用模式。
我为一个对象子集生成了一个脚本来进行第一次测试运行。它看起来像这样(脚本中的步骤解释,下面的来源)。
#Clusteranalysis agriculture
#Load data
agriculture <-read.table ("C:\\Users\\etc...", header=T,sep=";")
attach(agriculture)
#Define Dataframe to work with
df<-data.frame(agriculture)
#Define a Subset of objects to first test the script
a<-df[1,]
b<-df[2,]
c<-df[3,]
d<-df[4,]
e<-df[5,]
f<-df[6,]
g<-df[7,]
h<-df[8,]
i<-df[9,]
j<-df[10,]
k<-df[11,]
#Bind the objects
aTOk<-rbind(a,b,c,d,e,f,g,h,i,j,k)
#Calculate euclidian distances including only the columns 4 to 24
dist.euklid<-dist(aTOk[,4:24],method="euclidean",diag=TRUE,upper=FALSE, p=2)
print(dist.euklid)
#Cluster with Ward
cluster.ward<-hclust(dist.euklid,method="ward")
#Plot the dendogramm. define Labels with labels=df$Geocode didn't work
plot(cluster.ward, hang = -0.01, cex = 0.7)
#here are missing methods to determine the optimal number of clusters
#Calculate different solutions with different number of clusters
n.cluster<-sapply(2:5, function(n.cluster)table(cutree(cluster.ward,n.cluster)))
n.cluster
#Show the objects within clusters for the three cluster solution
three.cluster<-cutree(cluster.ward,3)
sapply(unique(three.cluster), function(g)aTOk$Geocode[three.cluster==g])
#Calculate some statistics to describe the clusters
three.cluster.median<-aggregate(aTOk[,4:24],list(three.cluster),median)
three.cluster.median
three.cluster.min<-aggregate(aTOk[,4:24],list(three.cluster),min)
three.cluster.min
three.cluster.max<-aggregate(aTOk[,4:24],list(three.cluster),max)
three.cluster.max
#Summary statistics for one variable
three.cluster.summary<-aggregate(aTOk[,4],list(three.cluster),summary)
three.cluster.summary
detach(agriculture)
来源: