modularity: Community Detection with Modularity Optimization

Description Usage Arguments Value References Examples

View source: R/cluster_modularity.R

Description

Find the communities of a graph by direct optimization of a modularity score. For simplicity, this function only accepts a symmetric network of \lbrace 0, 1 \rbrace binary edges.

Usage

1
modularity(graph)

Arguments

graph

one of the followings; (1) an igraph object, (2) a network object, or (3) an (N\times N) adjacency matrix.

Value

a named list containing

cluster

a length-N vector of class labels.

modularity

the computed modularity value.

References

\insertRef

modularity2004T4network

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## load the data
data(karate, package="T4network")

## community detection
karate.modular = T4network::modularity(karate$A)
karate.label   = karate.modular$cluster
karate.true    = karate$label

## wrap the graph as 'igraph' object
karate.igraph = igraph::graph_from_adjacency_matrix(karate$A, mode="undirected")

## visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(karate.igraph, vertex.label=NA, vertex.color=karate.true,  main="true label")
plot(karate.igraph, vertex.label=NA, vertex.color=karate.label, main="estimated label")
par(opar)

kisungyou/T4network documentation built on Dec. 21, 2021, 6:44 a.m.