MATLAB reference implementation of the Sliding-Window Channel Capacity (and Prediction Correlation) framework for estimating the time-varying strength (prediction-correlation) and duration (how long directed influence persists across windows) of directed interactions between ROI time series (e.g., fMRI BOLD).
- data input: data.mat
- main script to run swcc: main_script2run_swcc.m
- functions that execute swcc: ./swccv0226/sliding_pcorr_cc_window.m & ./swccv0226/pcorr_cc_x2y.m
main_script2run_swcc.m— demo driver script (load data → run SWCC and Pcorr → save outputs)data.mat— demo input dataswccv0226/sliding_pcorr_cc_window.m— sliding-window wrapperpcorr_cc_x2y.m— core estimator (fit + order selection + correlation)
- MATLAB
- Statistics and Machine Learning Toolbox (
aicbic) - Optimization Toolbox only if using positivity constraint (
lsqlinviaConstraint='p')
In MATLAB (repo root):
run('main_script2run_swcc.m')SWpC is called on two vectors per direction:
tc1(source):(T x 1)tc2(target):(T x 1)
To use more ROIs, construct input as (nroi x T) and loop over ROI pairs (as in the demo script).
-
TR(sec)
Sampling interval. -
windowsize_duration(sec)
Window duration in seconds. Window length in samples is computed fromTRand forced even:windowsize = floor(windowsize_duration/TR/2)*2
-
overlap(samples)
Window overlap. The demo uses near full overlap:overlap = windowsize - 1
-
maxDur(sec) andmaxLag(samples)
Maximum lag/order search range:maxLag = floor(maxDur/TR)
-
Constraint
Regression mode used to estimate the impulse response:'p': positivity-constrained least squares (useslsqlin)'all': unconstrained least squares (useslsqr)
Within each sliding window, SWCC estimates directed influence tc1 → tc2 by:
- Constructing a lag-embedded predictor matrix from the source window (
tc1) up to candidate model orders (Nh = 1..maxLag). - Fitting a finite impulse response (FIR) filter
h(lag weights) to predict the target window (tc2) from the lagged source. - Selecting the model order
Nhper window using information criteria (BIC and AIC/AICc). - Quantifying directed interaction strength in that window as the prediction correlation between the observed target (
tc2) and the model-predicted target (tc2_hat).
Running this window-by-window yields a time series of directed strength for each ROI pair and direction.
How to interpret SWCC outputs:
- Strength: the SWCC value per window (e.g.,
cc_bicorcc_aic) is the instantaneous directed interaction strength at that window. - Duration: duration is not returned as a single primitive value; it is derived from the temporal persistence of directed strength across windows. For example, you can compute duration as:
- the total number of windows where
cc_*exceeds a threshold, and/or - the length of contiguous above-threshold segments (then convert windows → seconds using
TRand the window step).
- the total number of windows where
This implementation computes both AIC and AICc (small-sample corrected AIC).
The returned AIC-based choice (Nh_aic, cc_aic) should be interpreted as:
- AICc-selected in short-window regimes (when the sample size per window is not large relative to the number of fitted parameters),
- otherwise AIC-selected.
AICc is recommended for short windows because it penalizes model complexity more strongly and tends to yield more stable (less overfit) order selection.
Calling:
[cc_bic, corr_bic, Nh_bic, cc_aic, corr_aic, Nh_aic, corr_std, corr0, H, nmaps] = ...
sliding_pcorr_cc_window(tc1, tc2, windowsize, overlap, maxLag, Constraint);Returns (typically) 1 × nWindows vectors (unless otherwise noted):
cc_bic— channel capacity using BIC-selected order (per window)corr_bic— prediction correlation using BIC-selected order (per window)Nh_bic— BIC-selected orderNh(per window)cc_aic— channel capacity using AIC/AICc-selected order (per window)corr_aic— prediction correlation using AIC/AICc-selected order (per window)Nh_aic— AIC/AICc-selected orderNh(per window)corr_std— baseline correlation (seepcorr_cc_x2y.mfor exact definition used)corr0— prediction correlation using orderNh = 1H— estimated impulse responses per window (stacked across windows)nmaps— number of windows
The demo script saves one file per subject:
./output/subj<k>.mat
Key saved arrays are shaped:
(nroi x nroi x nWindows)with index order:[sourceROI, targetROI, window]
Saved variables include:
slcc_BIC,slpcorr_BIC,slNh_BICslcc_AIC,slpcorr_AIC,slNh_AIC(AIC/AICc per the rule above)slpcorr_STDslpcorr1(storescorr0)
Both directions are computed and stored (i→j and j→i).