Skip to content

ENH: add Hosmer-lemeshow gof test #7095

Open

Description

@josef-pkt

a specific issue just for Hosmer-Lemeshow, I opened several more general issues

R package generalhoslem has three tests compared in the Hosmer et al articles
https://rdrr.io/cran/generalhoslem/man/logitgof.html
However: "Finally, it has been observed that the results from this implementation of the binary and ordinal Hosmer-Lemeshow tests and the Lipsitz test are slightly different from the Stata implementations. It is not not yet clear why this is but is under investigation." (quote from Details docstring)

for OrderedModel I get similar results to theirs but not the same, eg. my chi2=21.34, theirs is chi2=20.95, both at df=17.
similar to difference in my default to Stata: differences in binsizes in groups, e.g. groups are not exactly the same.
I haven't tried Stata for this yet. (example from unit test for OrderedModel using UCLA data)
WIP for #7094

update: I checked with Stata, chi2=21.504 slightly different from mine

The problem is not the groupsizes because all groups have the same size (nobs is multiple of number of groups)

Problem is in ties: there are 180 out of 400 ties in sort_var (average probability with score np.arange(1, k+1).
The split into groups depends on the sort algorithm.
If I use kind="stable" in argsort, then I get the same chi2 as in R generalhoslem. None of the numpy sorting algorithm replicates the Stata results.

Activity

  1. josef-pkt commented on Oct 12, 2020

    @josef-pkt
    MemberAuthor

    Hosmer-Lemeshow for OrderedModel

    code to compute it, but no convenience function or method yet:
    (from unit test in #7094 )

            import statsmodels.stats.diagnostic_gen as dia
            # TODO: add more properties or methods to Results class
            fitted = res1.predict()
            y_dummy = (res1.model.endog[:, None] == np.arange(3)).astype(int)
            sv = (fitted * np.arange(1, 3+1)).sum(1)
            dt = dia.test_chisquare_binning(
                y_dummy, fitted, sort_var=sv, bins=10, df=None, ordered=True,
                sort_method="stable")
    
  2. josef-pkt commented on Oct 23, 2020

    @josef-pkt
    MemberAuthor

    HL test for survey data

    Archer, Kellie J., and Stanley Lemeshow. 2006. “Goodness-of-Fit Test for a Logistic Regression Model Fitted Using Survey Sample Data.” The Stata Journal 6 (1): 97–105. https://doi.org/10.1177/1536867X0600600106.

  3. josef-pkt commented on Jul 21, 2021

    @josef-pkt
    MemberAuthor

    #7094 merged PR added hosmer lemeshow for Binary, Multinomial and OrderedModel
    with comments on background and other packages

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions