Surrogate data and what a surrogate test can tell you#
A surrogate test compares the connectivity of the data with the connectivity of copies of the
data in which the coupling between channels has been destroyed but some other property has been
kept. The null hypothesis is therefore not “there is no connectivity”. It is “the connectivity
is no larger than what the kept property alone produces”. Rejecting it says the data differ from
the surrogates in a way the kept property does not explain; it does not say the cause is a
directed influence between the regions. Every test result carries the null as text (null), so a
number never travels without its premise.
What each surrogate keeps and destroys#
Surrogate |
Keeps exactly |
Keeps approximately |
Destroys |
|---|---|---|---|
|
amplitude spectrum, autocorrelation, mean of each channel and trial |
nothing else |
phase relations between and within channels |
|
amplitude distribution of each channel and trial |
power spectrum (relative error about 0.2 in the test data) |
phase relations between and within channels |
|
amplitude distribution of each channel and trial |
power spectrum (relative error about 0.03 in the test data) |
phase relations between and within channels |
|
every series up to a rotation: spectrum, distribution, autocorrelation |
nothing else |
alignment between channels (and the trial-locked timing) |
|
every trial of every channel |
nothing else |
trial-by-trial pairing between channels |
|
every block of every channel (blocks of |
nothing else |
alignment of the blocks between channels |
Data with valid or predict masks (see Gaps, selected samples and event locks)
can be tested with trial_shuffle, which carries the masks with the trials, and with
block_shuffle, which cuts blocks inside each run of valid samples (the numbers of blocks
total and kept are recorded in the history of the prepared data) and carries predict with the
remaining blocks. The other generators move samples within a trial and refuse masked data.
Null hypotheses and their limitations#
The table is generated from the code (dirconn.stats.surrogates.limitations_table()); a test keeps it
identical to the classes’ null and limitations.
Surrogate |
Null hypothesis |
How the null can be rejected without coupling |
|---|---|---|
|
connectivity is explained by individual-channel power spectra |
1. Assumes each channel is a stationary linear Gaussian process; amplitude fluctuations over time and non-Gaussian amplitude distributions are not kept. |
|
connectivity is explained by spectra and marginal amplitude distributions |
1. The spectrum is matched only approximately and the error is systematically biased towards a flatter spectrum; IAAFT matches it better. |
|
connectivity is explained by spectra and marginal amplitude distributions |
1. Matches the spectrum only up to the iteration’s residual error, and the residual is not zero even at convergence. |
|
between-channel coupling is explained by within-channel autocorrelation |
1. The seam where the end of a trial is joined to its start is a discontinuity that affects model-based estimators such as MVAR fits; long trials make it negligible. |
|
there is no stable trial-to-trial coupling |
1. Coupling that comes from a shared evoked response is kept in every surrogate, so the test cannot detect it; it asks only about trial-specific (induced) coupling. |
|
between-channel coupling is explained by within-block structure (blocks are exchangeable within a channel) |
1. The observed result is computed on the blocks too (as separate trials), so a model loses the regression rows across block boundaries; with blocks short relative to the model order this costs data and changes the estimate. |
Running a test#
from dirconn import GC, surrogate_test
from dirconn.stats.surrogates import IAAFT
result = surrogate_test(GC(order=2), data, IAAFT(), n_surrogates=199, seed=0, reduce=None)
result.pvalues # (source, target, freq, time); NaN for undefined cells such as the diagonal
result.null # the premise of the p-values
result.limitations # how that null can be rejected without coupling
The estimator’s whole procedure, including a model order chosen by a criterion, is repeated on every
surrogate. Diagnostics raised inside the surrogate fits are not repeated 199 times: one summary warning
says how many surrogates raised one, and result.checks records it. A surrogate fit that leaves a cell
undefined that is defined on the data raises an error instead of producing a p-value.
n_surrogates is checked against the number of defined cells of the tested (reduced) result: a
Bonferroni-type correction over m cells needs n_surrogates >= m / alpha - 1.
Choosing one#
For continuous data (one trial)
phase_randomize,aaft,iaaft,circular_shiftandblock_shuffleapply;trial_shuffleneeds at least two trials and raises otherwise.block_shuffleis the surrogate to use when a model-based estimator (GC, DTF, PDC) runs on a continuous record and circular shifting would put a seam in the middle of the regressors. The blocks become separate trials, so no regression crosses a block boundary, and the observed result is computed on the same blocks (the generator’sprepare()step, called bysurrogate_test); the estimate therefore differs a little from a fit on the unbroken record. It is whattest="block_perm"ofdirconn.significance_testuses.If the amplitude distribution is clearly non-Gaussian (bursty, skewed, clipped), prefer
iaaftoverphase_randomize. A Gaussian surrogate of such data differs from it in more than coupling.If an evoked response dominates the epochs,
phase_randomize,aaft,iaaftandcircular_shiftall remove it from the surrogates. Their null then includes “no evoked response”, and the test can reject for that reason alone.trial_shufflekeeps the evoked response in every channel and is the better choice for asking whether coupling goes beyond it.The p-value of any of these tests is bounded below by
1 / (n_surrogates + 1); withtrial_shuffleand few trials the number of distinct surrogates may be smaller thann_surrogates.
Reproducibility#
Each surrogate uses its own generator, derived from one seed by dirconn.data.rng.RNGController:
generator i depends only on the seed and i, not on the number of workers, and raising the number
of surrogates leaves the earlier ones unchanged. The seed is required.
Known differences from the earlier neurrow implementation#
aaft: the earlier code arranged the data values in the order of a Gaussian draw, which destroys the autocorrelation before the phases are randomized. Here the sorted Gaussian values are arranged in the rank order of the data (the standard construction). Measured on skewed AR(1) test data, the relative amplitude-spectrum error is 0.21 to 0.25 here against 0.36 to 0.43 before.phase_randomize: the mean (and the Nyquist term for even lengths) is kept as it is; taking its magnitude would flip the sign of a negative mean.circular_shift: shifts lie in[min_shift, n_times - min_shift], so a shift is at leastmin_shiftsamples away from zero in both directions (the earlier range allowedn_times - 1, which is a shift of one sample backwards).iaaft: stops when the rank order no longer changes and warns whenn_iteris reached first.