Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Get prediction index in VAR predict. #4785

Merged
merged 2 commits into from Jul 7, 2018

Conversation

ChadFulton
Copy link
Member

@ChadFulton
Copy link
Member Author

Another issue that came up: predict also breaks if the params is not a numpy array, e.g. if it is a Pandas dataframe (which is what the res.params is if the passed endog was a Pandas dataframe). e.g.:

import pandas as pd
import statsmodels.api as sm

dta = sm.datasets.macrodata.load_pandas().data
dta.index = pd.PeriodIndex(start='1959Q1', end='2009Q3', freq='Q')

endog = dta[['realgdp', 'realcons', 'realinv']]

mod = sm.tsa.VAR(endog)
res = mod.fit(maxlags=1)

mod.predict(res.params, start=0, end=500)

yields:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-a2b015a59706> in <module>()
     10 res = mod.fit(maxlags=1)
     11 
---> 12 mod.predict(res.params, start=0, end=500)

~/projects/statsmodels/statsmodels/tsa/vector_ar/var_model.py in predict(self, params, start, end, lags, trend)
    563         # fit out of sample
    564         y = y[-k_ar:]
--> 565         coefs = params[k_trend:].reshape((k_ar, k, k)).swapaxes(1, 2)
    566         predictedvalues[pv_end:] = forecast(y, coefs, intercept, out_of_sample)
    567         return predictedvalues

~/miniconda3/envs/python3/lib/python3.6/site-packages/pandas/core/generic.py in __getattr__(self, name)
   4370             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   4371                 return self[name]
-> 4372             return object.__getattribute__(self, name)
   4373 
   4374     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'reshape'

This issue is fixed in 322e743

@coveralls
Copy link

coveralls commented Jul 6, 2018

Coverage Status

Coverage decreased (-0.03%) to 83.589% when pulling 322e743 on ChadFulton:var-predict into 56fa48e on statsmodels:master.

@codecov-io
Copy link

codecov-io commented Jul 6, 2018

Codecov Report

Merging #4785 into master will increase coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4785      +/-   ##
==========================================
+ Coverage    81.1%   81.11%   +<.01%     
==========================================
  Files         581      581              
  Lines       89787    89785       -2     
  Branches    10027    10027              
==========================================
- Hits        72826    72825       -1     
+ Misses      14682    14681       -1     
  Partials     2279     2279
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/var_model.py 88.54% <0%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56fa48e...322e743. Read the comment docs.

@ChadFulton
Copy link
Member Author

There is no coverage for predict, but at least "it's green" means I didn't break var_model.py with a syntax error. Guess we can merge whenever.

@ChadFulton
Copy link
Member Author

Guess I will merge this. It's pretty straightforward.

@ChadFulton ChadFulton merged commit 68c40b0 into statsmodels:master Jul 7, 2018
@josef-pkt josef-pkt added this to the 0.10 milestone Sep 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants