stats
tit.stats ¶
Cluster-based permutation testing for TI-Toolbox.
Provides group comparison and correlation analyses with cluster-based permutation correction for multiple comparisons. Both workflows produce NIfTI output maps, diagnostic plots, and text summaries written to the BIDS derivatives tree.
Public API¶
run_group_comparison Two-group voxelwise comparison with cluster-based permutation correction. run_correlation Voxelwise brain-behavior correlation with cluster-based permutation correction (ACES-style). GroupComparisonConfig Configuration dataclass for group comparison. GroupComparisonResult Result container for group comparison. CorrelationConfig Configuration dataclass for correlation analysis. CorrelationResult Result container for correlation analysis.
See Also¶
tit.analyzer : Single-subject ROI-level field analysis.
CorrelationConfig
dataclass
¶
CorrelationConfig(analysis_name: str, subjects: list[Subject], correlation_type: CorrelationType = PEARSON, cluster_threshold: float = 0.05, cluster_stat: ClusterStat = MASS, n_permutations: int = 1000, alpha: float = 0.05, n_jobs: int = -1, use_weights: bool = True, tissue_type: TissueType = GREY, nifti_file_pattern: str | None = None, effect_metric: str = 'Effect Size', field_metric: str = 'Electric Field Magnitude', atlas_files: list[str] = list())
Configuration for correlation-based cluster permutation testing.
Tests voxelwise correlation between brain field intensities and a continuous behavioral or clinical measure (effect size) across subjects, with cluster-based permutation correction for multiple comparisons.
Attributes¶
analysis_name : str
Human-readable name for this analysis run.
subjects : list of Subject
Subject entries with associated effect sizes.
correlation_type : CorrelationType
Pearson or Spearman rank correlation.
cluster_threshold : float
Uncorrected p-value threshold for forming clusters.
cluster_stat : ClusterStat
Cluster-level statistic used for permutation testing
("mass" or "size").
n_permutations : int
Number of permutations for the null distribution.
alpha : float
Family-wise error rate for significance.
n_jobs : int
Number of parallel workers (-1 for all CPUs).
use_weights : bool
Whether to apply per-subject weights during correlation.
tissue_type : TissueType
Which tissue compartment to analyze.
nifti_file_pattern : str or None
Filename pattern for subject NIfTI files. If None, derived
automatically from tissue_type.
effect_metric : str
Label for the behavioral/clinical variable in plots.
field_metric : str
Label for the field intensity axis in plots.
atlas_files : list of str
Atlas filenames for overlap analysis (looked up in the bundled
atlas directory).
See Also¶
CorrelationResult : Result container returned by the analysis. run_correlation : Orchestration function that consumes this config.
Subject
dataclass
¶
A single subject in a correlation analysis.
Attributes¶
subject_id : str
Subject identifier (without sub- prefix).
simulation_name : str
Name of the simulation to load for this subject.
effect_size : float
Continuous behavioral or clinical measure to correlate with
field intensity.
weight : float
Per-subject weight (default 1.0).
load_subjects
classmethod
¶
Load correlation subjects from a CSV file.
Expected columns: subject_id, simulation_name,
effect_size. Optional column: weight. Rows with NaN
subject_id or effect_size are silently skipped. The sub-
prefix is stripped from subject IDs automatically.
Parameters¶
csv_path : str Path to a CSV file with the required columns.
Returns¶
list of Subject Subject instances parsed from valid CSV rows.
Raises¶
ValueError If required columns are missing or no valid subjects are found.
Source code in tit/stats/config.py
CorrelationResult
dataclass
¶
CorrelationResult(success: bool, output_dir: str, n_subjects: int, n_significant_voxels: int, n_significant_clusters: int, cluster_threshold: float, analysis_time: float, clusters: list, log_file: str)
Result of a correlation-based cluster permutation test.
Attributes¶
success : bool Whether the analysis completed without error. output_dir : str Absolute path to the directory containing all outputs (NIfTI maps, plots, summary text, log). n_subjects : int Number of subjects included in the analysis. n_significant_voxels : int Total voxels surviving cluster-corrected threshold. n_significant_clusters : int Number of spatially contiguous clusters that survived permutation correction. cluster_threshold : float Cluster-level statistic threshold derived from the permutation null distribution at the requested alpha. analysis_time : float Wall-clock duration of the full analysis in seconds. clusters : list of dict One entry per significant cluster, containing size, mass, peak coordinates, mean/peak correlation coefficients, and atlas overlap info. log_file : str Absolute path to the analysis log file.
See Also¶
CorrelationConfig : Configuration that produced this result. run_correlation : Function that returns this result.
GroupComparisonConfig
dataclass
¶
GroupComparisonConfig(analysis_name: str, subjects: list[Subject], test_type: TestType = UNPAIRED, alternative: Alternative = TWO_SIDED, cluster_threshold: float = 0.05, cluster_stat: ClusterStat = MASS, n_permutations: int = 1000, alpha: float = 0.05, n_jobs: int = -1, tissue_type: TissueType = GREY, nifti_file_pattern: str | None = None, group1_name: str = 'Responders', group2_name: str = 'Non-Responders', value_metric: str = 'Current Intensity', atlas_files: list[str] = list())
Configuration for cluster-based permutation testing between two groups.
Compares voxelwise field intensities between responders and non-responders using a t-test with cluster-based permutation correction for multiple comparisons.
Attributes¶
analysis_name : str
Human-readable name for this analysis run.
subjects : list of Subject
Subject entries, each labelled as responder (1) or non-responder (0).
test_type : TestType
Whether to use an unpaired or paired t-test.
alternative : Alternative
Sidedness of the test hypothesis.
cluster_threshold : float
Uncorrected p-value threshold for forming clusters.
cluster_stat : ClusterStat
Cluster-level statistic used for permutation testing
("mass" or "size").
n_permutations : int
Number of permutations for the null distribution.
alpha : float
Family-wise error rate for significance.
n_jobs : int
Number of parallel workers (-1 for all CPUs).
tissue_type : TissueType
Which tissue compartment to analyze.
nifti_file_pattern : str or None
Filename pattern for subject NIfTI files. If None, derived
automatically from tissue_type.
group1_name : str
Display label for the responder group.
group2_name : str
Display label for the non-responder group.
value_metric : str
Label for the field value axis in plots.
atlas_files : list of str
Atlas filenames for overlap analysis (looked up in the bundled
atlas directory).
See Also¶
GroupComparisonResult : Result container returned by the analysis. run_group_comparison : Orchestration function that consumes this config.
Subject
dataclass
¶
A single subject in a group comparison analysis.
Attributes¶
subject_id : str
Subject identifier (without sub- prefix).
simulation_name : str
Name of the simulation to load for this subject.
response : int
Group label -- 1 for responder, 0 for non-responder.
load_subjects
classmethod
¶
Load group comparison subjects from a CSV file.
Expected columns: subject_id, simulation_name, response
(0 or 1). The sub- prefix is stripped from subject IDs
automatically.
Parameters¶
csv_path : str Path to a CSV file with the required columns.
Returns¶
list of Subject Subject instances parsed from the CSV rows.
Raises¶
ValueError If required columns are missing from the CSV.
Source code in tit/stats/config.py
GroupComparisonResult
dataclass
¶
GroupComparisonResult(success: bool, output_dir: str, n_responders: int, n_non_responders: int, n_significant_voxels: int, n_significant_clusters: int, cluster_threshold: float, analysis_time: float, clusters: list, log_file: str)
Result of a group comparison permutation test.
Attributes¶
success : bool Whether the analysis completed without error. output_dir : str Absolute path to the directory containing all outputs (NIfTI maps, plots, summary text, log). n_responders : int Number of responder subjects included. n_non_responders : int Number of non-responder subjects included. n_significant_voxels : int Total voxels surviving cluster-corrected threshold. n_significant_clusters : int Number of spatially contiguous clusters that survived permutation correction. cluster_threshold : float Cluster-level statistic threshold derived from the permutation null distribution at the requested alpha. analysis_time : float Wall-clock duration of the full analysis in seconds. clusters : list of dict One entry per significant cluster, containing size, mass, peak coordinates, and atlas overlap info. log_file : str Absolute path to the analysis log file.
See Also¶
GroupComparisonConfig : Configuration that produced this result. run_group_comparison : Function that returns this result.
run_correlation ¶
run_correlation(config: CorrelationConfig, callback_handler=None, stop_callback=None) -> CorrelationResult
Run cluster-based permutation testing for correlation (ACES-style).
Loads subject NIfTI volumes and effect sizes, computes voxelwise correlation, applies cluster-based permutation correction, generates diagnostic plots, and saves all outputs to the BIDS derivatives tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CorrelationConfig
|
Fully specified correlation configuration. |
required |
callback_handler
|
Optional |
None
|
|
stop_callback
|
Optional callable that returns |
None
|
Returns:
| Type | Description |
|---|---|
CorrelationResult
|
A |
CorrelationResult
|
paths to all generated output files. |
Raises:
| Type | Description |
|---|---|
KeyboardInterrupt
|
If |
Source code in tit/stats/permutation.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
run_group_comparison ¶
run_group_comparison(config: GroupComparisonConfig, callback_handler=None, stop_callback=None) -> GroupComparisonResult
Run cluster-based permutation testing for group comparison.
Loads responder and non-responder NIfTI volumes, performs voxelwise t-tests, applies cluster-based permutation correction, generates diagnostic plots, and saves all outputs to the BIDS derivatives tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
GroupComparisonConfig
|
Fully specified group comparison configuration. |
required |
callback_handler
|
Optional |
None
|
|
stop_callback
|
Optional callable that returns |
None
|
Returns:
| Type | Description |
|---|---|
GroupComparisonResult
|
A |
GroupComparisonResult
|
including paths to all generated output files. |
Raises:
| Type | Description |
|---|---|
KeyboardInterrupt
|
If |