Skip to content

VAR.forecast_cov and plot only work for trend='c' #142

Closed

Description

@josef-pkt

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

Activity

  1. josef-pkt commented on Jan 27, 2012

    @josef-pkt
    MemberAuthor

    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

  2. jseabold commented on Jun 3, 2014

    @jseabold
    Member

    I fixed the forecasting re: the trend. However, I don't think that the forecast standard errors are currently computed correctly.

  3. josef-pkt commented on Mar 19, 2015

    @josef-pkt
    MemberAuthor

    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

  4. added this to the 0.8 milestone on Mar 19, 2015
  5. yogabonito commented on Aug 5, 2016

    @yogabonito
    Contributor

    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.

  6. josef-pkt commented on Aug 7, 2016

    @josef-pkt
    MemberAuthor

    @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.

  7. removed this from the 0.8 milestone on Apr 6, 2021
  8. bashtage commented on Jul 31, 2026

    @bashtage
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions