permutation
tit.stats.permutation ¶
Cluster-based permutation testing for TI-Toolbox.
Entry points
run_group_comparison(config) -- GroupComparisonResult
run_correlation(config) -- CorrelationResult
Both accept an optional callback_handler (logging.Handler) for GUI
console integration and a stop_callback callable for user-initiated
cancellation.
run_group_comparison ¶
run_group_comparison(config: GroupComparisonConfig, callback_handler: Handler | None = None, stop_callback: Callable[[], bool] | None = None) -> GroupComparisonResult
Run cluster-based permutation testing for a two-group comparison.
Loads responder and non-responder field maps, performs voxelwise (or,
for config.space == "fsaverage", vertexwise) t-tests, applies
cluster-based permutation correction, generates diagnostic plots, and
saves all outputs under
<project>/derivatives/ti-toolbox/stats/group_comparison/<analysis_name>/.
Parameters¶
config : GroupComparisonConfig
Fully specified group comparison configuration.
callback_handler : logging.Handler or None, optional
Extra handler attached to the run-scoped logger (used by the app
to stream log lines).
stop_callback : callable or None, optional
Zero-argument callable returning True to request early
termination. Checked between pipeline stages.
Returns¶
GroupComparisonResult Summary of the outcome: output directory, subject counts, significant voxel/cluster counts, the permutation-derived cluster threshold and the per-cluster details.
Raises¶
KeyboardInterrupt
If stop_callback returns True during execution.
ValueError
If the subjects' NIfTIs do not share one grid (the message names
the offending subject).
FileNotFoundError
If a subject's MNI-space NIfTI (per config.nifti_file_pattern)
or fsaverage projection is missing.
Notes¶
Permutation p-values are (b + 1) / (m + 1), so with 1000
permutations the floor is 1/1001; a result is never exactly 0.
Examples¶
from tit.stats import GroupComparisonConfig, run_group_comparison subjects = GroupComparisonConfig.load_subjects("subjects.csv") # doctest: +SKIP cfg = GroupComparisonConfig( ... analysis_name="active_vs_sham", subjects=subjects, ... test_type="unpaired", n_permutations=1000, tissue_type="grey", ... ) # doctest: +SKIP res = run_group_comparison(cfg) # doctest: +SKIP res.success, res.n_significant_clusters, res.output_dir # doctest: +SKIP (True, 2, '.../derivatives/ti-toolbox/stats/group_comparison/active_vs_sham')
See Also¶
GroupComparisonConfig : The configuration consumed here. GroupComparisonResult : The returned container. run_correlation : Brain-behaviour correlation with the same correction.
Source code in tit/stats/permutation.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
run_correlation ¶
run_correlation(config: CorrelationConfig, callback_handler: Handler | None = None, stop_callback: Callable[[], bool] | None = None) -> CorrelationResult
Run cluster-based permutation testing for a brain-behaviour correlation.
Correlates each voxel's field value with a continuous per-subject
measure (Subject.effect_size), Pearson or Spearman, with
cluster-based permutation correction (ACES-style). Outputs go under
<project>/derivatives/ti-toolbox/stats/correlation/<analysis_name>/.
Parameters¶
config : CorrelationConfig
Fully specified correlation configuration.
callback_handler : logging.Handler or None, optional
Extra handler attached to the run-scoped logger.
stop_callback : callable or None, optional
Zero-argument callable returning True to request early
termination.
Returns¶
CorrelationResult Output directory, subject count, significant voxel/cluster counts, cluster threshold and per-cluster details.
Raises¶
KeyboardInterrupt
If stop_callback returns True during execution.
FileNotFoundError
If a subject's NIfTI is missing.
Examples¶
from tit.stats import CorrelationConfig, run_correlation subjects = CorrelationConfig.load_subjects("subjects_continuous.csv") # doctest: +SKIP cfg = CorrelationConfig(analysis_name="dose_response", subjects=subjects, ... correlation_type="spearman") # doctest: +SKIP run_correlation(cfg).n_significant_clusters # doctest: +SKIP 1
See Also¶
CorrelationConfig : The configuration consumed here. run_group_comparison : Two-group comparison with the same correction.