# Estimating lag order in Granger causality test

I have a weekly revenue from selling products, named Chicken and Egg. I am trying to understand whether purchasing Chicken Granger-causes customers to buy Egg or vice versa.

I don't have a Ph.D. in Stats and have been really struggling for the past two days. So far, I have learned everything from Google search and StackOverflow. So, I thought of asking experts about some questions. Here's the sequence I followed to check Granger causality:

Step1: Check stationarity

I understand from Interpretation of VAR and causality that we need to run adf and kpss to check stationarity. Fortunately, I got small p-values

library(tseries)
adf.test(df$$S_Chicken) adf.test(df$$W_Egg)
kpss.test(df$$S_Chicken) kpss.test(df$$W_Egg)


Step 2: Estimate Lag I wanted to estimate lag. Learning from Determining suitable time lag in Granger causality test, I used vars package. Now, I am unsure what type means in vars::VARselect. I read VAR models in R: Constant, Trend, Constant+Trend, None and wasn't sure about the difference among const, trendetc. So, I decided to loop through all type and possible lags to see what I get.

#get optimal lag order
for (lag in seq(5,50,5)){
cat("Lag:",lag,"\n")
for (type in c("trend","both","none","const")){
cat("     Type:",type,"\n")
cat("          S:",vars::VARselect(df$$S_Chicken, lag.max = lag, type=type)$$selection,"\n")
cat("          W:",vars::VARselect(df$$W_Egg, lag.max = lag, type=type)$$selection,"\n")
}
}


I have skipped output for sake of brevity. Running above code, we see that p (lag) varies in the set {1, 15, 35, 40} as per AIC, HQ, SC, ,FPE. I chose 5 and 50 as lower and upper limit based on business rules. i.e. if the product is purchased after 1 year (50 weeks), there is no Granger causal link.

Step 3: Run Granger test This is easy and straightforward. I am skipping this for sake of brevity.

Questions:

1. Can someone please guide me how to choose the lag? I understand the tradeoff as explained in Lag order for Granger causality test. What's the right way? I am asking this because changing p (lag) changes the result of Granger causality in Step 3. From Lag order selection for Toda-Yamamoto procedure (Granger causality), I understand that we should set lag.max sufficiently large. However, even when I do so, I get different values for different lag.max. As a result of different p from this test, the result of Granger causality test goes from statistically significant to insignificant.

2. Also, I have noticed that the value of p from Step 2 is different for Chicken and Egg. What should I do? Should I pick the maximum of the two values for Granger test?

3 Should I use const for type in vars::VARselect?

I'd appreciate any help extended during holiday season. My eternal gratitude to anyone willing to help this lost soul. This would be a good learning experience for me.

Here's my dataset:

dput(df)
structure(list(S_Chicken = c(0, 0, 0, 62774.57, 0, 0, 0, 110814.97007,
17435.364491, 3059.7, 295407.97001, 2642929.95251, 5877769.69099,
557964.289992, 302864.420001, 638515.511452, 199185.624302, 117253.769997,
140904.97657922, 867632.303131, 550196.801714, 959181.134732,
510807.875929, 460767.862837, 4341894.086142, 8136290.144111,
1368646.254693, 1023767.707093, 2682319.42977946, 5787105.90149718,
3237583.17954027, 2532539.333804, 3353335.006579, 8974108.26392648,
1641722.196719, 1630555.310797, 3330291.19102984, 5519552.49586992,
13552627.6585533, 1132458.511822, 1811601.00114292, 3352704.903924,
3879903.600603, 3022178.601945, 3503818.454007, 6098289.315593,
9186984.89554527, 4391072.428069, 3953562.096331, 3997384.107074,
6616468.884588, 29483968.6289028, 2265077.638747, 3753344.189456,
6211484.356152, 10899385.460533, 2752992.806802, 4879019.374517,
4628888.906388, 16838745.8250754, 5711482.034574, 3448962.807317,
7725682.404854, 18588887.276053, 55578639.337975, 4941760.321738,
3271579.288657, 5274534.441409, 3449127.992222, 3312029.77883,
3549183.24901, 4674703.52090884, 8799946.181313, 7702361.475478,
8852825.269613, 5642995.371033, 8969715.08304046, 18503348.282649,
5271072.893318, 5790800.1494897, 7240550.532071, 8322037.375561,
5234582.9219294, 7624888.19473199, 8239187.96494, 2187456.006063
), W_Egg = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 355089.47, 0, 15209.479993, 924.042453, 49012.43, 12426.07,
698.6, 330678.929743, 0, 36443.5, 25148.060002, 84604.679768,
408570.659992, 233561.797428, 225012.750019, 203913.99, 77868.23467,
214101.54993, 59247.335503, 1967160.321959, 458070.821242, 39208.328719,
39051.110083, 110831.968483, 630011.709975, 418487.590002, 300531.844468,
501681.160038, 438439.30002, 222852.409849, 126517.78, 313480.609164,
707647.297735, 5999546.142553, 50759.699997, 1525343.714895,
170811.704224, 1171865.505172, 701457.800012, 2311036.244954,
1261387.095132, 1112181.959579, 1783361.785215, 1215356.36973,
5182123.661543, 5779253.835316, 10078878.565432, 5579012.806055,
295489.775016, 1042592.990025, 770521.091289, 943591.552513,
400204.245813, 1623902.205893, 2469527.538234, 2552224.652401,
1151769.304545, 567841.577643, 1110740.89722, 9404018.52624101,
1249473.650353, 896099.041807, 1159826.185882, 2217336.297412,
1320907.977865, 1906507.779424, 4414587.639634, 1469215.877748
)), row.names = c(NA, -86L), class = "data.frame")

• Regarding spelling, Sir Clive W.J. Granger was an outstanding econometrician and a Nobel prize winner; let us at least start his name with a capital letter. Regarding resources, Dave Giles has some great resources on testing Granger causality. A classic is this blog post but there are a few more related ones, just search the relevant keywords and you will find them. – Richard Hardy Dec 23 '18 at 20:09
• And in this blog post Dave Giles includes a link for code for testing for Granger causality in R using the Toda-Yamamoto procedure. – Richard Hardy Dec 23 '18 at 20:25
• @Richard Hardy: Thanks for correcting me about the name. I think I did follow your guidelines for running Granger causal test in other SO threads. They are very helpful. Prof. Giles' blog was a little unclear to me because I lack formal training in Statistics. Hope you understand my situation. Do you think you could help me with my questions? – watchtower Dec 23 '18 at 20:35
• If I had some more time, I would write up an answer, but unfortunately I do not at the moment. Sorry. – Richard Hardy Dec 23 '18 at 20:53
• @Richard Hardy: Thank you for considering my request. I will wait. It will be great if you could answer whenever you get a chance. – watchtower Dec 23 '18 at 21:06