Repository navigation
Closed
Description
I was following this tutorial http://statsmodels.sourceforge.net/devel/vector_ar.html#class-reference This is the code
import statsmodels.api as sm
import pandas as pd
import numpy as np
mdata = sm.datasets.macrodata.load_pandas().data
dates = mdata[['year', 'quarter']].astype(int).astype(str)
quarterly = dates["year"] + "Q" + dates["quarter"]
from statsmodels.tsa.base.datetools import dates_from_str
quarterly = dates_from_str(quarterly)
mdata = mdata[['realgdp','realcons','realinv']]
mdata.index = pd.DatetimeIndex(quarterly)
mdata = np.log(mdata).diff().dropna()If I now run
model = sm.tsa.VAR(mdata)
results = model.fit(4, trend = 'nc')
irf = results.irf(10)
irf.plot()I get an error. However the following code runs fine
model = sm.tsa.VAR(mdata)
results = model.fit(4)
irf = results.irf(10)
irf.plot()Is this a bug? Am I doing something wrong? I am using Python 2.7.6 and statsmodels 0.5.0, and this is the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/vector_ar/irf.py", line 138, in plot
stderr = self.cov(orth=orth)
File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/vector_ar/irf.py", line 264, in cov
covs[i] = chain_dot(Gi, self.cov_a, Gi.T)
File "/usr/lib/python2.7/dist-packages/statsmodels/tools/tools.py", line 460, in chain_dot
return reduce(lambda x, y: np.dot(y, x), arrs[::-1])
File "/usr/lib/python2.7/dist-packages/statsmodels/tools/tools.py", line 460, in <lambda>
return reduce(lambda x, y: np.dot(y, x), arrs[::-1])
ValueError: matrices are not aligned
Activity
josef-pkt commentedon Apr 27, 2014
I have problems already with pandas in the example
josef-pkt commentedon Apr 27, 2014
looks like a bug to me
cov_a might be cutting off a constant, even though there was None
debugging with introspection, doesn't help much because I have no idea what this things mean
josef-pkt commentedon Apr 27, 2014
(still without looking at the code)
somewhere cov_a is created from cov_params, and truncates independent of
trendwithout
nccode search
self.cov_a = model._cov_alphanow what's cov_alpha
def _cov_alpha(self): self.cov_params[self.neqs:, self.neqs:]this cuts off the constant (one for each equation)
neqs = 3 in both cases
fix: don't cut off if
trend='nc'and I guess it's also incorrect for any other trend than 'c'
PR welcome
josef-pkt commentedon Apr 27, 2014
and my guess is that
cov_alphaorcov_ais actuallycov_endogthe covariance of the parameters of the lagged endogenous variables.(endogs that are on the right hand side and part of exog in OLS :) (my initial proposal for exog was
predetermined)sorry for the "language" detour.
josef-pkt commentedon May 22, 2014
bump this should be prio-high
eph commentedon May 26, 2014
Very new to statsmodels, and I don't have Lutkepohl handy, but shouldn't it just be:
josef-pkt commentedon May 26, 2014
@egh Yes, it looks like that's all there is.
cov_alpha is only used by
irfso it won't affect any other code.Can you open a PR, and also check the case when there is a linear trend?
It would be good to add unittests that check that
irfworks for k_trend = 0, 1 or 2.jseabold commentedon Sep 20, 2014
I'm fairly certain this is fixed in #815.
mcaceresb commentedon Sep 24, 2014
How do I pull this? (I'm sorry I'm not too adept with git). But this error persists in the master branch.
gives
'0.6.0.dev-2fcc5ae'If I then run my example I get a similar error.jseabold commentedon Sep 26, 2014
I'll see how much work it would be to pull out the fixes from that PR.
jseabold commentedon Sep 26, 2014
This isn't yet fixed in that PR.
jseabold commentedon Sep 26, 2014
To be honest, I'm not going to be able to fix this for 0.6. It would take me more time than I have to get back into this.
This code really needs a champion, so if you're interested in working through this, I'd continue the work started in my branch and see the TODOs on #815.
BUG: var irf correct cov_alpha(cov_ar_params) for trend and no constant