dirconn.GC#

class dirconn.GC(order: int | str = 'bic', max_order: int = 10, conditional: bool = True, method: str = 'refit', ridge: float = 0.0, demean: bool = True, n_folds: int = 5, check_order_stability: bool = True, check_whiteness: bool = True)#

Granger causality log(var_reduced / var_full) from a pooled least-squares VAR model.

values[i, j] measures how much the past of channel i improves the prediction of channel j: the log ratio of the residual sums of squares of the model without i and the model with it, in nats. Both models are fitted on the same observations (all trials, regressors never crossing a trial boundary) and at the same order, which is chosen once, on the full multivariate model. This is predictive influence, not interventional causality.

With conditional=True the reduced model keeps every other channel, so an influence that runs through a third channel is not mistaken for a direct one. With conditional=False each ordered pair is judged on its own, from a bivariate model and the target’s own past; this needs fewer coefficients but cannot tell direct from indirect influence. For two channels the modes coincide.

method decides where the reduced model comes from. "refit" (the default) fits it again by least squares at the same order. The reduced process of a VAR model is in general a VARMA process, so a reduced VAR of the same order is misspecified and the value is biased upwards at short orders; the bias shrinks quickly as the order grows. "state_space" (Barnett and Seth 2015) fits only the model of all channels, writes it in innovations form and obtains every reduced model exactly from it by solving one discrete algebraic Riccati equation per conditioning set (see dirconn.methods.statespace); the values are then non-negative and consistent at the true order. In the pairwise mode the “full” model of a pair is its bivariate subprocess of that same fit. SSGC gives the matching frequency-resolved values.

Data with valid or predict masks use only the rows those select (see dirconn.methods.mvar.row_mask()), for the order selection and for every model.

Parameters:
  • order (int or {"aic", "bic", "hqc", "cv"}) – A fixed model order, or the criterion that selects it with dirconn.select_order(). The selection curves are stored in the provenance.

  • max_order (int) – Largest candidate order when order is a criterion.

  • conditional (bool) – Condition on all other channels (default) or judge channel pairs separately.

  • method ({"refit", "state_space"}) – Refit every reduced model by least squares (default), or derive it from the fit of all channels through its state-space form. "state_space" needs a stable fit and raises ValueError when the stationarity check fails; the check is recorded in the provenance. dirconn.analytic_gc_test() (the F test of nested least-squares models) accepts only "refit".

  • ridge (float) – Relative ridge penalty (see dirconn.fit_var()). With method="refit" the models are no longer nested and small negative values can occur. With "state_space" the penalised fit of all channels and its residual covariance define the model, and the reduced models follow from it, so the values stay non-negative.

  • demean (bool) – Remove the per-channel mean over trials and time before fitting.

  • n_folds (int) – Number of folds when order="cv".

  • check_order_stability (bool) – Refit at longer orders and warn when the direction of a pair reverses (see dirconn.diagnostics.order_stability.order_stability_check(); the check always compares with least-squares refits). It costs a few extra fits; the resampling tests switch it off for the resampled fits.

  • check_whiteness (bool) – Test the residuals of the model of all channels for autocorrelation and warn when they are clearly not white (see dirconn.methods.base.residual_whiteness_check()). The resampling tests switch it off for the resampled fits.

__init__(order: int | str = 'bic', max_order: int = 10, conditional: bool = True, method: str = 'refit', ridge: float = 0.0, demean: bool = True, n_folds: int = 5, check_order_stability: bool = True, check_whiteness: bool = True) → None#

Methods

__init__([order, max_order, conditional, ...])

fit(data)

Estimate directed connectivity.

get_params()

Return the constructor parameters as a dictionary.

Attributes

check_order_stability

check_whiteness

conditional

demean

info

max_order

method

n_folds

order

ridge