You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
VAR.forecast_cov and plot only work for trend='c' #142
running example ex_var.py with trend = 'nc' or 'ct' raises an exception in plot_forecast and forecast_cov
>>> res_nc.forecast_cov(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\vector_ar\var_model.py", line 1056, in forecast_cov
omegas = self._omega_forc_cov(steps)
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\vector_ar\var_model.py", line 1203, in _omega_forc_cov
B = self._bmat_forc_cov()
File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\vector_ar\var_model.py", line 1241, in _bmat_forc_cov
return np.vstack((upper, self.params.T, lower))
File "C:\Python26\lib\site-packages\numpy\core\shape_base.py", line 214, in vstack
return _nx.concatenate(map(atleast_2d,tup),0)
ValueError: array dimensions must agree except for d_0
It looks like also test_causality() is working only for trend="c".
Here is a Jupyter-notebook showing the problem.
Take a look at the two lines responsible for this problem with a correction suggestion (line one, line two). I have tried out these correction suggestion for trend="nc" (in this case num_of_det_terms is 0) and it worked.
@yogabonito If you need to fix something to reuse VAR, then you could fix it in your branch and we worry about merge conflicts later.
But keep adding comments to issues or open new issues so we can track what's wrong in the VAR.
Fixed by PR #4538 (the same PR behind several other VAR fixes found in this triage): _bmat_forc_cov now derives shapes from k_exog instead of hardcoding k_trend, working correctly for any trend/exog combination. One narrow, non-crashing residual limitation remains: the parameter-uncertainty-adjusted forecast_cov(method="auto") is still explicitly gated to k_exog == 1 (effectively trend="c" only) - happy to file that as a narrow follow-up enhancement if you want it extended, but closing this one as fixed for the reported crash.
Activity
josef-pkt commentedon Jan 27, 2012
besides the test for var forecast is only a sanity check
scikits\statsmodels\tsa\vector_ar\tests\test_var.py", line 391, in test_forecast
jseabold commentedon Jun 3, 2014
I fixed the forecasting re: the trend. However, I don't think that the forecast standard errors are currently computed correctly.
josef-pkt commentedon Mar 19, 2015
predict predictedvalues with ct or ctt add linear and quadratic trend as constant
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/vector_ar/var_model.py#L360
based on reading the code while looking at some parts for #2329
yogabonito commentedon Aug 5, 2016
It looks like also test_causality() is working only for trend="c".
Here is a Jupyter-notebook showing the problem.
Take a look at the two lines responsible for this problem with a correction suggestion (line one, line two). I have tried out these correction suggestion for trend="nc" (in this case num_of_det_terms is 0) and it worked.
josef-pkt commentedon Aug 7, 2016
@yogabonito If you need to fix something to reuse VAR, then you could fix it in your branch and we worry about merge conflicts later.
But keep adding comments to issues or open new issues so we can track what's wrong in the VAR.
bashtage commentedon Jul 31, 2026
Fixed by PR #4538 (the same PR behind several other VAR fixes found in this triage): _bmat_forc_cov now derives shapes from k_exog instead of hardcoding k_trend, working correctly for any trend/exog combination. One narrow, non-crashing residual limitation remains: the parameter-uncertainty-adjusted forecast_cov(method="auto") is still explicitly gated to k_exog == 1 (effectively trend="c" only) - happy to file that as a narrow follow-up enhancement if you want it extended, but closing this one as fixed for the reported crash.