#### hosmerlem() will do the Hosmer-Lemeshow test, given the y and yhat vectors for the fittted data. #### This was changed a little bit from the origin hosmerlem function downloaded from #### https://stat.ethz.ch/pipermail/r-help/2008-September/174044.html hosmerlem <- function (y, yhat=n*prob, g = 10) { cutyhat <- cut(yhat, breaks = quantile(yhat, probs = seq(0, 1, 1/g)), include.lowest = T) obs <- xtabs(cbind(1 - y, y) ~ cutyhat) expect <- xtabs(cbind(1 - yhat, yhat) ~ cutyhat) chisq <- sum((obs - expect)^2/expect) if (chisq<1*(10^(-20))) P="." else P=ifelse((g==2),1,pchisq(chisq, g - 2,lower.tail=FALSE)) yhat c("X^2" = chisq, Df = g - 2, "P(>Chi)" = P) }