The network as a whole has a modularity of 0.567. The smaller clusters have 0 modularity because everyone knows everyone else; they're very small world and have average path lengths that are exceedingly close to 1.

Finally, the figure illustrates an assortativity of 0.29. Positive assortativity (which can fall between -1 and 1) indicates that nodes tend to be connected to nodes with similar numbers of connections. That seems reasonable here because most nodes are connected to others in their group, but some aren't.

Happy networking!

#install.packages("igraph")

ReplyDeletelibrary("igraph")

set.seed(454)

a = matrix(rbinom(100, 1, .9), ncol = 10)

diag(a) = 0

b = matrix(rbinom(100, 1, .05), ncol = 10)

c = matrix(rbinom(100, 1, .7), ncol = 10)

diag(c) = 0

d = matrix(rbinom(100, 1, .01), ncol = 10)

e = matrix(rbinom(100, 1, .7), ncol = 10)

diag(e) = 0

zero = matrix(rbinom(100, 1, .01), ncol = 10)

I = cbind(a, zero, b)

II = cbind(zero, c , zero)

III = cbind(d, zero, e)

thing = rbind(I, II, III)

#thing = matrix(sample(c(0,0,0,0,1), 900, replace = TRUE), ncol = 30)

sums = c(sum(a), sum(zero), sum(b),

sum(zero), sum(c), sum(zero),

sum(d), sum(zero), sum(e))

nice = graph.adjacency(thing, mode = "undirected")

colors = rep(c("deepskyblue" , "mediumpurple", "chartreuse"), each = 10)

V(nice)$color = colors

V(nice)$shape = "sphere"

V(nice)$size = 15

V(nice)$label = NA

E(nice)$color = "black"

plot(nice)

modularity(walktrap.community(nice))

average.path.length(nice)

assortativity.degree(nice)