Repository navigation
Description
Hi,
I get error message when I try to find error band of my SVAR model. "shape mismatch: value array of shape (0,) could not be broadcast to indexing result of shape (0,4,4)" Can you guys help me out?
ValueError Traceback (most recent call last)
in ()
----> 1 result.sirf_errband_mc(orth=False, repl=1000, T=10,signif=0.05, seed=None, burn=100, cum=False)
~\Anaconda3\lib\site-packages\statsmodels\tsa\vector_ar\svar_model.py in sirf_errband_mc(self, orth, repl, T, signif, seed, burn, cum)
721 if i < 10:
722 sol = SVAR(sim, svar_type=s_type, A=A_pass,
--> 723 B=B_pass).fit(maxlags=k_ar)
724 g_list.append(np.append(sol.A[A_mask].tolist(),
725 sol.B[B_mask].tolist()))
~\Anaconda3\lib\site-packages\statsmodels\tsa\vector_ar\svar_model.py in fit(self, A_guess, B_guess, maxlags, method, ic, trend, verbose, s_method, solver, override, maxiter, maxfun)
183 return self._estimate_svar(start_params, lags, trend=trend,
184 solver=solver, override=override,
--> 185 maxiter=maxiter, maxfun=maxfun)
186
187
~\Anaconda3\lib\site-packages\statsmodels\tsa\vector_ar\svar_model.py in _estimate_svar(self, start_params, lags, maxiter, maxfun, trend, solver, override)
253 solver=solver,
254 maxiter=maxiter,
--> 255 maxfun=maxfun)
256 A_mask = self.A_mask
257 B_mask = self.B_mask
~\Anaconda3\lib\site-packages\statsmodels\tsa\vector_ar\svar_model.py in _solve_AB(self, start_params, maxiter, maxfun, override, solver)
357 A_len = len(A[A_mask])
358
--> 359 A[A_mask] = start_params[:A_len]
360 B[B_mask] = start_params[A_len:]
361
ValueError: shape mismatch: value array of shape (0,) could not be broadcast to indexing result of shape (0,4,4)
Activity
[-]sirf_errband_mc / error message[/-][+]sirf_errband_mc / error message #svar[/+]mk1564 commentedon Sep 30, 2018
Here is my model.
so A_mask is going to be
josef-pkt commentedon Oct 1, 2018
@mk1564
I tried a simple example with your setting with random numbers, but for me it fails already earlier.
I'm using python 3.4 and have problems with bytes versus strings. my numpy is 1.11.2
What are your python, numpy and statsmodels version?
Given that there are no unit tests for sirf_errband_mc, it is likely that there are still some basic python 3 incompatibilities.
josef-pkt commentedon Oct 1, 2018
A changes dtype
the A array created by the user code is U(nicode)
SVARResult.sirf_errband_mc recreates it as S1 bytes array
josef-pkt commentedon Oct 1, 2018
If I recreate the model in
SVARResult.sirf_errband_mcwith dtype '<U11', then thesirf_eb = result.sirf_errband_mc(orth=False, repl=100, T=10, signif=0.05, seed=None, burn=100, cum=False)finishes without exception
sirf_eb is a 2-tuple with
josef-pkt commentedon Oct 1, 2018
irf plot seems to work also
But I have no idea whether the numbers are correct.
So quickfix seems to be to recreate A and B with the same dtype S or U in sirf_errband_mc.
The better fix would be to store the original user provided A and B and use it directly instead of recreating it.
(Based on quick bughunting in those lines that cause problems without trying to understand larger parts of SVAR. I haven't looked at it in quite some time, and never at IRF for SVAR.)
josef-pkt commentedon Oct 1, 2018
AFAICS, there is no caching of the MonteCarlo results. repeated calls to irf.plot perform a new simulation each time.
Because there are options for irf and irf.plot, we cannot simply store the results, i.e. they would only be valid for the last set of options, until we memoize for given arguments.
mk1564 commentedon Oct 1, 2018
Thank you for your comment! So do you mean I need to create A like
A1 = np.array([[1, 0, 0,0],['E', 1, 0,0],['E', 'E', 1,0],['E', 'E', 'E',1]],dtype='|S1')? It seems like it does not work even at the model fitting step.How did you change the model with dtype U?
josef-pkt commentedon Oct 1, 2018
Because we will be dropping Python 2.7 within the next one or two years, it is better to stick with unicode
The change that I made locally is in sirf_errband_mc in svar_model.py lines 677 and 678
mk1564 commentedon Oct 1, 2018
Thanks for your explanation, but after I changed the code as you said, I run the model again
A = np.array([[1, 0, 0,0],['E', 1, 0,0],['E', 'E', 1,0],['E', 'E', 'E',1]])B = np.array([['E', 0, 0,0], [0, 'E',0, 0], [0, 0, 'E',0],[0,0,0,'E']])model = SVAR(df[['r','gm','gp','gy']], svar_type='AB', A=A, B=B)result = model.fit()the last line causes an error like the following.. Do you know how to fix this?
josef-pkt commentedon Oct 1, 2018
that's strange because there was no change in fit.
I opened #5285 to see how the fix works across python and numpy versions.