Skip to content

BUG: GEE fit_history - #5789

Merged
kshedden merged 8 commits into
statsmodels:masterfrom
kshedden:gee_fit_history
May 31, 2019
Merged

kshedden merged 8 commits into
statsmodels:masterfrom
kshedden:gee_fit_history

Conversation

@kshedden

Copy link
Copy Markdown
Contributor

We can't delete fit_history after fitting the model (while transferring it to the results), because we may need to call update_params or other methods on the parent model that write to the fit history.

Also add some warnings.

@kshedden

Copy link
Copy Markdown
Contributor Author

Also closes #5786

Comment thread statsmodels/genmod/tests/test_gee.py Outdated
assert_almost_equal(score_results["df"],
mod_lr.score_test_results["df"])

for f in False, True:

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.

Informative variable name for f, brackets around list?

Comment thread statsmodels/genmod/tests/test_gee.py Outdated
_ = mod.compare_score_test(res_sub)

# Parent and submodel are the same dimension
with assert_warns(UserWarning):

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.

Pytest.warns, match kwarg

fam = sm.families.Tweedie(var_power=2, eql=True)
model1 = sm.GLM(y, x, family=fam)
result1 = model1.fit(method="newton")
result1 = model1.fit(method="newton", scale=scale)

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.

Is this related to the rest of the Pr?

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.

before this fades into distant memory, any thoughts here?

@codecov

codecov Bot commented May 25, 2019

Copy link
Copy Markdown

Codecov Report

Merging #5789 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5789      +/-   ##
==========================================
- Coverage   82.45%   82.41%   -0.04%     
==========================================
  Files         594      594              
  Lines       93689    93707      +18     
  Branches    10357    10361       +4     
==========================================
- Hits        77249    77229      -20     
- Misses      14042    14074      +32     
- Partials     2398     2404       +6
Impacted Files Coverage Δ
statsmodels/genmod/tests/test_glm.py 98.9% <100%> (-0.17%) ⬇️
statsmodels/genmod/tests/test_gee.py 99.17% <100%> (+0.01%) ⬆️
...smodels/genmod/generalized_estimating_equations.py 82.79% <100%> (+0.26%) ⬆️
statsmodels/iolib/openfile.py 66.66% <0%> (-9.1%) ⬇️
statsmodels/base/wrapper.py 86.76% <0%> (-4.42%) ⬇️
statsmodels/datasets/utils.py 80.24% <0%> (-3.09%) ⬇️
statsmodels/tsa/tsatools.py 87.34% <0%> (-2.47%) ⬇️
statsmodels/tsa/base/tsa_model.py 87.21% <0%> (-2.29%) ⬇️
statsmodels/iolib/foreign.py 72% <0%> (-1.41%) ⬇️
statsmodels/iolib/tests/test_foreign.py 97.22% <0%> (-1.39%) ⬇️
... and 14 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 22aaef4...fca7ad2. Read the comment docs.

@codecov

codecov Bot commented May 25, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5789 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5789      +/-   ##
==========================================
+ Coverage   82.45%   82.47%   +0.02%     
==========================================
  Files         594      595       +1     
  Lines       93689    93790     +101     
  Branches    10357    10357              
==========================================
+ Hits        77249    77354     +105     
+ Misses      14042    14040       -2     
+ Partials     2398     2396       -2
Impacted Files Coverage Δ
statsmodels/genmod/tests/test_glm.py 99.07% <100%> (ø) ⬆️
statsmodels/genmod/tests/test_gee.py 99.17% <100%> (+0.01%) ⬆️
...smodels/genmod/generalized_estimating_equations.py 82.71% <100%> (+0.18%) ⬆️
statsmodels/sandbox/distributions/extras.py 60.61% <0%> (-0.37%) ⬇️
statsmodels/miscmodels/tmodel.py 87.01% <0%> (-0.17%) ⬇️
statsmodels/stats/tests/test_mediation.py 100% <0%> (ø) ⬆️
...tsmodels/tsa/statespace/tests/test_concentrated.py 100% <0%> (ø) ⬆️
...tsmodels/sandbox/nonparametric/densityorthopoly.py 0% <0%> (ø) ⬆️
statsmodels/discrete/tests/test_constrained.py 90.6% <0%> (ø) ⬆️
statsmodels/tsa/filters/_utils.py 42.5% <0%> (ø) ⬆️
... and 56 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 22aaef4...47e6a21. Read the comment docs.

@coveralls

coveralls commented May 25, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 84.999% when pulling 47e6a21 on kshedden:gee_fit_history into 22aaef4 on statsmodels:master.


# It is easy to forget to set the scale parameter. Sometimes
# this is intentional, so we warn.
if isinstance(self.family, families.Gaussian) and scale is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GEE also allows other families with scale != 1

https://www.statsmodels.org/dev/_modules/statsmodels/genmod/generalized_estimating_equations.html#GEE.estimate_scale
lists the families with scale=1, instead of the complement set

in general there should be a scale option as in GLM, e.g. to handle purely overdispersed Poisson (i.i.d. with scale!=1).

@kshedden
kshedden merged commit 4f17158 into statsmodels:master May 31, 2019
qler1 = result1.qic()
qler2 = result2.qic()
with warnings.catch_warnings():
warnings.simplefilter("ignore")

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.

does this warn consistently and/or intentionally? i.e. could be pytest.warns?

mod_sub = gee.GEE(endog, exog, group)
res_sub = mod_sub.fit()
mod = gee.GEE(endog, exog, group)
_ = mod.compare_score_test(res_sub)

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.

could part of this block be outside of the pytest.warns context?

assert_almost_equal(score_results["p-value"],
mod_lr.score_test_results["p-value"])
assert_almost_equal(score_results["df"],
mod_lr.score_test_results["df"])

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.

future reference, the lint-compatible version of this is one of:

assert_almost_equal(score_results["df"],
                                    mod_lr.score_test_results["df"])

assert_almost_equal(
    score_results["df"],
    mod_lr.score_test_results["df"])


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.

5 participants