O'Reilly logo

R Statistical Application Development by Example Beginner's Guide by Prabhanjan Narayanachar Tattar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – The Hosmer-Lemeshow goodness-of-fit statistic

The Hosmer-Lemeshow goodness-of-fit statistic for logistic regression is one of the very important metrics for evaluating a logistic regression model. The hosmerlem function from the preceding web link will be used for the pass_logistic regression model.

  1. Extract the fitted values for the pass_logistic model with pass_hat <- fitted(pass_logistic).
  2. Create the function hosmerlem from the previously-mentioned URL:
    hosmerlem <- function(y, yhat, g=10) { cutyhat = cut(yhat, breaks = quantile(yhat, probs=seq(0, 1, 1/g)), include.lowest=TRUE) obs = xtabs(cbind(1 - y, y) ~ cutyhat) expect = xtabs(cbind(1 - yhat, yhat) ~ cutyhat) chisq = sum((obs - expect)^2/expect) P = 1 - pchisq(chisq, g - 2) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required