So in this lecture, we are going to go over a topic that is typically taught in a module on Varma,
which is Granger causality, earlier in this course, we were exposed to various hypothesis tests.
This is another the Granger causality test is a statistical test that checks whether one time series
is useful in forecasting another time series.
Now, one important thing to note about the Granger causality test is it's actually not a test for causality.
When we use the term causality, we typically mean that one thing causes another thing, and this concept
can get pretty philosophical in this case, despite its name.
We are actually not talking about true causality.
Instead, we take a more mechanical perspective.
Granger causal simply means that one time series can be used in forecasting a different time series.
A predictive relationship does not necessarily imply a causal relationship.
Let's now look at some details.
Suppose that we have two stationary time Series X of T and Y of T, suppose that we build in auto regressive
model for Y of T.
Now suppose that we build another auto regressive model to predict Y of T, but instead of only using
past values of Y of T, we also use arbitrary legs from X of T.
As you can see, you can pick a very specific lags like X of T minus three and X of T minus seven and
so forth.
So this method allows you to test only the legs you choose.
Now what this test essentially does is it checks whether or not the coefficients on the legs of X are
statistically significant.
If they are, then we conclude that X of T Granger causes Y of T.
As a reminder, recall that in regression analysis, it's always possible to test whether the coefficients
of your model are statistically significant.
Intuitively, what we mean by significant is that the coefficient is far away from zero.
If it is far away enough from zero, then we have more confidence that it truly has an effect on the
dependent variable or the target.
In this lecture, we're essentially doing this, but with VAR models instead of generic linear regression.
Note that there is also a multivariate version of the Granger causality test, but this is not available
in the Stats Model's package.
This looks at a VAR model, as we've seen in this section.
Essentially, if we find that a subscript TAO at Roget column, I for any title has an absolute value,
which is significantly larger than zero, then we can say that the time Series Y so by Granger causes
the time Series Y Sub J.
This should be pretty intuitive.
Basically, it means that the coefficient from a lag of Y has an influence on the current value of YJ.
So hopefully this helps to connect this topic to the rest of this section.
But again, a note that the multivariate version is not included in the stats modest package.
Now, let's get to the practical question, which is how do you do this in Python?
Suppose that we have a buy very at time series, which occupy two columns of a data frame.
We can then pass this through the method Granger causality tests, and this will produce a p value for
every leg you want to test for using various different tests.
Now, in order to understand what these specific tests are and how they work, you would need to take
a graduate course on mathematical statistics.
So that's definitely outside the scope of this course.
These tests will typically produce similar results anyway, so the main thing in your work is to remain
consistent.
As always, you will choose a significance threshold beforehand, and any p value smaller than this
threshold will be deemed significant.