2017-07-17 21 views
2

我要测试的霍普金斯统计从comato包霍普金斯()函数outputed和我使用下面的可再现的代码:霍普金斯函数返回错误消息

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
# 
# SIMPLE EXPERIMENTS TO CHECK THE EFFECT OF CLUSTERABILITY ON HOPKINS STATISTIC 
# 
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 

################################################################################### 
# CREATE THREE DATASETS OF LOW, MEDIUM AND HIGH CLUSTERABILITY 
################################################################################# 

low1 <- data.table(V1 = rnorm(500, mean = 0, sd = 1), V2 = rnorm(500, mean = 0, sd = 1), Cluster = as.factor(rep(1, 500))) 
low2 <- data.table(V1 = rnorm(500, mean = 0, sd = 1), V2 = rnorm(500, mean = 0, sd = 1), Cluster = as.factor(rep(2, 500))) 
low <- rbind(low1, low2) 


#--------------------------------------------------------------------------------------------- 
medium1 <- data.table(V1 = rnorm(500, mean = 0, sd = 1), V2 = rnorm(500, mean = 0, sd = 1), Cluster = as.factor(rep(1, 500))) 
medium2 <- data.table(V1 = rnorm(500, mean = 2, sd = 1), V2 = rnorm(500, mean = 2, sd = 1), Cluster = as.factor(rep(2, 500))) 
medium <- rbind(medium1, medium2) 

#---------------------------------------------------------------------------------------------- 

high1 <- data.table(V1 = rnorm(500, mean = 0, sd = 1), V2 = rnorm(500, mean = 0, sd = 1), Cluster = as.factor(rep(1, 500))) 
high2 <- data.table(V1 = rnorm(500, mean = 4, sd = 1), V2 = rnorm(500, mean = 4, sd = 1), Cluster = as.factor(rep(2, 500))) 
high <- rbind(high1, high2) 

######################################################################################### 
# VISUALIZE THE CLUSTERS 
########################################################################################## 


#--------------------------------------------------------------- 
# LOW 
#-------------------------------------------------------------- 

ggplot(low, aes(V1, V2, colour = Cluster)) + 
    geom_point(size = 2.5, alpha = 0.5) + ggtitle("Low Clusterability") + theme_economist() 

enter image description here

#--------------------------------------------------------------- 
# MEDIUM 
#-------------------------------------------------------------- 

ggplot(medium, aes(V1, V2, colour = Cluster)) + 
    geom_point(size = 2.5, alpha = 0.5) + ggtitle("Medium Clusterability") + theme_economist() 

enter image description here

#--------------------------------------------------------------- 
# HIGH 
#-------------------------------------------------------------- 

ggplot(high, aes(V1, V2, colour = Cluster)) + 
    geom_point(size = 2.5, alpha = 0.5) + ggtitle("High Clusterability") + theme_economist() 

enter image description here

########################################################################################## 
# DETERMINE THE HOPKINS STATISTIC FOR EACH OF THE AFOREMENTIONED CASES 
############################################################################################ 

library(comato) 

hopkins_low_comato <- Hopkins.index(low[, .(V1, V2)]) 

hopkins_medium_comato <- Hopkins.index(medium[, .(V1, V2)]) 

hopkins_high_comato <- Hopkins.index(high[, .(V1, V2)]) 

但是我得到以下的错误消息:

enter image description here

你的意见可以理解

+0

通过聚类趋势的霍普金斯定义,所有三组数据也有类似的聚类趋势。第一次只有1个群集。但它仍然是一个高斯*簇*。在我看来,不幸的是,这个指数是无用的。 –

回答

0

基本上函数只接受一个矩阵作为数据类型。 所以,你可以将你的数据帧矩阵,并且使用该函数以这种方式:

low_matrix <- as.matrix(low[, .(V1, V2)]) 
hopkins_low_comato <- Hopkins.index(low_matrix)