This function calculates how modular is a given division of a graph into subgraphs.
# S3 method for igraph
modularity(x, membership, weights = NULL, ...)modularity_matrix(graph, membership, weights = NULL)
The input graph.
Numeric vector, one value for each vertex, the membership vector of the community structure.
If not NULL
then a numeric vector giving edge weights.
Additional arguments, none currently.
For modularity
a numeric scalar, the modularity score of the
given configuration.
For modularity_matrix
a numeric square matrix, its order is the number of
vertices in the graph.
modularity
calculates the modularity of a graph with respect to the
given membership
vector.
The modularity of a graph with respect to some division (or vertex types)
measures how good the division is, or how separated are the different vertex
types from each other. It defined as
If edge weights are given, then these are considered as the element of the
modularity_matrix
calculates the modularity matrix. This is a dense matrix,
and it is defined as the difference of the adjacency matrix and the
configuration model null model matrix. In other words element
Clauset, A.; Newman, M. E. J. & Moore, C. Finding community structure in very large networks, Physical Review E 2004, 70, 066111
cluster_walktrap
,
cluster_edge_betweenness
,
cluster_fast_greedy
, cluster_spinglass
,
cluster_louvain
and cluster_leiden
for
various community detection methods.
# NOT RUN {
g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5)
g <- add_edges(g, c(1,6, 1,11, 6, 11))
wtc <- cluster_walktrap(g)
modularity(wtc)
modularity(g, membership(wtc))
# }
Run the code above in your browser using DataLab