1. Why connectivity for task fMRI?

Activation maps (Chapters 3.2 General Linear Model, 5.1 NiLearn fMRI Basic Analysis) tell you where the brain responded to a condition. Resting-state functional connectivity (6. Functional Connectivity and Resting State) tells you which regions co-fluctuate at baseline. Neither answers the question that drives most cognitive-neuroscience hypotheses: do these regions work together differently when the task changes?

Task-fMRI connectivity fills that gap. Instead of asking “was region A active during condition X?”, we ask:

  • Does the coupling between A and B strengthen under condition X versus Y?
  • Do A and B share information about what the participant is doing — not just amplitude, but pattern content?

This chapter walks through two methods that answer those questions: psychophysiological interaction (PPI / gPPI) for amplitude-level coupling, and representational similarity analysis (RSA) and informational connectivity for content-level coupling. Huang et al. (2024) 1 is the unifying review and the main reference for what follows.

connectivity is not causality

All methods in this chapter describe statistical dependence between regions under different task contexts. None of them, on their own, license claims like “A drives B”. Effective-connectivity methods such as dynamic causal modelling (DCM) and Granger causality try harder at directionality but are themselves model-dependent and are out of scope here.


2. A spectrum of task-connectivity methods

The Huang et al. review organises the field along a spectrum from amplitude-only to information-rich:

FamilyQuestionRepresentative methodUnit of analysis
Activation-basedDoes amplitude in B track amplitude in A as a function of task?PPI, gPPI, beta-series correlationSingle voxel / ROI time series
Effective / model-basedIs there a directed influence from A to B consistent with model M?DCM, Granger causalityGenerative model parameters
Information-basedDo A and B carry the same content about the task?RSA, informational connectivity, MVPA-basedMultivoxel patterns

You can think of it as moving from “do their needles move together?” to “do they read the same book?” The methods are complementary — a region pair can be tightly coupled in amplitude yet carry orthogonal information, and vice versa.

which task-connectivity method?

  • “Does coupling between A and B change with condition?” → PPI / gPPI.
  • “Do A and B share information about the condition labels or stimuli?” → RSA or informational connectivity.
  • “Is there a directed influence from A to B consistent with a generative model?” → DCM (not covered here; see Friston, Harrison & Penny, 2003).

3. Psychophysiological Interaction (PPI)

3.1 The conceptual model

PPI was introduced by Friston et al. (1997) 2 as a regression-based way to ask whether the relationship between a seed region and the rest of the brain changes as a function of an experimental variable. The first-level GLM for a target voxel is:

The fourth term is the PPI regressor: the elementwise product of the seed time series and the psychological task regressor. Its coefficient is the connectivity-by-condition estimate — the change in seed–target coupling attributable to the task contrast. Take to group level and you have a task-connectivity map.

There is one subtlety. The seed BOLD signal is a convolved (smoothed) version of underlying neural activity, but the psychological regressor lives in neural time. Multiplying them directly mixes timescales. The classical Friston recipe deconvolves the seed with the HRF first, forms the product in neural space, then reconvolves the interaction with the HRF before entering it into the GLM. Cisler et al. (2014) 3 showed that for fast event-related designs the deconvolution step can hurt more than it helps, and that BOLD-domain PPI (no deconvolution) often does as well or better — useful to know when picking a software path.

3.2 Generalised PPI (gPPI)

Original PPI was designed for two-condition blocked experiments. McLaren et al. (2012) 4 generalised it to arbitrary task designs: instead of one interaction regressor, gPPI includes one PPI regressor per task condition, plus the original psychological regressors and the seed time course. The contrast you care about is then formed across PPI betas (e.g. ) rather than baked into a single product. This:

  • handles event-related and multi-condition designs cleanly,
  • reduces false negatives caused by misspecifying the “psychological” contrast a priori,
  • and is now the de-facto default (the original two-condition PPI is essentially deprecated).

always use gPPI, not classical PPI

Unless you are reproducing a specific historical analysis, set up your design as gPPI. McLaren et al. (2012) simulations show classical PPI is biased whenever the task has more than two conditions or unequal trial counts.

3.3 A nilearn workflow sketch

Nilearn does not ship a one-call PPI helper, but everything you need is already in 5.1 NiLearn fMRI Basic Analysis: a FirstLevelModel, a design matrix, and per-subject contrasts. PPI is just a design-matrix extension.

import numpy as np, pandas as pd, os
from nilearn.glm.first_level import (
    FirstLevelModel, make_first_level_design_matrix
)
from nilearn.maskers import NiftiSpheresMasker
 
bids_dir     = os.environ["BIDS_DIR"]
fmriprep_dir = os.environ["FMRIPREP_DIR"]
work_dir     = os.environ["WORK_DIR"]
 
func     = f"{fmriprep_dir}/sub-01/func/sub-01_task-stroop_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz"
events   = pd.read_csv(f"{bids_dir}/sub-01/func/sub-01_task-stroop_events.tsv", sep="\t")
t_r      = 2.0
n_scans  = 200
frame_times = np.arange(n_scans) * t_r
 
# 1. Standard task design matrix (HRF-convolved condition regressors)
dm = make_first_level_design_matrix(
    frame_times, events=events, hrf_model="spm",
    drift_model="cosine", high_pass=1./128
)
 
# 2. Extract seed time series from a sphere ROI (e.g. left dlPFC)
seed_masker = NiftiSpheresMasker(seeds=[(-40, 30, 30)], radius=6,
                                 standardize="zscore_sample",
                                 detrend=True, t_r=t_r)
seed_ts = seed_masker.fit_transform(func).ravel()        # shape (n_scans,)
 
# 3. Build gPPI interaction regressors: seed * each condition regressor
#    (BOLD-domain PPI; for deconvolution-based PPI use a toolbox)
conditions = [c for c in dm.columns if c in events["trial_type"].unique()]
for cond in conditions:
    dm[f"PPI_{cond}"] = seed_ts * dm[cond].values
 
# 4. Add the seed itself as a covariate (physiological main effect)
dm["seed"] = seed_ts
 
# 5. Fit and contrast PPI betas across conditions
flm = FirstLevelModel(t_r=t_r, mask_img=None,
                      smoothing_fwhm=6, noise_model="ar1").fit(
    func, design_matrices=dm
)
ppi_contrast = flm.compute_contrast(
    "PPI_incongruent - PPI_congruent", output_type="effect_size"
)
ppi_contrast.to_filename(f"{work_dir}/sub-01_PPI_incong-cong.nii.gz")

That ppi_contrast map is the subject-level connectivity-by-condition effect. Feed it to SecondLevelModel exactly as you would any other COPE (see 5.1 NiLearn fMRI Basic Analysis §4 and 4.2 High-level Analysis with FSL).

motion confounds dominate weak PPI effects

PPI betas are typically small and easily corrupted by motion-driven coupling. Always include the same nuisance regressors you would for a univariate GLM — see 5.2 Confound Selection. Concatenate them into dm before fitting.

For users who prefer a maintained toolbox over hand-rolled design matrices, SPM’s PPI module (GUI + scripting) and McLaren’s gPPI toolbox for SPM are the standard. FSL ships PPI as a flag in FEAT. All three implement the deconvolve-multiply-reconvolve recipe.

3.4 PPI caveats

  • Low sensitivity. PPI effects are roughly an order of magnitude smaller than main-effect activations. Power calculations should assume you need 30+ subjects for whole-brain inference at cluster-corrected .
  • HRF mismatch. Deconvolution amplifies high-frequency noise. With short TRs and high SNR it is fine; with TR ≥ 2 s and fast event timing, consider BOLD-domain PPI (Cisler et al., 2014).
  • Interpretation. describes a regression slope, not a causal arrow. A significant PPI between A and B is compatible with A driving B, B driving A, or a common modulator C driving both.
  • Cluster correction is non-trivial. PPI residuals are autocorrelated differently than main-effect GLM residuals; permutation-based thresholding (5.3 Visualization and Statistical Thresholding with Nilearn) is the safest default.

4. Representational Similarity Analysis (RSA)

PPI asks whether amplitudes co-vary. RSA asks a deeper question: do two regions encode the same set of distinctions? Two regions might both be active for every face, but one might distinguish identities and the other only male-vs-female. PPI cannot tell them apart; RSA can.

4.1 The core idea

Kriegeskorte, Mur & Bandettini (2008) 5 reduced every region’s response to a representational dissimilarity matrix (RDM): a matrix where entry is the dissimilarity of the multivoxel patterns evoked by conditions and . Common dissimilarity metrics:

  • between pattern vectors (scale-invariant);
  • Mahalanobis distance (sensitive to noise covariance — preferred when you have many trials per condition);
  • crossnobis distance (Mahalanobis with cross-validation across runs — bias-free, recommended in Diedrichsen & Kriegeskorte, 2017).

The RDM is the region’s “fingerprint” in representational space. Once you have one RDM per region, you can:

  1. Compare to a model RDM (theory-driven): does V1 cluster stimuli by retinotopy, IT by category?
  2. Compare RDMs across regions (data-driven): which regions share representational geometry? This is representational connectivity in the sense used by Huang et al. (2024).

4.2 Workflow

1. Single-trial (or per-condition) betas via LSS GLM
2. Extract pattern vectors per ROI
3. Compute RDM per ROI (pdist)
4. Compare RDMs:
     - against a model RDM → Spearman/Kendall correlation
     - against another ROI's RDM → representational connectivity
5. Fisher-z transform before group-level inference

use LSS, not LSA, for closely-spaced trials

Naively fitting one regressor per trial in a single GLM (LSA — least squares all) blows up the design matrix’s collinearity when trials are seconds apart. Mumford et al. (2012) 6 showed that LSS — fitting one GLM per trial, with that trial as a regressor and all other trials lumped into a nuisance regressor — gives much cleaner single-trial estimates. Most RSA pipelines now default to LSS.

4.3 A minimal RSA snippet

Assume betas_roi1 and betas_roi2 are (n_conditions, n_voxels) arrays of LSS-derived condition betas extracted from two ROIs.

import numpy as np
from scipy.spatial.distance import pdist, squareform
from scipy.stats import spearmanr
 
def rdm(patterns, metric="correlation"):
    """patterns: (n_conditions, n_voxels) -> condensed RDM."""
    return pdist(patterns, metric=metric)
 
rdm1 = rdm(betas_roi1)          # condensed vectors, length K*(K-1)/2
rdm2 = rdm(betas_roi2)
 
# Representational connectivity: how similar are the two regions' geometries?
rho, p = spearmanr(rdm1, rdm2)
print(f"ROI1 <-> ROI2 representational similarity: rho = {rho:.3f}, p = {p:.3g}")
 
# Compare to a model RDM (e.g. binary same-category matrix)
model_rdm = pdist(category_labels.reshape(-1, 1), metric="hamming")
rho_model, p_model = spearmanr(rdm1, model_rdm)

For anything beyond a quick sanity check, use rsatoolbox (https://rsatoolbox.readthedocs.io/), the Kriegeskorte-lab Python library. It handles crossnobis distances, noise normalisation, bootstrap inference over stimuli and subjects, and model comparison — all things you do not want to re-implement.

pip install rsatoolbox

4.4 RSA caveats

  • Metric choice matters. Correlation distance discards mean-activation differences (often a feature, sometimes a bug). Crossnobis is the safest default when you have multiple runs.
  • Single-trial beta noise. LSS reduces but does not eliminate the problem. With < 8 trials per condition, RDM estimates are unstable; bootstrap CIs are essential.
  • Always Fisher-z before averaging correlations of RDMs across subjects. Spearman values do not average linearly.
  • Searchlight RSA (sliding the RDM analysis through small spheres) inherits all the multiple-comparisons problems of voxel-wise GLM and then some. Use permutation-based cluster inference; see 5.3 Visualization and Statistical Thresholding with Nilearn.

5. Informational connectivity

Representational connectivity (§4) compares average RDMs between regions: a single similarity value per pair. Coutanche & Thompson-Schill (2013) 7 introduced a time-resolved cousin: informational connectivity (IC).

The recipe:

  1. Train a classifier (or decode discriminability score) per trial in region A.
  2. Do the same for region B.
  3. Correlate the trial-by-trial discriminability time series between A and B.

If A and B fluctuate together in how well they can tell conditions apart — not just in how active they are — they are “informationally connected”. This is the natural analogue of functional connectivity in the representational regime, and it can dissociate from amplitude FC: two regions can be tightly amplitude-coupled while their decoding successes are independent, indicating they encode the task in parallel rather than sharing content.

IC is rarely a master’s-project workhorse — it requires many trials per condition and a decoder you trust — but it is a useful concept to know exists when reviewers ask “is amplitude coupling enough?“.


6. Common pitfalls across methods

before you trust any task-connectivity result

  • Motion. Both PPI and RSA are sensitive to motion-driven artefacts that mimic task-locked coupling. Always include the standard fMRIPrep nuisance set (see 5.2 Confound Selection).
  • Single-subject sample size. PPI effects are tiny; pilot estimates from are essentially uninformative.
  • Cluster correction. Voxel-wise FDR is rarely defensible for connectivity maps. Prefer non-parametric / permutation thresholding (nilearn.glm.thresholding.threshold_stats_img with cluster-level correction, or FSL randomise). See 5.3 Visualization and Statistical Thresholding with Nilearn.
  • Seed selection bias. Picking a seed ROI from the same data you then analyse is circular (“double-dipping”). Define seeds from a separate localiser, an independent atlas, or leave-one-subject-out folds.
  • Reporting. State exactly which PPI flavour (classical, gPPI, beta-series), which deconvolution choice (BOLD-domain vs neural-domain), and which RDM distance you used. These choices change results.

7. Where to go next

  • For a generative, directed model of how regions influence each other (DCM, structural causal models): Friston, Harrison & Penny (2003) and Stephan et al. (2010).
  • For dynamic / time-varying connectivity during a task: see the dynamic FC section of 6. Functional Connectivity and Resting State.
  • For full-pipeline tooling: nilearn for hand-rolled PPI/RSA, rsatoolbox for production RSA, SPM gPPI toolbox or FSL FEAT-PPI for vetted PPI implementations.

References

Diedrichsen, J., & Kriegeskorte, N. (2017). Representational models: A common framework for understanding encoding, pattern-component, and representational-similarity analysis. PLOS Computational Biology, 13(4), e1005508. https://doi.org/10.1371/journal.pcbi.1005508

Footnotes

  1. Huang, S., De Brigard, F., Cabeza, R., & Davis, S. W. (2024). Connectivity analyses for task-based fMRI. Physics of Life Reviews, 49, 139–156. https://doi.org/10.1016/j.plrev.2024.04.012

  2. Friston, K. J., Buechel, C., Fink, G. R., Morris, J., Rolls, E., & Dolan, R. J. (1997). Psychophysiological and modulatory interactions in neuroimaging. NeuroImage, 6(3), 218–229. https://doi.org/10.1006/nimg.1997.0291

  3. Cisler, J. M., Bush, K., & Steele, J. S. (2014). A comparison of statistical methods for detecting context-modulated functional connectivity in fMRI. NeuroImage, 84, 1042–1052. https://doi.org/10.1016/j.neuroimage.2013.09.018

  4. McLaren, D. G., Ries, M. L., Xu, G., & Johnson, S. C. (2012). A generalized form of context-dependent psychophysiological interactions (gPPI): A comparison to standard approaches. NeuroImage, 61(4), 1277–1286. https://doi.org/10.1016/j.neuroimage.2012.03.068

  5. Kriegeskorte, N., Mur, M., & Bandettini, P. (2008). Representational similarity analysis — connecting the branches of systems neuroscience. Frontiers in Systems Neuroscience, 2, 4. https://doi.org/10.3389/neuro.06.004.2008

  6. Mumford, J. A., Turner, B. O., Ashby, F. G., & Poldrack, R. A. (2012). Deconvolving BOLD activation in event-related designs for multivoxel pattern classification analyses. NeuroImage, 59(3), 2636–2643. https://doi.org/10.1016/j.neuroimage.2011.08.076

  7. Coutanche, M. N., & Thompson-Schill, S. L. (2013). Informational connectivity: identifying synchronized discriminability of multi-voxel patterns across the brain. Frontiers in Human Neuroscience, 7, 15. https://doi.org/10.3389/fnhum.2013.00015