Learn R Programming

binomTools (version 1.0-1)

HLtest.Rsq: Goodness-of-fit tests for GLMs for binary data

Description

Goodness-of-fit tests for GLMs for binary data including the Hosmer-Lemeshow decile test and X-squared test with normal approximation.

Usage

## S3 method for class 'Rsq':
HLtest(object, method = c("deciles", "fixed"),
         decile.type = 8, ...)

## S3 method for class 'HLtest.Rsq':
print(x, digits = getOption("digits"), ...)

## S3 method for class 'Rsq':
X2GOFtest(x, ...)

## S3 method for class 'X2GOFtest.Rsq':
print(x, ...)

Arguments

object
An Rsq object
x
An HLtest.Rsq or an X2GOFtest.Rsq object
method
The type of Hosmer-Lemeshow test to be performed. The "deciles" method should be more accurate (Hosmer et al, 1997)
decile.type
The quantile computation method; see quantile for details
digits
the desired number of printed digits
...
currently not used

Value

  • For HLtest.Rsq an object of class HLtest.Rsq with components
  • expectedthe expected frequencies in the 2 x 10 entries
  • observedthe observed frequencies in the 2 x 10 entries
  • residPearson residuals
  • X2the Pearson X-squared statistic
  • p.valuethe p-value for the goodness-of-fit test
  • methodthe method used for the test
  • For X2GOFtest an object of class X2GOFtest with components
  • p.valuethe p-value for the goodness-of-fit test
  • z.scorethe standardized z-score for the goodness-of-fit test
  • RSSthe residual sums of squares term
  • X2the pearson chi-squared statistic

Details

These tests are known to have very low power. They are only appropriate when the fitted frequencies are very low and when the covariate pattern dictates strictly binary observations.

References

Hosmer, D.W. and Lemeshow, S. (1980). Goodness of fit tests for the multiple logistic regression model. Communications in Statistics - Theory and Methods, A9(10), p. 1043-1069.

Examples

Run this code
## Lifted from example(predict.glm):
ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- factor(rep(c("M", "F"), c(6, 6)))
SF <- cbind(numdead, numalive=20-numdead)
budworm.lg <- glm(SF ~ sex*ldose, family=binomial)
## summary(budworm.lg)

(Rsq.budworm <- Rsq(budworm.lg))

HLtest(Rsq.budworm)
HLtest(Rsq.budworm, method="fixed")
X2GOFtest(Rsq.budworm)

Run the code above in your browser using DataLab