Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About community.to.membership function

Tags:

r

igraph

library(igraph)
g=graph.famous("Zachary")
c=walktrap.community(g)
a=community.to.membership(g,c$merges,steps=2)
b=a$membership
modularity(g,b)

When running the modularity(g,b) function, R did not respond. Why?

like image 788
Ben Avatar asked Feb 18 '26 08:02

Ben


1 Answers

This is a bug in igraph. The community.to.membership function returns a zero-based membership vector and modularity expects a 1-based membership vector.

The community.to.membership function is actually deprecated and the cutat function should be used instead:

library(igraph)
set.seed(42)
g <- graph.famous("Zachary")
c <- walktrap.community(g)
b <- cutat(c, steps=2)
modularity(g, b)
# [1] -0.02621631

Btw. your example is not reproducible, because walktrap.community is not deterministic and you don't set the random seed.

Btw.2. there is no real difference between igraph versions 0.6-1 and 0.6-3 (and 0.6-x), the number after a dash is just the build number. The package was rebuilt for technical reasons, and version 0.6-3 contains the same code as 0.6-1.

like image 118
Gabor Csardi Avatar answered Feb 19 '26 20:02

Gabor Csardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!