Skip to content

Edge Selection

PThreshold

Bases: BaseEdgeSelector

Select edges whose correlation with the target is significant at a p-value threshold, optionally after multiple-comparison correction.

Pass a list of thresholds (and/or corrections) to search over them with an inner cross-validation loop.

__init__(threshold=0.05, correction=None)

:param threshold: p-value threshold(s); edges with p below the threshold are selected. A single value (e.g. 0.05) or a list (e.g. [0.01, 0.05]) to tune via inner CV. :param correction: multiple-comparison correction, or None for no correction. Can be one of statsmodels' methods: bonferroni : one-step correction sidak : one-step correction holm-sidak : step down method using Sidak adjustments holm : step-down method using Bonferroni adjustments simes-hochberg : step-up method (independent) hommel : closed method based on Simes tests (non-negative) fdr_bh : Benjamini/Hochberg (non-negative) fdr_by : Benjamini/Yekutieli (negative) bonferroni : one-step correction sidak : one-step correction holm-sidak : step down method using Sidak adjustments holm : step-down method using Bonferroni adjustments simes-hochberg : step-up method (independent) hommel : closed method based on Simes tests (non-negative) fdr_bh : Benjamini/Hochberg (non-negative) fdr_by : Benjamini/Yekutieli (negative) fdr_tsbh : two stage fdr correction (non-negative) fdr_tsbky : two stage fdr correction (non-negative)

UnivariateEdgeSelection

Bases: BaseEstimator

Univariate edge selection for CPM.

Correlates each edge with the target using the chosen statistic and selects edges with one or more selection strategies (e.g. a p-value threshold). When several configurations are supplied, they form a hyperparameter grid that the inner cross-validation loop searches over.

Parameters:

Name Type Description Default
edge_statistic str

Correlation statistic used to relate each edge to the target. One of 'pearson', 'spearman', 'pearson_partial', 'spearman_partial' (continuous target), or 'point_biserial' / 'point_biserial_partial' (binary target). The *_partial variants control for the covariates during selection.

'spearman'
t_test_filter bool

Reserved for an optional pre-filtering step (currently inactive).

False
edge_selection Union[list, None, PThreshold]

One or more selection strategies. Provide a list of multiple configurations to tune them via an inner CV.

None

correlations_and_pvalues(X, Y_perms, correlation_type='pearson', confounds=None)

Univariate edge selection as a vectorised OLS GLM, batched over permutations.

For each edge (column of X) and each (permuted) target (column of Y_perms) this fits, in one batched linear-algebra pass on CPU/GPU, the linear model

Text Only
target ~ intercept [+ confounds] + edge

and returns the edge effect and the p-value of its coefficient. By the Frisch–Waugh–Lovell theorem the coefficient only requires residualising the edge on the confounds — the target is never residualised to obtain the coefficient (its raw values drive it; this is what we want when the target is the thing we ultimately predict). This single path is mathematically identical to:

  • Pearson correlation (continuous target, no confounds)
  • point-biserial correlation (binary 0/1 target, no confounds)
  • the partial-correlation / coefficient F-test (confounds present)
  • Spearman, when X and Y are rank-transformed first.

A binary (0/1) target needs no special handling: regressing it on an edge is the linear-probability model, whose coefficient test equals the point-biserial correlation. (Its homoskedastic p-values are the conventional point-biserial ones; OLS standard errors are not heteroskedasticity-robust, which is standard for this kind of screening filter.)

The reported r is the semi-partial correlation (confounds removed from the connectome edge only, not the target). Its sign and the p-value are those of the regression coefficient, so the choice of semi-partial vs partial affects only the reported effect-size magnitude, never which edges are selected.

Args: X: (N_samples, N_features) — continuous edge values (fixed across perms) Y_perms: (N_samples, N_perms) — target(s), one column per permutation correlation_type: 'pearson' (linear / point-biserial) or 'spearman' (ranks) confounds: optional (N_samples, N_confounds); when given, the edge effect controls for these covariates.

Returns: r_matrix: (N_features, N_perms) — semi-partial correlation (effect size) p_matrix: (N_features, N_perms) — p-value of the edge coefficient

get_residuals(data, confounds)

Regresses out 'confounds' from 'data' using OLS and returns the residuals.

Args: data: (..., N_samples) or (N_samples, ...) The target data (can be X or Y). Can be numpy or torch. confounds: (N_samples, N_confounds). Can be numpy or torch.

Returns: residuals: Same shape and type as data

torch_rankdata(data, dim=-1)

Computes ranks of the data along a given dimension. Equivalent to scipy.stats.rankdata (method='ordinal') but fully vectorized on GPU.