R: Hosmer-Lemeshow Goodness of Fit Test

HLtest {vcdExtra} | R Documentation

## Hosmer-Lemeshow Goodness of Fit Test

### Description

The `HLtest` function computes the classical Hosmer-Lemeshow (1980) goodness of fit test for a binomial `glm` object in logistic regression

The general idea is to assesses whether or not the observed event rates match expected event rates in subgroups of the model population. The Hosmer-Lemeshow test specifically identifies subgroups as the deciles of fitted event values, or other quantiles as determined by the `g` argument. Given these subgroups, a simple chisquare test on `g-2` df is used.

In addition to `print` and `summary` methods, a `plot` method is supplied to visualize the discrepancies between observed and fitted frequencies.

### Usage

    HosmerLemeshow(model, g = 10)

    HLtest(model, g = 10)

    ## S3 method for class 'HLtest'
    print(x, ...)
    ## S3 method for class 'HLtest'
    summary(object, ...)
    ## S3 method for class 'HLtest'
    plot(x, ...)
    ## S3 method for class 'HLtest'
    rootogram(x, ...)

### Arguments

`model` | A `glm` model object in the `binomial` family
`g` | Number of groups used to partition the fitted values for the GOF test.
`x, object` | A `HLtest` object
`...` | Other arguments passed down to methods

### Value

A class `HLtest` object with the following components:

`table` | A data.frame describing the results of partitioning the data into `g` groups with the following columns: `cut`, `total`, `obs`, `exp`, `chi`
`chisq` | The chisquared statistics
`df` | Degrees of freedom
`p.value` | p value
`groups` | Number of groups
`call` | `model` call

### Author(s)

Michael Friendly

### References

Hosmer, David W., Lemeshow, Stanley (1980). A goodness-of-fit test for multiple logistic regression model. Communications in Statistics, Series A, 9, 1043-1069.

Hosmer, David W., Lemeshow, Stanley (2000). Applied Logistic Regression, New York: Wiley, ISBN 0-471-61553-6

Lemeshow, S. and Hosmer, D.W. (1982). A review of goodness of fit statistics for use in the development of logistic regression models. American Journal of Epidemiology, 115(1), 92-106.

### See Also

`rootogram`, ~~~

### Examples

    data(birthwt, package="MASS")
    # how to do this without attach?
    attach(birthwt)
    	race = factor(race, labels = c("white", "black", "other"))
    	ptd = factor(ptl > 0)
    	ftv = factor(ftv)
    	levels(ftv)[-(1:2)] = "2+"
    	bwt <- data.frame(low = factor(low), age, lwt, race,
        	smoke = (smoke > 0), ptd, ht = (ht > 0), ui = (ui > 0), ftv)
    detach(birthwt)
    options(contrasts = c("contr.treatment", "contr.poly"))
    BWmod <- glm(low ~ ., family=binomial, data=bwt)

    (hlt <- HLtest(BWmod))
    str(hlt)
    summary(hlt)
    plot(hlt)

    # basic model
    BWmod0 <- glm(low ~ age, family=binomial, data=bwt)
    (hlt0 <- HLtest(BWmod0))
    str(hlt0)
    summary(hlt0)
    plot(hlt0)

[Package vcdExtra version 0.7-1 Index]