Skip to content

ENH: McFadden and Cox&Snell Pseudo R squared to GLMResults - #7682

Merged
josef-pkt merged 3 commits into
statsmodels:mainfrom
josef-pkt:glm_prsquared
Sep 6, 2021
Merged

josef-pkt merged 3 commits into
statsmodels:mainfrom
josef-pkt:glm_prsquared

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

rebased version of #7367 squashed

api changes still open

@josef-pkt josef-pkt added this to the 0.13 milestone Sep 3, 2021
@josef-pkt

josef-pkt commented Sep 3, 2021 •

Copy link
Copy Markdown
Member Author

adding prsquared to summary() evaluates now llnull for summary

this breaks in one unit test with family=sm.families.Gamma()

    def test_non_invertible_hessian_fails_summary():
        # Test when the hessian fails the summary is still available.

E           ValueError: The first guess on the deviance function returned a nan.
  This could be a boundary  problem and should be reported.

locally, I get a second error with precision and test tolerance in test_tweedie_score
but only fails by a small margin, and looks unrelated to changes in this PR (I didn't run locally all genmod tests in some time)

            nhess = approx_hess_cs(pa, lambda x: model.loglike(x, scale=1))
            ahess = model.hessian(pa, scale=1)
>           assert_allclose(nhess, ahess, atol=1e-8, rtol=1e-8)
E           AssertionError:
E           Not equal to tolerance rtol=1e-08, atol=1e-08
E
E           Mismatched elements: 2 / 16 (12.5%)
E           Max absolute difference: 2.28975279e-08
E           Max relative difference: 1.93772825e-08

@josef-pkt

josef-pkt commented Sep 3, 2021 •

Copy link
Copy Markdown
Member Author

unit test for non-invertible hessian case was added in #3299
summary should work even if some results statistics are not available. In several cases we set results to nan.

Problem in this case is that fitting the null raises an exception instead of signaling non-convergence.

GLMResults.null is a misleading name, it only returns fittedvalues.

another strange part: llnull uses the scale of the full model self.scale ?
sounds like a bug for MLE, but recommended in some cases of LLR like tests.
already in #6953 (comment)

If we drop the wls part in null, then we could use results_null.llf (which would use the null model scale).
#6953 (comment)

test case has perfect fit and scale=0, both endog and exog in null model are ones.

deviance and loglike are nan if scale=0.

If I comment out the deviance check in _fit_irls, then unit test test_non_invertible_hessian_fails_summary fails with the PerfectSeparationError (At that point self.scale is 5.238529448733284e-32, not exactly zero.
#3703 #2680 #1705
For saturated models with perfect fit I switched to not using irls,

Those things are not directly related to this PR and need separate fixes.

@josef-pkt

Copy link
Copy Markdown
Member Author

all green now,

todo fixing api: no prsquared attribute(s) and summary is getting prsquared (CS)

adding McF for discrete cases to summary is left for future, #7687, users will be able to call the method

@josef-pkt

Copy link
Copy Markdown
Member Author

should be ready to merge when green

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant