compute_edge_pvalues: Compute P-Values for Edge Differences Between Populations

View source: R/compute_edge_pvalues.R

compute_edge_pvaluesR Documentation

Compute P-Values for Edge Differences Between Populations

Description

This function computes p-values for the differences in edge presence between populations using statistical tests (e.g., Fisher's exact test, chi-squared test).

Usage

compute_edge_pvalues(edge_counts, N, method = "fisher", adjust_method = "none")

Arguments

edge_counts

An array of edge counts from compute_edge_frequencies.

N

A vector of sample sizes for each population.

method

The statistical test method to use: "fisher", "chi.squared", or "prop". Default is "fisher". The "prop" method requires exactly two populations. The method is validated even when the graphs have no edges.

adjust_method

The method for p-value adjustment for multiple testing (one of p.adjust.methods). Default is "none". Validated even when the graphs have no edges.

Value

A matrix of p-values for each edge.

Examples

# Generate synthetic populations
control_graphs <- generate_category_graphs(
  n_graphs = 5,
  n_nodes = 10,
  n_communities = 2,
  base_intra_prob = 0.8,
  base_inter_prob = 0.2,
  seed = 1
)
patient_graphs <- generate_category_graphs(
  n_graphs = 5,
  n_nodes = 10,
  n_communities = 2,
  base_intra_prob = 0.6,
  base_inter_prob = 0.4,
  seed = 2
)
populations <- list(Control = control_graphs, Patient = patient_graphs)

# Compute edge frequencies
frequencies <- compute_edge_frequencies(populations)
edge_counts <- frequencies$edge_counts
N <- lengths(populations)

# Compute p-values for edge differences
edge_pvalues <- compute_edge_pvalues(edge_counts, N)
# View p-values for the first few edges
print(edge_pvalues[1:5, 1:5])

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