我想知道igraph实现的Leiden算法是否存在已知问题.当我运行它时,它生成的分区与其他类似的算法(即使是其他包实现的leiden)相比,社区太多了.即使影响分辨率参数,它也会产生大量的社区.

library(igraph)
library(leidenAlg)
G <- graph_from_literal(1-2:3-4:5-6:7-8:9-10:11-12-13-14:15-16,1-7,10:8-13)
clLouv <- cluster_louvain(G)
clLeid <- cluster_leiden(G, resolution_parameter = .5)
cl_Leid_r <- find_partition_with_rep(G, edge_weights=E(G))
clLouv$membership
clLeid$membership
cl_Leid_r

谢谢

推荐答案

以邻接矩阵的密度作为分解参数,得到了满意的结果.

例如.

library(igraph)
G <- graph_from_literal(1-2:3-4:5-6:7-8:9-10:11-12-13-14:15-16,1-7,10:8-13)
r <- gsize(G)*2 / (gorder(G) * (gorder(G)-1))         # density of the adjacency matrix, or    
r <- mean(degree(G)) / gorder(G)                      # or
r <- quantile(strength(G))[2] / (gorder(G) - 1)       # from ?cluster_leiden documentation.
set.seed(20231206)                                    # For sake of reproducibility.
clLeid <- cluster_leiden(G, resolution_parameter = r)
plot(clLeid, G)

这给出的结果与卢瓦因方法非常相似.

clLeid
#IGRAPH clustering leiden, groups: 3, mod: NA
#+ groups:
#  $`1`
#  [1] "1" "2" "3" "4" "5" "7"
#  
#  $`2`
#  [1] "6"  "8"  "9"  "10" "11" "12" "13"
#  
#  $`3`
#  [1] "14" "15" "16"

clLeid$membership
[1] 1 1 1 1 1 2 1 2 2 2 2 2 2 3 3 3

Update,按如下方式验证模块化:

print(modularity_matrix(G, resolution = r, directed = FALSE), digits=4)

print.default(clLeid)
## $membership
##  [1] 1 1 1 1 1 2 1 2 2 2 2 2 2 3 3 3
## 
## $nb_clusters
## [1] 3
## 
## $quality
## [1] 0.45
## 
## $algorithm
## [1] "leiden"
## 
## $vcount
## [1] 16
## 
## $names
##  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15" "16"
## 
## attr(,"class")
## [1] "communities"

R相关问答推荐

如何提高以键ID为列的表中键查找的效率?

使用预定值列表将模拟数量(n)替换为rnorm()

如何从R中的字符串元素中减go 一个数字?

将非重复序列高效转换为长格式

使用case_match()和char数组重新编码值

如何计算多个日期是否在一个日期范围内

如何删除最后一个可操作对象

在ggplot2的框图中绘制所有级别的系数

SHINY:使用JS函数应用的CSS样式显示HTML表格

为什么在BASE R中绘制线条时会看到线上的点?

如何平滑或忽略R中变量的微小变化?

ggplot R:X,Y,Z使用固定/等距的X,Y坐标绘制六边形热图

根据r中另一个文本列中给定的范围对各列求和

R-使用stri_trans_General()将其音译为德语字母

将美学添加到ggploy中的文本标签

使用列名和r中的前缀 Select 列的CREATE函数

通过比较来自多个数据框的值和R中的条件来添加新列

R dplyr::带有名称注入(LHS of:=)的函数,稍后在:=的RHS上引用

动态统计函数在ShinyApp内部更改

Package emMeans:如果emmip模型中包含的变量较少,emMeans模型中的其他变量设置为什么?