# Simulation parameters
pk <- rep(20, 4)
nu_within <- 0.8
nu_between <- 0.1
# Expected metrics
expected <- ExpectedCommunities(
pk = pk,
nu_within = nu_within,
nu_between = nu_between
)
# Example of simulated graph
set.seed(1)
theta <- SimulateAdjacency(
pk = pk,
nu_within = nu_within,
nu_between = nu_between
)
# Comparing observed and expected numbers of edges
bigblocks <- BlockMatrix(pk)
BlockStructure(pk)
sum(theta[which(bigblocks == 2)]) / 2
expected$total_number_edges_c[1, 2]
# Comparing observed and expected modularity
igraph::modularity(igraph::graph_from_adjacency_matrix(theta, mode = "undirected"),
membership = rep.int(1:length(pk), times = pk)
)
expected$modularity
Run the code above in your browser using DataLab