Repository navigation
Description
Hi,
I get error message for some models when I try to compute the standard errors for the coefficients. But the code in the package seems to be working well. Can you guys help me? Thanks!
z=result_bp.ys_lagged
cov=np.kron(scipy.linalg.inv(np.dot(z.T, z)), result_bp.sigma_u)
stderr = np.sqrt(np.diag(cov))
stderr.reshape((48, 4), order='C')
This one works fine if I manually input (48,4). The following is the error message when I try to use the attribute (stderr) in VAR.
ValueError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\internals.py in create_block_manager_from_blocks(blocks, axes)
4858
-> 4859 mgr = BlockManager(blocks, axes)
4860 mgr._consolidate_inplace()
~\Anaconda3\lib\site-packages\pandas\core\internals.py in init(self, blocks, axes, do_integrity_check)
3281 if do_integrity_check:
-> 3282 self._verify_integrity()
3283
~\Anaconda3\lib\site-packages\pandas\core\internals.py in _verify_integrity(self)
3492 if block._verify_integrity and block.shape[1:] != mgr_shape[1:]:
-> 3493 construction_error(tot_items, block.shape[1:], self.axes)
3494 if len(self.items) != tot_items:
~\Anaconda3\lib\site-packages\pandas\core\internals.py in construction_error(tot_items, block_shape, axes, e)
4842 raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4843 passed, implied))
4844
ValueError: Shape of passed values is (4, 48), indices imply (4, 24)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in ()
----> 1 result_bp.stderr
~\Anaconda3\lib\site-packages\statsmodels\base\wrapper.py in getattribute(self, attr)
39 obj = data.wrap_output(obj, how[0], *how[1:])
40 elif how:
---> 41 obj = data.wrap_output(obj, how=how)
42
43 return obj
~\Anaconda3\lib\site-packages\statsmodels\base\data.py in wrap_output(self, obj, how, names)
416 return self.attach_dates(obj)
417 elif how == 'columns_eq':
--> 418 return self.attach_columns_eq(obj)
419 elif how == 'cov_eq':
420 return self.attach_cov_eq(obj)
~\Anaconda3\lib\site-packages\statsmodels\base\data.py in attach_columns_eq(self, result)
528
529 def attach_columns_eq(self, result):
--> 530 return DataFrame(result, index=self.xnames, columns=self.ynames)
531
532 def attach_cov(self, result):
~\Anaconda3\lib\site-packages\pandas\core\frame.py in init(self, data, index, columns, dtype, copy)
377 else:
378 mgr = self._init_ndarray(data, index, columns, dtype=dtype,
--> 379 copy=copy)
380 elif isinstance(data, (list, types.GeneratorType)):
381 if isinstance(data, types.GeneratorType):
~\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_ndarray(self, values, index, columns, dtype, copy)
534 values = maybe_infer_to_datetimelike(values)
535
--> 536 return create_block_manager_from_blocks([values], [columns, index])
537
538 @Property
~\Anaconda3\lib\site-packages\pandas\core\internals.py in create_block_manager_from_blocks(blocks, axes)
4864 blocks = [getattr(b, 'values', b) for b in blocks]
4865 tot_items = sum(b.shape[0] for b in blocks)
-> 4866 construction_error(tot_items, blocks[0].shape[1:], axes, e)
4867
4868
~\Anaconda3\lib\site-packages\pandas\core\internals.py in construction_error(tot_items, block_shape, axes, e)
4841 raise ValueError("Empty data passed with indices specified.")
4842 raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4843 passed, implied))
4844
4845
ValueError: Shape of passed values is (4, 48), indices imply (4, 24)
Activity
josef-pkt commentedon Oct 6, 2018
It looks like there is something wrong with the pandas wrapper.
You could check the underlying result (note, I never tried that for VAR)
If
result_bpis your results instance returned by fit it should be the wrapped results, The underlying numpy array result instance isresult_bp._results.So you could try whether
result_bp._results.stderrreturns correct results.mk1564 commentedon Oct 6, 2018
Hi Josef,
Thanks for your quick comment. It works! But the things is it gives an array but does not create nice looking table with variable names. Can you tell me how I can make one?
logy logc logi logh
L1.logy 0.525307 0.303396 2.778826 0.428730
L1.logc 0.456111 0.263431 2.412786 0.372256
L1.logi 0.086517 0.049969 0.457668 0.070611
L1.logh 0.100109 0.057819 0.529566 0.081704
L2.logy 0.529679 0.305921 2.801955 0.432299
L2.logc 0.451868 0.260980 2.390341 0.368793
L2.logi 0.085625 0.049454 0.452949 0.069883
L2.logh 0.086582 0.050006 0.458013 0.070664
josef-pkt commentedon Oct 6, 2018
Does
result_bp.paramsreturn a DataFrame?If yes, then you could recreate a DataFrame from
result_bp._results.stderrwith the same index and column names as params.josef-pkt commentedon Oct 6, 2018
I cannot replicate this in the simple example from the sirf_errband PR
However, when I access cov_params I get a similar error
mk1564 commentedon Oct 6, 2018
I have another model for which
stderrworks fine. The usualstderrcommend creates a nice looking table but._results.stderrdoes not. Can you tell me why with._resultsI cannot make a table, even though the commend is essentially the same?josef-pkt commentedon Oct 6, 2018
When the model is created with pandas DataFrames, then the results are converted back to pandas dataframes or series. This is done in the wrapper.
So using the internal
_resultsonly has numpy methods available but not pandas.mk1564 commentedon Oct 6, 2018
Oh I see. Thanks!
josef-pkt commentedon Oct 6, 2018
@mk1564
We have PR #5220 that refactors and fixes some bugs in VAR/var_model.
If you are able to checkout and run from a development PR branch, then it would very helpful if you could check whether your code works with that refactoring.
Several names will be changed to more informative names, but it should be backwards compatible with deprecation, with maybe some exceptions.
I'm not sure yet whether we want to include that refactoring in 0.10, because merging before a release doesn't give us much time to figure out refactoring problems.
[-]VAR stderr[/-][+]BUG: VAR cov_params pandas wrapper is broken[/+]josef-pkt commentedon Oct 6, 2018
AFAICS, pandas wrapper for cov_params never worked, problem is similar to MNLogit when params is 2-D
the wrapper uses "cov"
but
param_namesandx_namesdefine exog names for each single equation but not for the raveledequation cross exoglist.I changed the title to reflect this.
jbrockmendel commentedon Oct 8, 2018
This is fixed in sm2, https://github.com/jbrockmendel/sm2, could be fixed here too if improving things were allowed.
BUG: Allow pandas to wrap VAR covariance
BUG: Allow pandas to wrap VAR covariance