Introduction to BrainNetTest

knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>"
)

Overview

BrainNetTest implements the non-parametric L1-distance ANOVA test of Fraiman and Fraiman (2018) for comparing populations of brain networks represented as graphs. The package provides:

This vignette introduces the basic API on simple synthetic data. The companion vignette, Generating and Analyzing Brain Networks with Community Structures, shows the full pipeline on community-structured populations.

Installation

# Release version
install.packages("BrainNetTest")

# Development version from GitHub
# install.packages("remotes")
remotes::install_github("mmaximiliano/BrainNetTest")

A minimal example

library(BrainNetTest)
set.seed(1)

Generating random graphs

generate_random_graph() returns a symmetric binary adjacency matrix with no self-loops:

G <- generate_random_graph(n_nodes = 10, edge_prob = 0.2)
isSymmetric(G)
all(diag(G) == 0)

Central graph and Manhattan distance

Given a population (list of adjacency matrices), the central graph is the entry-wise mean; compute_distance() returns the L1 (Manhattan) distance between two graphs:

population <- replicate(
  5, generate_random_graph(n_nodes = 10, edge_prob = 0.2),
  simplify = FALSE)

central <- compute_central_graph(population)
compute_distance(population[[1]], central)

The group test statistic T

compute_test_statistic() aggregates within- and between-group Manhattan distances into the statistic T. More negative (smaller) values indicate stronger evidence that the groups differ: with equal group sizes, the expected value of T is zero when all populations have the same edge probabilities and becomes more negative the more those probabilities differ between groups (see ?compute_test_statistic):

control <- replicate(
  15, generate_random_graph(n_nodes = 10, edge_prob = 0.20),
  simplify = FALSE)
patient <- replicate(
  15, generate_random_graph(n_nodes = 10, edge_prob = 0.40),
  simplify = FALSE)

populations <- list(Control = control, Patient = patient)
compute_test_statistic(populations, a = 1)

The global test

compute_test_statistic() returns only the observed value. global_test() assesses group differences by permuting the group labels across the pooled sample while preserving the group sizes (requiring exchangeable group labels under the null; equal edge means alone are not sufficient). By default (criterion = "combined"), it combines T with the smallest marginal edge p-value U across the same permutations; criterion = "original" evaluates the lower tail of T alone. The normalisation constant a is fixed at 1, because rescaling by a positive constant leaves permutation ranks unchanged.

gt <- global_test(populations, n_permutations = 500, seed = 42)
gt

The permutation null distribution of T is kept in gt$null_distribution, so it can be inspected or plotted. Because the observed sample is counted among the B + 1 values, permutation p-values are never below 1 / (B + 1), which is marked as (minimum) when attained.

Exploring candidate edges

Once a global difference is detected, identify_critical_links() explores which edges are associated with that difference. It runs the same global test first and then iteratively removes edges, ranked by their marginal p-values, until the test on the remaining edges rises above alpha. This selection step is exploratory: it does not establish edge-level family-wise error or false discovery rate control, and stopping does not prove that the remaining networks are equal. Always report the initial global p-value separately from the selected edges:

result <- identify_critical_links(
  populations,
  alpha          = 0.05,
  method         = "fisher",
  n_permutations = 200,
  seed           = 42)

result

The result is a critical_links object. Printing it, as above, gives a compact report; summary() adds the settings the analysis ran with and the node-level ranking:

summary(result)

The individual components remain available, result$critical_edges being the ranked table of critical edges. The get_critical_nodes() helper summarises the result at the node level on its own:

get_critical_nodes(result)

References

Fraiman, D. and Fraiman, R. (2018) An ANOVA approach for statistical comparisons of brain networks. Scientific Reports, 8, 4746. https://doi.org/10.1038/s41598-018-23152-5



Try the BrainNetTest package in your browser

Any scripts or data that you put into this service are public.

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