Multi Variate Breusch Godfrey LM Autocorrelation test for VAR in statsmodels python?

Viewed 185

Is there a way to do multi variate Bruesch Godfrey Lagrange Multiplier residual serial correlation tests for vector autoregressions (VAR) using statsmodels? I would like to get the same output as Eviews in View > Residual Tests> Autocorrleation LM Test

Eviews Output I'm Tying to Replicate

I have tried using the acorr_breusch_godfrey from stats models but it doesn't seem to be giving me outputs. Am I misparameterizing this? Or do I need to loop through the variables some how?

Below is an example using OLS (works) and the second one is VAR (doesn't work).

import pandas as pd
import numpy as np
import statsmodels.api as sm
from statsmodels.tsa.api import VAR
from statsmodels.stats.diagnostic import acorr_breusch_godfrey

data = pd.read_csv('http://web.pdx.edu/~crkl/ceR/data/cjx.txt', sep='\s+', index_col='YEAR', nrows=39)

X = np.log(data.X)
L = np.log(data.L1)
K = np.log(data.K1)
df = pd.DataFrame({'X': X, 'L': L, 'K': K})

# OLS Regression
model_ols = sm.OLS.from_formula('X~L+K', df).fit()
# print(model_ols.summary())
print(sm.stats.diagnostic.acorr_breusch_godfrey(model_ols))

# Vector Auto Regression
model_var = VAR(endog=df[['L','K']],exog=df['X']).fit(maxlags=2)
# print(results_var.summary())
sm.stats.diagnostic.acorr_breusch_godfrey(model_var,nlags=15)

For the last one I've also tried the below to no avail:

sm.stats.diagnostic.acorr_breusch_godfrey(model_var.resid.loc[:,0],nlags=15)
0 Answers
Related