# Goodness of fit for logistic regression in r

I am running a logistic regression model in r programming and wanted to know the goodness of fit of it since the command does not give out the f-test value as in the linear regression models.

So I used the following command:

summary( glm( vomiting ~ age, family = binomial(link = logit) ) )

# Call:
# glm(formula = vomiting ~ age, family = binomial(link = logit))

# Deviance Residuals:
#    Min       1Q   Median       3Q      Max
# -1.0671  -1.0174  -0.9365   1.3395   1.9196

#  Coefficients:
#               Estimate Std. Error z value Pr(>|z|)
#  (Intercept) -0.141729   0.106206  -1.334    0.182
#  age         -0.015437   0.003965  -3.893 9.89e-05 ***
#  ---
#  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' '

#  (Dispersion parameter for binomial family taken to be 1
#  Null deviance: 1452.3  on 1093  degrees of freedom
#  Residual deviance: 1433.9 on 1092  degrees of freedom

#  AIC: 1437.9
#  Number of Fisher Scoring iterations: 4


Then I run the following which I got some idea from someone else and get:

 1-pchisq(1452.3-1433.9, 1093-1092)
# [1] 1.79058e-05


May I know in detail what the null hypothesis and alternative hypothesis are and what this 1.79058e-05 value means in this case?

## migrated from stackoverflow.comOct 22 '17 at 16:23

This question came from our site for professional and enthusiast programmers.

• I suggest to use the Hosmer-Lemeshow goodness of fit test for logistic regression which is implemented in the ResourceSelection library with the hoslem.test function. See: thestatsgeek.com/2014/02/16/… – Marco Sandri Oct 22 '17 at 9:32
• I agree with @RuiBarradas. The test that you are using is not a goodness-of-fit test but a likelihood ratio test for the comparison of the proposed model with the null model. P=1.79058e-05 means that the fit of your model is significantly better than the fit of the null model – Marco Sandri Oct 22 '17 at 14:38
• Like @MarcoSandri says, your model is significantly better than the model vomiting ~ 1, which is basically a computation of the means. Read the link I've provided you with. – Rui Barradas Oct 22 '17 at 15:40
• @Eric No. If you want to make a goodness-of-fit test on your logistic regression model, use the Hosmer-Lemeshow test: en.wikipedia.org/wiki/Hosmer%E2%80%93Lemeshow_test The test statistic asymptotically follows a chi-square distribution. – Marco Sandri Oct 22 '17 at 17:05
• @Eric The Hosmer–Lemeshow test determine if the differences between observed and expected proportions are significant. If your p is greater than 0.05, than you can say that you have a good fit. – Marco Sandri Oct 22 '17 at 17:24

I suggest to use the Hosmer-Lemeshow goodness of fit test for logistic regression which is implemented in the ResourceSelection library with the hoslem.test function. See: thestatsgeek.com/2014/02/16/ - Marco Sandri

But as @kjetilbhalvorsen points out below, Frank Harrell disagrees:

The Hosmer-Lemeshow test is to some extent obsolete because it requires arbitrary binning of predicted probabilities and does not possess excellent power to detect lack of calibration. It also does not fully penalize for extreme overfitting of the model. Better methods are available such as

Hosmer, D. W.; Hosmer, T.; le Cessie, S. & Lemeshow, S. A comparison of goodness-of-fit tests for the logistic regression model. Statistics in Medicine, 1997, 16, 965-980

Their new measure is implemented in the R rms package.

• I've copied this comment by @MarcoSandri as a community wiki answer because the comment is, more or less, an answer to this question. We have a dramatic gap between answers and questions. At least part of the problem is that some questions are answered in comments: if comments which answered the question were answers instead, we would have fewer unanswered questions. – mkt Aug 19 '18 at 11:53
• Please see this answer stats.stackexchange.com/questions/18750/… by Frank Harrell for diverging opinion! He seems to think Hosmer-Lemeshow is obsolete – kjetil b halvorsen Aug 31 '18 at 8:35
• @kjetilbhalvorsen Thanks, edited to include that disagreement. – mkt Aug 31 '18 at 8:43