| Type: | Package |
| Title: | Hypothesis Testing for Populations of Brain Networks |
| Version: | 0.2.2 |
| Description: | Non-parametric hypothesis testing for populations of brain networks represented as graphs, following the L1-distance ANOVA framework of Fraiman and Fraiman (2018) <doi:10.1038/s41598-018-23152-5>. The package builds on this nonparametric graph-comparison framework, extending it with procedures for edge-level inference and identification of the specific connections driving group differences. In particular, it provides utilities to compute central (mean) graphs, pairwise Manhattan distances between adjacency matrices, the group test statistic T and its permutation p-value, and a fast permutation procedure to identify the critical edges that drive between-group differences. Helper functions to generate synthetic community-structured graphs and to visualise brain networks with communities are also included. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/mmaximiliano/BrainNetTest |
| BugReports: | https://github.com/mmaximiliano/BrainNetTest/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.0.0) |
| Imports: | stats, graphics, utils, igraph |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.1.7) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-23 20:25:22 UTC; maxi |
| Author: | Maximiliano Martino
|
| Maintainer: | Maximiliano Martino <maxii.martino@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-23 20:40:02 UTC |
Compute the Central (Representative) Graph for a Population
Description
This function computes the central graph for a given population by averaging the adjacency matrices of all graphs within that population.
Usage
compute_central_graph(graph_list)
Arguments
graph_list |
A list of adjacency matrices representing brain networks. |
Value
A single adjacency matrix representing the central graph of the population.
Examples
# Generate synthetic Control data
Control <- list(
generate_random_graph(n_nodes = 5, edge_prob = 0.1),
generate_random_graph(n_nodes = 5, edge_prob = 0.1)
)
central_graph <- compute_central_graph(Control)
Compute the Manhattan Norm Distance Between Two Graphs
Description
This function calculates the Manhattan norm (L1 norm) distance between two adjacency matrices representing brain networks.
Usage
compute_distance(G, M)
Arguments
G |
A square adjacency matrix representing a brain network. |
M |
A square adjacency matrix representing the central brain network. |
Value
A numeric value representing the Manhattan distance between G and M.
Examples
# Generate synthetic data
G1 <- generate_random_graph(n_nodes = 5, edge_prob = 0.1)
G2 <- generate_random_graph(n_nodes = 5, edge_prob = 0.1)
central_graph <- compute_central_graph(list(G1, G2))
distance <- compute_distance(G1, central_graph)
Compute Edge Frequencies in Populations
Description
This function computes the frequency of each edge (connection between nodes) across all graphs within each population.
Usage
compute_edge_frequencies(populations)
Arguments
populations |
A list where each element is a population containing a list of graphs (adjacency matrices). |
Value
A list containing edge counts and edge proportions for each population.
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,
intra_prob_variation = 0.05,
inter_prob_variation = 0.05,
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,
intra_prob_variation = 0.05,
inter_prob_variation = 0.05,
seed = 2
)
populations <- list(Control = control_graphs, Patient = patient_graphs)
# Compute edge frequencies
frequencies <- compute_edge_frequencies(populations)
# View edge counts for the first population
edge_counts_control <- frequencies$edge_counts[,,1]
print(edge_counts_control)
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 |
N |
A vector of sample sizes for each population. |
method |
The statistical test method to use: "fisher", "chi.squared", or "prop". Default is "fisher". |
adjust_method |
The method for p-value adjustment for multiple testing. Default is "none". |
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,
intra_prob_variation = 0.05,
inter_prob_variation = 0.05,
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,
intra_prob_variation = 0.05,
inter_prob_variation = 0.05,
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])
Compute the Test Statistic T for Brain Network Populations
Description
This function computes the test statistic T to assess whether different populations of brain networks originate from the same distribution.
Usage
compute_test_statistic(populations, a = 1)
Arguments
populations |
A named list where each element is a list of adjacency
matrices for a population. Example:
|
a |
A normalization constant. Default is 1. |
Value
A numeric value representing the test statistic T.
Examples
# Generate synthetic populations data
Control <- list(
generate_random_graph(n_nodes = 5, edge_prob = 0.1),
generate_random_graph(n_nodes = 5, edge_prob = 0.1)
)
PatientA <- list(
generate_random_graph(n_nodes = 5, edge_prob = 0.15),
generate_random_graph(n_nodes = 5, edge_prob = 0.15)
)
PatientB <- list(
generate_random_graph(n_nodes = 5, edge_prob = 0.2),
generate_random_graph(n_nodes = 5, edge_prob = 0.2)
)
populations <- list(Control = Control, PatientA = PatientA, PatientB = PatientB)
# Compute the test statistic T
T_value <- compute_test_statistic(populations, a = 1)
print(T_value)
Generate a Set of Graphs with Similar Community Structures for a Category
Description
This function generates a list of adjacency matrices representing brain networks belonging to the same category (e.g., Control group). The generated graphs have similar community structures but vary slightly in their intra-community and inter-community connection probabilities to reflect natural variability.
Usage
generate_category_graphs(
n_graphs = 10,
n_nodes = 100,
n_communities = 4,
community_sizes = NULL,
base_intra_prob = 0.8,
base_inter_prob = 0.2,
intra_prob_variation = 0.05,
inter_prob_variation = 0.05,
seed = NULL
)
Arguments
n_graphs |
An integer specifying the number of graphs to generate. Default is 10. |
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. |
base_intra_prob |
A numeric value between 0 and 1, or a numeric vector
of length |
base_inter_prob |
A numeric value between 0 and 1 specifying the base probability of an edge existing between nodes from different communities. Default is 0.2. |
intra_prob_variation |
A numeric value specifying the maximum variation to apply to the intra-community probability for each graph. Default is 0.05. |
inter_prob_variation |
A numeric value specifying the maximum variation to apply to the inter-community probability for each graph. Default is 0.05. |
seed |
An optional integer for setting the random seed to ensure reproducibility. Default is NULL. |
Value
A list of symmetric binary adjacency matrices with no self-loops, representing brain networks with similar community structures.
Examples
# Generate a set of 5 graphs for the Control category
control_graphs <- generate_category_graphs(n_graphs = 5, n_nodes = 100, n_communities = 4,
base_intra_prob = 0.8, base_inter_prob = 0.2)
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 |
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)
Generate a Random Symmetric Adjacency Matrix
Description
This function generates a random symmetric adjacency matrix representing a brain network. The adjacency matrix is binary, with edges present based on a specified probability.
Usage
generate_random_graph(n_nodes, edge_prob = 0.1)
Arguments
n_nodes |
An integer specifying the number of nodes (brain regions). |
edge_prob |
A numeric value between 0 and 1 specifying the probability of an edge existing between any two nodes. |
Value
A symmetric binary adjacency matrix with no self-loops.
Examples
G <- generate_random_graph(n_nodes = 10, edge_prob = 0.1)
Extract Critical Nodes from Critical Edge Results
Description
Given the output of identify_critical_links, this function
identifies the unique nodes involved in the critical edges and summarizes
their participation. Each node is reported with the number of critical edges
it participates in (its critical degree). If node labels are supplied,
they are included in the output.
Usage
get_critical_nodes(result, node_labels = NULL)
Arguments
result |
The list returned by |
node_labels |
An optional character vector of length |
Value
A data frame with the following columns, ordered by decreasing
critical_degree:
- node
Integer node index.
- label
Character label for the node (only present when
node_labelsis notNULL).- critical_degree
Number of critical edges incident on this node.
If no critical edges were found (result$critical_edges is
NULL or has zero rows), an empty data frame with the same columns
is returned.
Examples
# Generate two synthetic populations with different community structure
control <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.8, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.5, base_inter_prob = 0.5, seed = 2)
populations <- list(Control = control, Patient = patient)
# Identify critical edges
result <- identify_critical_links(populations, alpha = 0.05,
method = "fisher", n_permutations = 200, seed = 42)
# Extract critical nodes (no labels)
get_critical_nodes(result)
# With labels
labels <- paste0("Region_", 1:10)
get_critical_nodes(result, node_labels = labels)
Permutation Test for Differences Between Populations of Brain Networks
Description
Tests whether two or more populations of brain networks share the same
central graph, using the L1-distance ANOVA statistic T of Fraiman and
Fraiman (2018) and a permutation null distribution. This is the global test
that identify_critical_links runs before it starts removing
edges; here it is available on its own, so that the population-level
question can be answered, and reported, before any edge is singled out.
Usage
global_test(populations, n_permutations = 1000, seed = NULL)
Arguments
populations |
A named |
n_permutations |
Positive integer giving the number of permutation
replicates used to approximate the null distribution of T. Default
|
seed |
Optional integer seed for reproducibility of the permutation
replicates. Default |
Details
The statistic T contrasts the mean distance of each graph to its
own population's central graph with its mean distance to every
population's central graph (see compute_test_statistic).
Under the alternative it tends towards negative values, because graphs
are closer to their own centre than to the others. Inference uses the
permutation distribution; no standard-normal approximation is assumed. The
p value is therefore the left tail: replicates are generated by
permuting the group labels across the pooled sample while preserving the
group sizes, T is recomputed for each, and the proportion of replicates
with a statistic below the observed one is reported. With B
replicates the estimate cannot resolve below 1/B, which is how the
print method reports an estimate of zero.
The normalisation constant a of
compute_test_statistic is fixed at 1. The p value
does not depend on it: a rescales the observed statistic and every
replicate by the same positive factor, which leaves their comparison
unchanged.
The computation uses the edge-wise decomposition of T described in
identify_critical_links: the statistic of every replicate
is obtained from permuted edge counts through a single matrix product,
rather than by rebuilding graphs and recomputing distances. That
decomposition holds for binary graphs, which is why the input must be
binary. Calling global_test() and
identify_critical_links with the same populations,
n_permutations and seed evaluates the same permutations, so
the p value returned here is the one that
identify_critical_links() records in its p_value component.
Value
An object of class "global_test": a list with the
components
- statistic
the observed value of T, computed with normalisation constant
a = 1.- p_value
the permutation
pvalue: the proportion of replicates whose statistic is smaller than the observed one.NAwhen the graphs have a single node and hence no edges.- null_distribution
numeric vector of length
n_permutationsholding the statistic of every replicate.- n_permutations
the number of replicates.
- group_sizes
named integer vector with the number of graphs in each population.
- n_nodes
the number of nodes.
- call
the matched call.
A print method is provided.
References
Fraiman, D. and Fraiman, R. (2018) An ANOVA approach for statistical comparisons of brain networks. Scientific Reports, 8, 4746. doi:10.1038/s41598-018-23152-5.
See Also
compute_test_statistic for the statistic alone,
identify_critical_links for the edges behind a rejection,
print.global_test.
Examples
control <- generate_category_graphs(n_graphs = 20, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.6, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(n_graphs = 20, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.6, base_inter_prob = 0.4, seed = 2)
populations <- list(Control = control, Patient = patient)
gt <- global_test(populations, n_permutations = 500, seed = 42)
gt
gt$p_value
# The observed statistic is the one compute_test_statistic() returns
all.equal(gt$statistic, compute_test_statistic(populations, a = 1))
# The null distribution is kept, so it can be inspected
summary(gt$null_distribution)
Identify Critical Edges That Explain Population Differences
Description
Iteratively identifies the edges that drive the observed difference between two or more populations of brain networks, using the permutation-based L1-distance ANOVA test of Fraiman and Fraiman (2018). Edges are ranked by their marginal p-value, then removed in batches until the global test is no longer significant. The permutation null is re-evaluated incrementally via a prefix-sum decomposition of T, which avoids recomputing the statistic from scratch at every step.
Usage
identify_critical_links(
populations,
alpha = 0.05,
method = "fisher",
adjust_method = "none",
batch_size = 1,
n_permutations = 1000,
a = 1,
seed = NULL
)
Arguments
populations |
A named |
alpha |
Numeric significance level used both for the global test and
for the iterative edge-removal stopping rule. Default |
method |
Character string selecting the marginal edge test used to
rank candidate edges. One of |
adjust_method |
Character string passed to |
batch_size |
Positive integer giving the number of edges to drop per
iteration. Larger values speed up the procedure at the cost of coarser
resolution. Default |
n_permutations |
Positive integer giving the number of permutation
replicates used to approximate the null distribution of T. Default
|
a |
Positive numeric normalisation constant for the test statistic T
(see |
seed |
Optional integer seed for reproducibility of the permutation
replicates. Default |
Details
The implementation exploits the fact that T decomposes as a sum of
per-edge contributions \Delta_e. Removing an edge e is equivalent
to subtracting \Delta_e from T, so prefix sums of the sorted
\Delta_e values give the test statistic after any number of
removals in O(1). The permutation null is built once via a single BLAS
matrix multiplication and reused for every iteration, reducing the
overall complexity from O(K * B * |E| * m) (naive) to O(B * |E| * m).
Permutation replicates are generated by uniformly permuting the group labels across the pooled sample of all graphs, while preserving the original group sizes (sampling without replacement).
Value
An object of class "critical_links": a list with the
components
- critical_edges
a
data.framewith columnsnode1,node2,p_value, listing the edges removed until the test became non-significant, ordered from most to least significant;NULLif the global test was not significant.- edges_removed
a list of length-2 integer vectors giving the
(i, j)indices of the removed edges, in removal order.- modified_populations
the input
populationswith the critical edges zeroed out in every graph.- p_value
the permutation
pvalue of the global test on the unmodified data,NAwhen there were no candidate edges.- n_edges
the number of candidate edges considered.
- settings
the arguments the analysis ran with.
- call
the matched call.
Methods are provided for print,
summary and
plot. The first three components are
unchanged from earlier versions, so code that extracts them keeps working.
References
Fraiman, D. and Fraiman, R. (2018) An ANOVA approach for statistical comparisons of brain networks. Scientific Reports, 8, 4746. doi:10.1038/s41598-018-23152-5.
See Also
print.critical_links,
summary.critical_links, plot.critical_links,
compute_test_statistic,
compute_edge_pvalues, get_critical_nodes.
Examples
set.seed(1)
control <- generate_category_graphs(
n_graphs = 15, n_nodes = 10, n_communities = 2,
base_intra_prob = 0.8, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(
n_graphs = 15, n_nodes = 10, n_communities = 2,
base_intra_prob = 0.5, base_inter_prob = 0.5, seed = 2)
populations <- list(Control = control, Patient = patient)
result <- identify_critical_links(
populations, alpha = 0.05, method = "fisher",
n_permutations = 200, seed = 42)
result
summary(result)
head(result$critical_edges)
Plot a Critical-Edge Analysis
Description
Method interface to plot_critical_edges: draws the weighted
central graph of each population alongside a panel highlighting the
critical edges.
Usage
## S3 method for class 'critical_links'
plot(x, populations, ...)
Arguments
x |
An object of class |
populations |
The named |
... |
Further arguments passed to |
Details
The populations must be supplied, because the object stores the modified populations, in which the critical edges have been removed, and plotting them would hide the very structure the figure is about.
Value
Invisibly NULL; called for its side effect.
See Also
plot_critical_edges, which this method wraps and
which can also be called directly.
Examples
set.seed(1)
community_sizes <- c(4, 3, 3)
control <- generate_category_graphs(n_graphs = 30, n_nodes = 10,
n_communities = 3, community_sizes = community_sizes,
base_intra_prob = rep(0.8, 3), base_inter_prob = 0.1, seed = 1)
patient <- generate_category_graphs(n_graphs = 30, n_nodes = 10,
n_communities = 3, community_sizes = community_sizes,
base_intra_prob = c(0.3, 0.8, 0.8), base_inter_prob = 0.1, seed = 2)
populations <- list(Control = control, Patient = patient)
result <- identify_critical_links(populations, n_permutations = 200,
seed = 42)
plot(result, populations,
communities = rep(seq_along(community_sizes), times = community_sizes))
Visualize Central Graphs and Critical Edges
Description
Produces a multi-panel figure summarising the output of
identify_critical_links: one panel per population showing the
weighted central graph, plus a final panel that highlights the critical
edges on a chosen reference central graph. This is the canonical
visualization of the BrainNetTest workflow and replaces the manual
igraph plumbing required to build the same figure.
Usage
plot_critical_edges(
populations,
critical_links,
communities = NULL,
layout = NULL,
central_graphs = NULL,
reference = 1L,
threshold = 0.5,
edge_scale = 6,
critical_color = "red",
critical_width = 3,
background_color = "grey80",
background_width = 1,
vertex_size = 12,
vertex_label = TRUE,
panel_titles = NULL,
mfrow = NULL,
...
)
Arguments
populations |
A named |
critical_links |
The object returned by
|
communities |
Optional integer (or factor) vector of length
|
layout |
Optional layout for the graphs. Either an
|
central_graphs |
Optional list of pre-computed central graphs (one per
population). If |
reference |
Either an integer index or a name selecting which
population's central graph is used as the background of the
critical-edges panel. Default |
threshold |
Numeric in |
edge_scale |
Numeric multiplier applied to the central-graph edge
weights to set |
critical_color, critical_width |
Color and line width used to draw
critical edges. Defaults |
background_color, background_width |
Color and line width used to draw
non-critical edges in the critical panel. Defaults |
vertex_size |
Vertex size passed to |
vertex_label |
Logical. If |
panel_titles |
Optional character vector of length
|
mfrow |
Optional integer vector of length 2 giving the
|
... |
Additional arguments forwarded to
|
Details
The first length(populations) panels show the weighted
central graph of each population, with edge widths proportional to the
central-graph weights. The final panel binarises the chosen reference
central graph at threshold and overlays the critical edges
returned by identify_critical_links() in
critical_color. Critical edges that are absent from the binarised
reference graph are added so that they remain visible.
The graphics state (par(mfrow, mar, oma)) is restored on exit.
Value
Invisibly returns NULL; called for its side effect of
producing the multi-panel plot.
See Also
identify_critical_links,
compute_central_graph,
get_critical_nodes.
Examples
set.seed(123)
community_sizes <- c(4, 2, 3, 3, 5)
control <- generate_category_graphs(
n_graphs = 50, n_nodes = 17, n_communities = 5,
community_sizes = community_sizes,
base_intra_prob = rep(0.70, 5), base_inter_prob = 0.05,
intra_prob_variation = 0.02, inter_prob_variation = 0.01)
patient <- generate_category_graphs(
n_graphs = 50, n_nodes = 17, n_communities = 5,
community_sizes = community_sizes,
base_intra_prob = c(0.40, 0.70, 0.70, 0.70, 0.70),
base_inter_prob = 0.05,
intra_prob_variation = 0.02, inter_prob_variation = 0.01)
populations <- list(Control = control, Patient = patient)
result <- identify_critical_links(populations, alpha = 0.05,
method = "fisher", n_permutations = 200, seed = 1)
communities <- rep(seq_along(community_sizes), times = community_sizes)
plot_critical_edges(populations, result, communities = communities)
Print a Critical-Edge Analysis
Description
Compact report of an identify_critical_links analysis: the
populations compared, the outcome of the global test, and the size of the
critical set together with its most significant edges. Use
summary.critical_links for the call, the analysis settings
and the node-level view as well.
Usage
## S3 method for class 'critical_links'
print(x, n = 6, digits = getOption("digits"), ...)
Arguments
x |
An object of class |
n |
Number of critical edges to display. Default |
digits |
Number of significant digits used for the $p$ values.
Default |
... |
Further arguments, currently ignored. |
Value
x, invisibly.
See Also
summary.critical_links,
plot.critical_links.
Examples
control <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.8, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.5, base_inter_prob = 0.5, seed = 2)
result <- identify_critical_links(list(Control = control, Patient = patient),
n_permutations = 200, seed = 42)
result
Print a Global Test Result
Description
Reports the populations compared, the observed statistic and the
permutation p value of a global_test analysis. An
estimate of zero is reported as being below 1/B, the resolution of
B permutation replicates.
Usage
## S3 method for class 'global_test'
print(x, digits = getOption("digits"), ...)
Arguments
x |
An object of class |
digits |
Number of significant digits used for the statistic.
Default |
... |
Further arguments, currently ignored. |
Value
x, invisibly.
See Also
Examples
control <- generate_category_graphs(n_graphs = 20, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.6, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(n_graphs = 20, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.6, base_inter_prob = 0.4, seed = 2)
global_test(list(Control = control, Patient = patient),
n_permutations = 500, seed = 42)
Print a Critical-Edge Analysis Summary
Description
Print a Critical-Edge Analysis Summary
Usage
## S3 method for class 'summary.critical_links'
print(x, n = 10, digits = getOption("digits"), ...)
Arguments
x |
An object of class |
n |
Number of critical edges and nodes to display. Default |
digits |
Number of significant digits used for the $p$ values.
Default |
... |
Further arguments, currently ignored. |
Value
x, invisibly.
Rank Edges Based on P-Values
Description
This function ranks edges based on their p-values obtained from statistical tests, ordering them from lowest to highest p-value (most to least significant).
Usage
rank_edges(edge_pvalues)
Arguments
edge_pvalues |
A square matrix of p-values for each edge, typically obtained from |
Value
A data frame with edges and their corresponding p-values, ordered from most significant.
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)
# Rank edges based on p-values
edge_df <- rank_edges(edge_pvalues)
# View the top ranked edges
head(edge_df)
Summarise a Critical-Edge Analysis
Description
Extends print.critical_links with the settings the analysis
used and a node-level view of the critical set: the nodes that participate
in the most critical edges, as returned by get_critical_nodes.
Usage
## S3 method for class 'critical_links'
summary(object, node_labels = NULL, ...)
Arguments
object |
An object of class |
node_labels |
Optional character vector of node labels, passed to
|
... |
Further arguments, currently ignored. |
Value
An object of class "summary.critical_links", a list with the
components n_critical, n_edges, p_value,
settings, group_sizes, critical_edges and
critical_nodes.
See Also
identify_critical_links,
get_critical_nodes.
Examples
control <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.8, base_inter_prob = 0.2, seed = 1)
patient <- generate_category_graphs(n_graphs = 15, n_nodes = 10,
n_communities = 2, base_intra_prob = 0.5, base_inter_prob = 0.5, seed = 2)
result <- identify_critical_links(list(Control = control, Patient = patient),
n_permutations = 200, seed = 42)
summary(result)