Skip to content

BUG: Fix multidimensional model cov_params when using pandas - #5956

Merged
bashtage merged 3 commits into
statsmodels:masterfrom
bashtage:var-cov-params
Jul 18, 2019
Merged

bashtage merged 3 commits into
statsmodels:masterfrom
bashtage:var-cov-params

Conversation

@bashtage

Copy link
Copy Markdown
Member
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in master and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/master -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@coveralls

coveralls commented Jul 16, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.007%) to 85.749% when pulling f3fba98 on bashtage:var-cov-params into 9298953 on statsmodels:master.

@codecov

codecov Bot commented Jul 16, 2019

Copy link
Copy Markdown

Codecov Report

Merging #5956 into master will increase coverage by <.01%.
The diff coverage is 98.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5956      +/-   ##
==========================================
+ Coverage      83%   83.01%   +<.01%     
==========================================
  Files         604      604              
  Lines       95262    95299      +37     
  Branches    10449    10455       +6     
==========================================
+ Hits        79072    79109      +37     
  Misses      13767    13767              
  Partials     2423     2423
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/tests/test_var.py 94.39% <100%> (+0.13%) ⬆️
statsmodels/tsa/vector_ar/var_model.py 88.65% <100%> (-0.08%) ⬇️
statsmodels/discrete/tests/test_discrete.py 99.55% <100%> (ø) ⬆️
statsmodels/discrete/discrete_model.py 88.28% <100%> (+0.07%) ⬆️
statsmodels/base/data.py 90.69% <91.66%> (+0.25%) ⬆️

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 0880f35...dd125db. Read the comment docs.

@codecov

codecov Bot commented Jul 16, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5956 into master will decrease coverage by 0.22%.
The diff coverage is 98.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5956      +/-   ##
==========================================
- Coverage   83.24%   83.01%   -0.23%     
==========================================
  Files         610      604       -6     
  Lines       95657    95299     -358     
  Branches    10483    10455      -28     
==========================================
- Hits        79625    79109     -516     
- Misses      13626    13767     +141     
- Partials     2406     2423      +17
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/tests/test_var.py 94.39% <100%> (-0.1%) ⬇️
statsmodels/tsa/vector_ar/var_model.py 88.65% <100%> (-0.08%) ⬇️
statsmodels/discrete/tests/test_discrete.py 99.55% <100%> (-0.3%) ⬇️
statsmodels/discrete/discrete_model.py 88.28% <100%> (+0.09%) ⬆️
statsmodels/base/data.py 90.69% <91.66%> (+0.22%) ⬆️
statsmodels/robust/norms.py 80.92% <0%> (-16%) ⬇️
statsmodels/stats/_lilliefors.py 82.75% <0%> (-14.71%) ⬇️
statsmodels/iolib/openfile.py 66.66% <0%> (-14.11%) ⬇️
statsmodels/robust/robust_linear_model.py 79.14% <0%> (-13.81%) ⬇️
statsmodels/stats/tabledist.py 40.78% <0%> (-10.57%) ⬇️
... and 276 more

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 c860d30...e6fb0ce. Read the comment docs.

@bashtage

Copy link
Copy Markdown
Member Author

@josef-pkt Would be good if you could look at this since it is deep (affects base).

@bashtage
bashtage requested a review from josef-pkt July 17, 2019 20:41
Comment thread statsmodels/discrete/discrete_model.py Resolved
@jbrockmendel

Copy link
Copy Markdown
Contributor

Instead of "xname.yname", I think we'd be better off with a MultiIndex that didn't mangle the names at all (e.g. retained non-str names), see https://github.com/jbrockmendel/sm2/blob/master/sm2/base/data.py#L527

Extend PandasData to allow cov_names to be set separately from param_names

closes statsmodels#5305
closes statsmodels#2270
@bashtage

Copy link
Copy Markdown
Member Author

Instead of "xname.yname", I think we'd be better off with a MultiIndex that didn't mangle the names at all (e.g. retained non-str names)

Great idea. Much better than munged strings.

@bashtage

Copy link
Copy Markdown
Member Author

As for sm2, that fix doesn't work across the board since VAR and MNLogit use reverse orders for the outer and inner indices.

Fix cov_params and conf_int when using pandas

closes statsmodels#814
@bashtage
bashtage merged commit 876dd47 into statsmodels:master Jul 18, 2019
@bashtage
bashtage deleted the var-cov-params branch July 18, 2019 20:56
getattr(bivariate_var_result, attr)


def test_var_cov_params(bivariate_var_data):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test name should reflect its about pandas. ill handle in follow-up


import numpy as np
import pandas as pd
from pandas.testing import assert_index_equal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty much everywhere else we import from pandas.util.testing (and im not sure if we ever use statsmodels.compat.pandas.ptesting). ill take a look in follow-up.

#_wrap_methods = lm.wrap.union_dicts(
# _wrap_methods = lm.wrap.union_dicts(
# lm.RegressionResultsWrapper._wrap_methods,
# _methods)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill fix in follow-up

@jbrockmendel

Copy link
Copy Markdown
Contributor

minor comments, generally looks good

jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request Jul 19, 2019
bashtage added a commit that referenced this pull request Jul 19, 2019
# use range below to ensure sortedness
ynames = [ynames[key] for key in range(int(self.J))]
idx = MultiIndex.from_product((ynames[1:], self.data.xnames),
names=(yname, None))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on adding level names?

self.data.xnames[k_trend:])

self.data.cov_names = pd.MultiIndex.from_product((self.data.xnames,
self.data.ynames))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too level names might be helpful

@bashtage bashtage added this to the 0.11 milestone Dec 18, 2019
@bashtage bashtage changed the title BUG: Fix mutidimensional model cov_params when using pandas BUG: Fix multidimensional model cov_params when using pandas Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: VAR cov_params pandas wrapper is broken BUG: VAR cov_params pandas wrapper broken MNLogit.cov_params is broken when wrapped.

3 participants