Hosmer-Lemeshow Goodness of Fit (GOF) Test.
hoslem.test(x, y, g = 10)
A list with class "htest" containing the following components:
"htest"
the value of the chi-squared test statistic, (sum((observed - expected)^2 / expected)).
sum((observed - expected)^2 / expected)
the degrees of freedom of the approximate chi-squared distribution of the test statistic (g - 2).
g - 2
the p-value for the test.
a character string indicating the type of test performed.
a character string giving the name(s) of the data.
the observed frequencies in a g-by-2 contingency table.
g
the expected frequencies in a g-by-2 contingency table.
a numeric vector of observations, binary (0/1).
expected values.
number of bins to use to calculate quantiles.
Peter Solymos by adapting code pieces from R help mailing list
The Hosmer-Lemeshow test is a statistical test for goodness of fit for logistic regression models.
Hosmer D W, Lemeshow S 2000. Applied Logistic Regression. New York, USA: John Wiley and Sons.
set.seed(123) n <- 500 x <- rnorm(n) y <- rbinom(n, 1, plogis(0.1 + 0.5*x)) m <- glm(y ~ x, family=binomial) hoslem.test(m$y, fitted(m))
Run the code above in your browser using DataCamp Workspace