modularity: Computes the (Signed) Modularity Statistic

View source: R/modularity.R

modularityR Documentation

Computes the (Signed) Modularity Statistic

Description

Computes (signed) modularity statistic given a network and community structure. Allows the resolution parameter to be set

Usage

modularity(network, memberships, resolution = 1, signed = FALSE)

Arguments

network

Matrix or data frame. A symmetric matrix representing a network

memberships

Numeric (length = ncol(network)). A numeric vector of integer values corresponding to each node's community membership

resolution

Numeric (length = 1). A parameter that adjusts modularity to prefer smaller (resolution > 1) or larger (0 < resolution < 1) communities. Defaults to 1 (standard modularity computation)

signed

Boolean (length = 1). Whether signed or absolute modularity should be computed. The most common modularity metric is defined by positive values only. Gomez et al. (2009) introduced a signed version of modularity that will discount modularity for edges with negative values. This property isn't always desired for psychometric networks. If TRUE, then this signed modularity metric will be computed. If FALSE, then the absolute value of the edges in the network (using abs) will be used to compute modularity. Defaults to FALSE

Value

Returns the modularity statistic

Author(s)

Alexander P. Christensen <alexpaulchristensen@gmail.com> with assistance from GPT-4

References

Gomez, S., Jensen, P., & Arenas, A. (2009). Analysis of community structure in networks of correlated data. Physical Review E, 80(1), 016114.

Examples

# Load data
wmt <- wmt2[,7:24]

# Estimate EGA
ega.wmt <- EGA(wmt, model = "glasso")

# Compute standard (absolute values) modularity
modularity(
  network = ega.wmt$network,
  memberships = ega.wmt$wc,
  signed = FALSE
)
# 0.1697952

# Compute signed modularity
modularity(
  network = ega.wmt$network,
  memberships = ega.wmt$wc,
  signed = TRUE
)
# 0.1701946


EGAnet documentation built on Nov. 18, 2023, 1:07 a.m.