为什么能量距离函数给我零结果?

时间:2018-07-30 11:44:48

标签: r

如此处https://cran.r-project.org/web/packages/energy/energy.pdf

所述

e.dist返回值返回簇之间的E距离(能量统计)。 作为输入,它接受合并样本的数据矩阵欧几里德距离

我想计算我的数据集中100次观察之间的电子距离。

看看我做了什么:

> disteuc<-dist(DATABASE,method = "euclidean")
> edist(disteuc,sizes=100)
dist(0)

为什么我得到空值??

这是我的数据集中的前100行:

> dput(DATABASE[1:100,])
structure(list(TYPE_PEAU = c(2L, 2L, 3L, 2L, 2L, 2L, 2L, 4L, 
3L, 2L, 2L, 2L, 2L, 1L, 4L, 2L, 2L, 2L, 4L, 2L, 3L, 3L, 2L, 2L, 
2L, 2L, 2L, 4L, 3L, 4L, 2L, 2L, 2L, 2L, 4L, 2L, 1L, 2L, 2L, 2L, 
2L, 4L, 3L, 2L, 4L, 2L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 4L, 2L, 2L, 
3L, 4L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 4L, 2L, 4L, 
3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 2L, 4L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 2L, 2L, 2L), SENSIBILITE = c(3L, 
2L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 
1L, 3L, 3L, 1L, 3L, 2L, 2L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 1L, 3L, 
1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 1L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 2L, 3L, 2L, 3L, 2L, 
3L, 3L, 3L, 3L, 3L, 2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13L, 7L, 23L, 32L, 32L, 
32L), NOMBRE_ACHAT = c(14L, 6L, 3L, 9L, 8L, 13L, 10L, 14L, 4L, 
3L, 10L, 8L, 12L, 3L, 7L, 6L, 4L, 13L, 3L, 3L, 6L, 13L, 3L, 4L, 
6L, 7L, 4L, 12L, 5L, 6L, 16L, 3L, 14L, 4L, 4L, 6L, 9L, 13L, 3L, 
5L, 12L, 4L, 3L, 6L, 3L, 6L, 6L, 3L, 6L, 4L, 3L, 3L, 7L, 3L, 
12L, 12L, 10L, 3L, 6L, 7L, 14L, 3L, 18L, 7L, 5L, 4L, 7L, 17L, 
6L, 6L, 3L, 6L, 17L, 10L, 12L, 5L, 13L, 15L, 6L, 3L, 11L, 6L, 
7L, 7L, 16L, 3L, 3L, 3L, 3L, 6L, 3L, 4L, 3L, 10L, 3L, 4L, 6L, 
5L, 14L, 3L), NOMBRE_CADEAU = c(2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 1L, 1L, 
2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 
3L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 
1L, 1L, 1L, 1L, 2L, 1L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 
2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L)), .Names = c("TYPE_PEAU", 
"SENSIBILITE", "IMPERFECTIONS", "BRILLANCE", "GRAIN_PEAU", "RIDES_VISAGE", 
"ALLERGIES", "MAINS", "PEAU_CORPS", "INTERET_ALIM_NATURELLE", 
"INTERET_ORIGINE_GEO", "INTERET_VACANCES", "INTERET_ENVIRONNEMENT", 
"INTERET_COMPOSITION", "AGE_INTERVAL", "ATTENTE_BEAUTE_1", "ATTENTE_BEAUTE_2", 
"MILIEU_VIE", "PROFIL_SELECTIONNE", "NOMBRE_ACHAT", "NOMBRE_CADEAU"
), row.names = c(NA, 100L), class = "data.frame")
> 

1 个答案:

答案 0 :(得分:2)

您仅指定一个群集大小,如果您有100个数据并且它们都在同一群集中,则与其他群集之间没有距离。

> edist(disteuc,sizes=100)
dist(0)
> edist(disteuc,sizes=c(10, 90))
         1
2 42.51959
> edist(disteuc,sizes=c(10, 40, 50))
         1        2
2 44.32714         
3 39.80484 35.26888