I am trying to recover confidence/prediction intervals in Python Statsmodels (Version 0.12.1) with two or more endogenous (y) variables, as is common in VARMAX. The following example correctly predicts the in-sample and out-sample means for two endogenous varialbes. But the in-sample and out-sample confidence intervals are returned only for the first endogenous variable, dln_inv. I would like to know how to recover the confidence interval for the second variable, dln_inc, as well. I would appreciate any help.
import numpy as np
import statsmodels.api as sm
from statsmodels.tsa.api import VARMAX
import warnings
warnings.filterwarnings("ignore")
dta = sm.datasets.webuse('lutkepohl2', 'https://www.stata-press.com/data/r12/')
dta.index = dta.qtr
dta.index.freq = dta.index.inferred_freq
subset = dta.loc['1960-04-01':'1978-10-01', ['dln_inv', 'dln_inc', 'dln_consump']]
endog = subset[['dln_inv', 'dln_inc']] # notice two endogenous variables
exog = subset['dln_consump']
p = int(0)
q = int(1)
model = VARMAX(endog, exog=exog, order=(int(p),int(q))).fit(maxiter=100,disp=False)
in_sample_predicted = model.get_prediction()
in_sample_predicted_means = in_sample_predicted.predicted_mean
# the following command seems to produce the confidence interval for the first endogenous variable, dln_inv
in_sample_CI = in_sample_predicted.summary_frame(alpha=0.05)
n_periods = 5
exog_preforecast = exog + exog * np.random.normal(0,0.5,exog.shape)
out_sample_forecast = model.get_forecast(steps=n_periods,exog=exog_preforecast[-n_periods:])
out_sample_forecast_means = out_sample_forecast.predicted_mean
# the following command seems to produce the confidence interval for the first endogenous variable, dln_inv
out_sample_CI = out_sample_forecast.summary_frame(alpha=0.05)
There are two ways to get confidence intervals for all variables.
First, if you are using the
summary_frame
method, you can pass the integer index of variable you want to retrieve intervals for, using theendog
argument (which seems not to be in the docstring, unfortunately).Second, you can retrieve invervals for all variables at once, using the
conf_int
method:Which yields the following DataFrame output: