dirconn.contrast_test#

dirconn.contrast_test(estimator: Estimator, data_a: TimeSeries, data_b: TimeSeries, *, n_permutations: int, seed: int, reduce: Callable[[Connectivity], Connectivity] | str | Sequence[float] | None = None, alpha: float = 0.05, paired: bool = False) → ContrastResult#

Test whether connectivity differs between two conditions or two segments of the same trials.

Permutation i uses RNGController(seed).child(i) to shuffle the pooled trials and assigns the first n_a to condition A, so the group sizes are kept and results do not depend on how the work is split. The estimator’s whole procedure, including a model order chosen by a criterion, is repeated on every relabelling.

With paired=True the data sets are two segments of the same trials, trial k of data_a and trial k of data_b being cut from the same trial. Permutation i then draws one fair coin per trial from RNGController(seed).child(i).integers(0, 2, n_trials) and swaps the two segments of that trial when it is 1, so every trial keeps both of its segments and the groups keep their size. A relabelling and its complement give the same |statistic|, so a p-value cannot be finer than 1 / 2**(n_trials - 1). An unpaired test on such data would ignore what the two segments of a trial share and compare a null that is too wide.

Parameters:
  • estimator (Estimator) – Any dirconn estimator.

  • data_a (TimeSeries) – Epoched data with the same channels, sampling frequency and number of samples, and at least two trials each. The trial counts may differ; with paired=True they must be equal and the segments of equal length.

  • data_b (TimeSeries) – Epoched data with the same channels, sampling frequency and number of samples, and at least two trials each. The trial counts may differ; with paired=True they must be equal and the segments of equal length.

  • n_permutations (int) – Number of random relabellings; the smallest p-value is 1 / (n_permutations + 1). A warning says so when fewer distinct relabellings exist than permutations drawn.

  • seed (int) – Required.

  • reduce (callable, str or (float, float), optional) – Applied to every fit before comparing (see surrogate_test()).

  • alpha (float) – Level used for the power check, as in surrogate_test().

  • paired (bool) – True when data_a and data_b are two segments of the same trials (see above).

Return type:

ContrastResult

Raises:

ValueError – For incompatible conditions, invalid arguments, or a relabelled fit that leaves a cell undefined that is defined in both conditions.