Granger Causality

Granger Causality#

Granger Causality (GC) is a statistical concept of causality based on prediction. If a time series X “Granger-causes” a time series Y, then past values of X should contain information that helps predict Y beyond the information contained in past values of Y alone [Zan21]. Before using Granger Causality, it’s important to detrend the time series data to avoid spurious results, i.e. using the Z-Score.

import delaynet as dn

# Calculate single-lag Granger Causality
result = dn.connectivity(ts1, ts2, metric="granger causality", lag_steps=5)

Parameters:

  • lag_steps: Time lags to consider. An integer will consider lags [1, …, lag_steps]. Passing a list will consider the specified values as lags.

granger.gt_multi_lag(ts2, lag_steps: int | list = None)

Granger Causality connectivity metric with variable time lag.

Testing for various time lags and selecting the one with the lowest p-value.

Parameters:
  • ts1 (numpy.ndarray) – First time series.

  • ts2 (numpy.ndarray) – Second time series.

  • lag_steps (int | list) – Time lags to consider. Can be a single integer or a list of integers. An integer will consider lags [1, …, lag_steps]. A list will consider the specified values as lags.

Returns:

Best p-value and corresponding lag.

Return type:

tuple[float, int]