Analysis code for the SPACE (Supportive Parenting for Anxious Childhood Emotions) fMRI change study: neuroimaging and clinical-outcome analyses of an emotion face processing task collected pre- and post-treatment, under parent-accompanied and alone scan conditions, across two randomized-controlled-trial phases (Phase I: SPACE vs. PE; Phase II: SPACE vs. CBT).This repo contains the complete analysis pipeline underlying the reported neuroimaging and clinical results.
| Script | Stage | Produces |
|---|---|---|
01_aggregate_data.sh |
Data aggregation (HPC) | Smoothed, condition-contrasted first-level activation volumes |
02_extract_roi_activation.py |
ROI extraction (HPC) | Per-subject Shen 368-parcel median activation (long format) |
03_create_clinical_brain_volumes.py |
Covariate volumes (HPC) | Per-subject symptom-score brain volumes for downstream masking |
04_build_final_datasets.py |
Dataset construction | 5 FINAL analysis datasets (Phase I/II x ITT/PP, cross-phase) |
05_neuroimaging_lme.R |
Primary neuroimaging analysis | Table 3, Figure 2 — hierarchical TIME x TX x CONDITION LMEs per ROI |
06_clinical_outcomes_lme.R |
Primary clinical analysis | Tables 1-2, Figure 1 — TIME x TX LMEs for PARS/FASA-P/FASA-C |
07_clinical_neuro_subsamples.R |
Supplementary clinical analysis | Clinical LMEs restricted to the neuroimaging subsamples |
08_scanner_sensitivity.R |
Sensitivity analysis | Leave-two-out refit excluding subjects scanned on a different scanner |
09_phase_sensitivity.R |
Sensitivity analysis | Permutation test distinguishing power loss from Phase I-specific effects |
10_qc_selection_analysis.py |
Selection-bias analysis | QC-included vs. QC-excluded participant comparison |
11_plot_amygdala_3way.R |
Figure generation | Phase II amygdala TIME x TX x CONDITION interaction plot |
Shared logic used by more than one numbered script is factored into four helper files, each sourced by the scripts that need it:
| Helper | Used by |
|---|---|
data_loading_helpers.R |
05, 08, 09, 11 |
neuro_lme_helpers.R |
05, 08 |
neuro_plot_helpers.R |
05, 11 |
clinical_lme_helpers.R |
06, 07 |
R (developed against R 4.3.1): lme4, lmerTest, ggplot2, dplyr,
ggExtra, lavaan, grid, patchwork, stringr, ggpubr, tidyr,
foreach, doParallel.
Python: numpy, pandas, scipy, joblib, nibabel, pyreadstat.
External tools: AFNI (3dmaskave, 3dmerge, 3dcalc) for stages 1-2;
an HPC environment with an environment-module system (module load AFNI) for
stages 1-3, which are designed to run on a compute cluster rather than locally.
Run the numbered scripts in order; each stage's output feeds the next. Stages 1-3 require raw imaging data and AFNI/HPC access and are not reproducible outside that environment; stages 4 onward operate on the tabular outputs of stages 1-3 and can be run on any machine with the Python/R dependencies above installed.
bash 01_aggregate_data.sh # HPC only
python 02_extract_roi_activation.py # HPC only
python 03_create_clinical_brain_volumes.py # HPC only
python 04_build_final_datasets.py
Rscript 05_neuroimaging_lme.R
Rscript 06_clinical_outcomes_lme.R
Rscript 07_clinical_neuro_subsamples.R
Rscript 08_scanner_sensitivity.R
Rscript 09_phase_sensitivity.R
python 10_qc_selection_analysis.py
Rscript 11_plot_amygdala_3way.RScripts 05-11 use control flags (near the top of each file) to toggle optional branches (e.g. exploratory post-hoc reporting, SEM, residualization); all flags default to the setting used for the reported manuscript results.
Note on file paths: scripts in this directory read their base directories
from environment variables (e.g. SPACE_BASE, SPACE_DATA_DIR,
SPACE_OUT_DIR) with placeholder defaults. Set these variables to point to
the location of the corresponding input files before running the scripts in
your environment.