generate_community_graph: Generate a Random Symmetric Adjacency Matrix with Community...

View source: R/generate_community_graph.R

generate_community_graphR Documentation

Generate a Random Symmetric Adjacency Matrix with Community Structure

Description

This function generates a random symmetric adjacency matrix representing a brain network with community structure. Nodes within the same community have a higher probability of being connected compared to nodes from different communities.

Usage

generate_community_graph(
  n_nodes = 100,
  n_communities = 4,
  community_sizes = NULL,
  intra_prob = 0.8,
  inter_prob = 0.2,
  seed = NULL
)

Arguments

n_nodes

An integer specifying the total number of nodes (brain regions). Default is 100.

n_communities

An integer specifying the number of communities. Default is 4.

community_sizes

An integer vector specifying the sizes of each community. If NULL, communities are of equal size. Default is NULL.

intra_prob

A numeric value between 0 and 1, or a numeric vector of length n_communities, specifying the probability of an edge existing between nodes within the same community. If a scalar, the same probability is used for all communities. Default is 0.8.

inter_prob

A numeric value between 0 and 1 specifying the probability of an edge existing between nodes from different communities. Default is 0.2.

seed

An optional integer for setting the random seed to ensure reproducibility. Default is NULL.

Value

A symmetric binary adjacency matrix with no self-loops, representing a brain network with community structure.

Examples

# Generate a brain network with community structure
G <- generate_community_graph(n_nodes = 100, n_communities = 4, intra_prob = 0.8, inter_prob = 0.2)

BrainNetTest documentation built on Dec. 3, 2026, 5:08 p.m.