dirconn.select_order#

dirconn.select_order(data: TimeSeries, max_order: int, *, criterion: str = 'bic', ridge: float = 0.0, demean: bool = True, n_folds: int = 5) → OrderSelection#

Choose the VAR order with an information criterion or by cross-validation.

Every candidate order is fitted on one common set of observations (the samples from max_order onwards in each trial; for masked data the rows that row_mask() selects at max_order), so the criteria compare models on the same data. With K channels, n observations, residual covariance S (maximum likelihood) and m K^2 free coefficients:

aic = ln|S| + 2 m K^2 / n
bic = ln|S| + ln(n) m K^2 / n
hqc = ln|S| + 2 ln(ln(n)) m K^2 / n

The cross-validation criterion "cv" is the held-out prediction error, normalised per channel by its variance and averaged over channels, so it is scale free. With at least four trials whole trials are held out; otherwise contiguous time blocks of each trial are held out with a gap that prevents leakage (see cv_splits()). It makes no assumption about the noise and is the more trustworthy choice for short records and many channels, at a higher cost. It has no penalty term, so beyond the true order the curve is nearly flat and the minimum can land a lag or more above the BIC choice: inspect OrderSelection.cv rather than trusting the single number.

Parameters:
  • data (TimeSeries) – The data.

  • max_order (int) – Largest candidate order.

  • criterion ({"aic", "bic", "hqc", "cv"}) – Criterion that picks the order. The default BIC is conservative and consistent.

  • ridge – As in fit_var().

  • demean – As in fit_var().

  • n_folds (int) – Number of folds for criterion="cv" (at least 2); with whole-trial folds it is capped at the number of trials.

Returns:

Carries the three information-criterion curves so the choice can be inspected, and the cross-validation curve when it was requested.

Return type:

OrderSelection