[R] Hosmer-Lemeshow test for Cox model
jane.wong
jane.wong083 at gmail.com
Thu Jul 5 16:01:23 CEST 2012
Dear list,
Usually we use Hosmer-Lemeshow test to test the goodness of fit for logistic
model, but if I use it to test for Cox model, how can I get the observed
probability for each group?
Suppose I calculated the 5-year predicted probability using Cox model, then
I split the dataset into 10 group according to this predicted probability.
We should compare the observed probability with predicted probability within
each group,but how to calculate this observed probability, should I use
Kaplan-Meier to estimate it? how should I modify the following
program,thanks.
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)
return(list(chisq=chisq,p.value=P))
}
--
View this message in context: http://r.789695.n4.nabble.com/Hosmer-Lemeshow-test-for-Cox-model-tp4635482.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list