I am trying to test goodness of fit for my legalistic regression using several
options as shown below. Â Hosmer-Lemeshow test (whose function I borrowed from
a previous post), Hosmerâle Cessie omnibus lack of fit test (also borrowed
from a previous post), Pearson chi-square test, and deviance test. Â All the
tests, except the deviance tests, produced p-values well above 0.05. Â Would
anyone please teach me why deviance test produce p-values such a small value
(0.001687886) that suggest lack of fit, while other tests suggest good fit? Did
I do something wrong?
Â
Thank you for your time and help!
Â
Kiyoshi
Â
Â
mod.fit <- glm(formula = no.NA$repcnd ~Â no.NA$svl, family = binomial(link =
logit), data =Â no.NA, na.action = na.exclude, control = list(epsilon =
0.0001, maxit = 50, trace = F))
Â
> # Option 1: Hosmer-Lemeshow test
> mod.fit <- glm(formula = no.NA$repcnd ~Â no.NA$svl, family = binomial(link =
> logit), data =Â no.NA, na.action = na.exclude, control = list(epsilon =
> 0.0001, maxit = 50, trace = F))
           Â
 >  hosmerlem <- function (y, yhat, 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)
P <- 1 - pchisq(chisq, g - 2)
c("X^2" = chisq, Df = g - 2, "P(>Chi)" = P)
}
Â
> hosmerlem(no.NA$repcnd, fitted(mod.fit))
 X^2                     Df Â
                       P(>Chi)
7.8320107 Â Â Â Â Â Â Â Â Â Â 8.0000000Â Â Â Â Â Â Â Â Â Â Â 0.4500497
Â
Â
> # Option 2 - Hosmerâle Cessie omnibus lack of fit test:
> library(Design)
> lrm.GOF <- lrm(formula = no.NA$repcnd ~Â no.NA$svl, data =Â no.NA, y = T, x
> = T)
> resid(lrm.GOF,type = "gof")
Sum of squared errors    Expected value|H0      Â
SDÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
ZÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â P
               48.3487115         Â
              48.3017399          Â
             0.1060826    0.4427829    0.6579228
Â
> # Option 3 - Pearson chi-square p-value:
> pp <- sum(resid(lrm.GOF,typ="pearson")^2)
> 1-pchisq(pp, mod.fit$df.resid)
[1] 0.4623282
Â
Â
> # Option 4 - Deviance (G^2) test:
> 1-pchisq(mod.fit$deviance, mod.fit$df.resid)
[1] 0.001687886
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.