How to compare 2 time series data points using Grangers test?
Granger relation check is employed to see if just once series is going to be helpful to forecast another variable by investigation relation between 2 variables in a very statistic. The strategy could be a probabilistic account of causality; it uses discovered knowledge sets to search out patterns of correlation. One smart issue regarding statistic vector auto regression (VAR) is that we have a tendency to check ‘causality’ in some sense.
How Granger Causality works:
It is supported the concept that if X causes Y, then the forecast of Y supported previous values of Y and also the previous values of X ought to the best lead to the forecast of Y supported previous values of Y alone. Granger relation shouldn't be accustomed check if a lag of Y causes Y. Instead, it's typically used on exogenous (not Y lag) variables solely. In easy terms ‘X is alleged to Granger-cause Y if Y is higher expected victimization the histories of each X and Y than it will by using the history of Y alone.
Assumtions we made while performing Granger Causality Test:- 1. Future values cannot cause the past values. 2. A notably distinct data is contained in cause regarding impact which is able to not be accessible elsewhere
We will import all the Libraries including grangercausalitytests.
from statsmodels.tsa.stattools import grangercausalitytests import pandas as pd import numpy as np
df = pd.read_csv("/content/sample_data/california_housing_train.csv") df.head()
This test is a X/Y based test. We have to feed two columns thorugh this test.
res = grangercausalitytests(df[['median_income', 'median_house_value']], maxlag=4)