adjacency_permutation_test#

adjacency_permutation_test(domain, network_name, label_name, population=None, include_boundaries=None, exclude_boundaries=None, boundary_exclude_distance=0, adjacency_order=1, label_shuffle_iterations=100, alpha=0.05, transform_counts=None, observation_threshold=15, visualise_output=False, visualise_correlation_matrix_kwargs={})#

Test the correlation between adjacency labels in a network, also referred to as neighbourhood enrichment. This function computes the adjacency correlation matrix by considering the k-hop neighborhood of each object within the network by performing label shuffling to generate a null distribution and computing the standard effect size (SES) and corrected p-values (Benjamini-Hochberg) to identify significant adjacent label correlations.

Parameters:
domainobject

The domain object containing networks and labels.

network_namestr, optional

The name of the network to be analysed. Default is None.

label_namestr, optional

The name of the label to be analysed. Default is None.

populationarray-like or query, optional

A query or array of object indices to filter the labels. Default is None.

include_boundariesarray-like, query-like, or None, optional

Boundaries to include in the analysis. Defaults to None.

exclude_boundariesarray-like, query-like, or None, optional

Boundaries to exclude from the analysis. Defaults to None.

boundary_exclude_distancefloat, optional

Buffer to exclude objects located within boundary_exclude_distance from the boundaries. Defaults to 0.

adjacency_orderint, optional

The order of adjacency to consider for neighborhood. Default is 1.

label_shuffle_iterationsint, optional

The number of iterations for label shuffling. Default is 100.

alphafloat, optional

The significance level for p-value correction. Default is 0.05.

transform_countsstr, optional

The transformation to apply to the counts. Options are ‘arcsinh’, ‘log’, ‘sqrt’, or None. Default is None.

observation_thresholdint, optional

The minimum number of observations for a label in the network to be considered. Default is 15.

visualise_outputbool, optional

Whether to visualise the adjacency correlation matrix. Default is False.

visualise_correlation_matrix_kwargsdict, optional

Additional keyword arguments for visualising the correlation matrix.

Returns:
SESndarray

The standardized effect size matrix. Ordering of labels is the same as unique_labels_following_query.

Andarray

The p-value matrix. Ordering of labels is the same as unique_labels_following_query.

unique_labels_following_queryndarray

The unique labels considered after applying the query.

Raises:
RuntimeError

If the network name or label name is not found in the domain.

ValueError

If the label is not categorical or if the query type is incorrect.

Examples

Minimal example of computing and visualising the adjacency permutation test on a dataset:

import muspan as ms

# load example domain
example_domain = ms.datasets.load_example_domain('Synthetic-Points-Exclusion')

# generate a network modelling cell-cell contact
ms.networks.generate_network(example_domain,
                            network_name='contact network',
                            network_type='delaunay',
                            max_edge_distance=20)

# compute adjacency permutation test on the contact network
adj_zscore,adj_zscore_pval_filtered,label_cats = ms.networks.adjacency_permutation_test(example_domain,
                                                                                        label_name='Celltype',
                                                                                        network_name='contact network',
                                                                                        visualise_output=True)