I am using the Granger causality test to measure the lag between pairs of time series where it is already apparent that one is following the other. So I am not expecting this test to tell me whether causality is likely or not, but rather to help me measure what the lag is.

The question is: is my method for sorting the lag hypothesis optimal? The measurement yields a sensible result for most cases, but there are a few where the result is a counter-intuitive and very long lag.

In the following I will first describe my method and then show two examples, one where my method works and one where it does not.

The method: I am using statsmodels, which comes with a Granger-test module. In my method I run the Granger test for lags between 1 and 12 days. Then I look at the values from the F-test. The lag with the highest F-test value is the optimal lag. Here is the code in Python:

granger_test_result = grangercausalitytests(data[:, 1::-1], maxlag=12, verbose=False)

optimal_lag = -1
F_test = -1.0
for key in granger_test_result.keys():
    _F_test_ = granger_test_result[key][0]['params_ftest'][0]
    if _F_test_ > F_test:
        F_test = _F_test_
        optimal_lag = key
return optimal_lag

Example #1: This figure illustrates the kind of data I am analyzing. It is evident that green series follows the orange one. In this case, my method works pretty fine and the optimal lag is found to be 1 day.

two time series with a lag, as determined via the Granger causality test, of 1 day

Example #2: In this case, my method yields a counter-intuitive and very large lag of 12 days.

enter image description here

This is the output from statsmodels F-test for each of the tested lags. The first item in the tuple corresponds to the F-test value. The highest value is indeed for 12L.

Optimal lag 12. F_test: 74.84. p_value: 0.00
(32.153600306648876, 4.9523452120563632e-07, 57.0, 1L)
(51.600830587070561, 2.9531736086260536e-13, 54.0, 2L)
(46.061291459709828, 1.511140176815108e-14, 51.0, 3L)
(34.512420150659764, 1.4224612929215072e-13, 48.0, 4L)
(22.215895296628979, 3.7705907562143266e-11, 45.0, 5L)
(18.817209069293003, 1.7380007128923565e-10, 42.0, 6L)
(14.366562461309808, 4.6093266266687769e-09, 39.0, 7L)
(11.296513565933811, 7.9114754208643629e-08, 36.0, 8L)
(12.008824010113649, 3.9713072573193326e-08, 33.0, 9L)
(10.237915003417235, 3.1897816507786703e-07, 30.0, 10L)
(9.7564732369412628, 8.1924196528108249e-07, 27.0, 11L)
(74.843204319602407, 5.2948535623699612e-16, 24.0, 12L)
  • 4
    $\begingroup$ Why don't you look at autocorrelation (ACF) and partial autocorrelation (PACF) instead? They are direct measures of lead-lag relationships while Granger causality is indirect at best and irrelevant at worst (depending on the properties of the series). $\endgroup$ – Richard Hardy Feb 1 '18 at 18:29
  • $\begingroup$ Are you sure that this is actually a use-case for for Granger causality? Correct me if I am wrong, but suppose you have a set of time series that it cointegrated, doesn't there exist some theorem that says something about one Granger causing another? $\endgroup$ – Theodore Dec 19 '18 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.