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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With