Skip to content

BUG: GLM-Gaussian fit_constrained, wrong bse - #4195

Merged
josef-pkt merged 4 commits into
statsmodels:masterfrom
josef-pkt:bug_fit_constrained_glm
Jan 8, 2018
Merged

josef-pkt merged 4 commits into
statsmodels:masterfrom
josef-pkt:bug_fit_constrained_glm

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Jan 7, 2018 •

Copy link
Copy Markdown
Member

issue #4193

This currently adds unit tests for Gaussian compared to OLS for a single parameter constraint, inlcudes cov_type='HC0' test.

There is one test failure with master, bug not yet fixed.
The work around is to assign cov_params_default which doesn't fail the unit tests.

cov_type='HC0' looks correct with fit_constrained, tests don't fail

bug fix which most likely works is
to assign directly to cov_params_default in fit_regularized

side issue: OLS and GLM don't agree on scale with master (in this branch), difference in example is around 1%
I got agreement between OLS and GLM-Gaussian for scale when I worked on top of #3856 which looks like fixes the scale difference.

Aside: fit_constrained never got a follow-up #1749, see comments in original PR #1714

@josef-pkt josef-pkt added comp-base comp-genmod prio-high type-bug-wrong serious bugs that silently return incorrect numbers labels Jan 7, 2018
@josef-pkt josef-pkt added this to the 0.9 milestone Jan 7, 2018
@josef-pkt

Copy link
Copy Markdown
Member Author

as red as expected

more tests: the Poisson and Logit/Binomial tests in discrete test_constrained don't include unit tests for cov_type

@josef-pkt

josef-pkt commented Jan 7, 2018 •

Copy link
Copy Markdown
Member Author

correction: It looks like only discrete.Poisson has fit_constrained, it is not added to any other classes
unit tests are for GLM-Binomial not Logit,
edit this is because fit_constrained requires offset and only the count models in discrete have currently offset #1640.

Stata results are for Logit and for GLM Binomial, one Stata result, results_constraint2_robust, has robust cov_type but is not yet used in unit tests

@josef-pkt

Copy link
Copy Markdown
Member Author

question:
the original PR mentions convergence failures
last year I improved start_params in Poisson and better llnull handling.

Do the start_params changes affect or interact with fit_regularized? Is llnull correctly adjusted?

aside: Does llnull include an offset?
It is not excluded explicitly in the creating the constrained model.
In that case, using offset in the unit tests will not produce the same llnull as the constrained model.
How is the fixed part in the constraints that is reflected in transform offset accounted for in llnull computation?

@josef-pkt

Copy link
Copy Markdown
Member Author

aside: GLM._fit_gradient does correctly a normalized_cov_params scale correction

        if rslt.normalized_cov_params is None:
            cov_p = None
        else:
            cov_p = rslt.normalized_cov_params / scale

@josef-pkt

Copy link
Copy Markdown
Member Author

This should be green now, fixes scaling bug in GLM-Gaussian and makes the same change to the generic version and the Poisson method.
(This is not DRYed out yet, same code in 3 places. One problem that remain is that we don't have a robust way to recreate Results instances based on an existing model.)

This should be finished for the bug fix and unit tests, but there are more minor refactorings and changes possible, for a later PR.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.001%) to 82.083% when pulling ba00e63 on josef-pkt:bug_fit_constrained_glm into 64dc3ea on statsmodels:master.

@josef-pkt
josef-pkt force-pushed the bug_fit_constrained_glm branch from ba00e63 to a2e65a2 Compare January 8, 2018 01:21
@josef-pkt

Copy link
Copy Markdown
Member Author

There ain't no future in python 2.7
amended and force pushed to add future division to discrete test module

@coveralls

coveralls commented Jan 8, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 82.104% when pulling a2e65a2 on josef-pkt:bug_fit_constrained_glm into a33760f on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

green enough, merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-base comp-genmod prio-high type-bug-wrong serious bugs that silently return incorrect numbers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants