0

Using the R igraph package, I am trying to compare a set of similar network partitions representing cohorts. Each network is undirected and consists of the same (n=150) nodes connected differently for each cohort. Since I have 11 cohorts that I would like to compare, it would be ideal if I could implement this procedure in a loop, but I can't quite figure out how.

If I have the network objects g1 and g2, I can manually compare them:

compare(infomap.community(g1), infomap.community(g2), method='nmi')

I've figured out that I can save the networks in a list, but then I won't be able to compare them either by

network_list <- list(g1, g2)
compare(infomap.community(network_list[1]), infomap.community(network_list[2]), method='nmi')

Which produces the error "Error in infomap.community(test[1]) : Not a graph object", or by

community_object_list <- list(infomap.community(g1), infomap.community(g2))
compare(community_object_list[1], community_object_list[2])

Producing the error "Error in i_compare(comm1, comm2, method) : (list) object cannot be coerced to type 'double'"

Does anyone know how to fix this, or can think of another way to do it?

Thanks

qwuaren
  • 1
  • 1
  • 1
    you may need to subset the list using `[[` -- double square brackets i.e. `network_list[[1]]` – user20650 Jan 17 '20 at 22:56
  • https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el – user20650 Jan 17 '20 at 22:58
  • @user20650 Thanks! I've already tried that, but I get the same errors regardless. – qwuaren Jan 17 '20 at 22:59
  • okay, can you then provide a reproducible example please as I'd of thought that would work. (i.e. `set.seed(1); g1 = random.graph.game(10, 0.1) ; g2 = random.graph.game(10, 0.1)`. Then `compare(infomap.community(g1), infomap.community(g2), method='nmi')` and `network_list <- list(g1, g2); compare(infomap.community(network_list[[1]]), infomap.community(network_list[[2]]), method='nmi')` give the same answer for me) – user20650 Jan 17 '20 at 23:32
  • FYI, this q&a provides useful examples of how to write reproducible questions ; https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – user20650 Jan 17 '20 at 23:34

0 Answers0