head (d)
## id fu.days status drug age sex ascites
## 1 1 400 death penicillamine 21464 female 1
## 2 2 4500 censored penicillamine 20617 female 0
## 3 3 1012 death penicillamine 25594 male 0
## 4 4 1925 death penicillamine 19994 female 0
## 5 5 1504 censored due to liver tx placebo 13918 female 0
## 7 7 1832 censored placebo 20284 female 0
## hepatom spiders edema bili chol albumin copper alk.phos sgot trig
## 1 1 1 1.0 14.5 261 2.60 156 1718.0 137.95 172
## 2 1 1 0.0 1.1 302 4.14 54 7394.8 113.52 88
## 3 0 0 0.5 1.4 176 3.48 210 516.0 96.10 55
## 4 1 1 0.5 1.8 244 2.54 64 6121.8 60.63 92
## 5 1 1 0.0 3.4 279 3.53 143 671.0 113.15 72
## 7 1 0 0.0 1.0 322 4.09 52 824.0 60.45 213
## platelet protime stage outcome
## 1 190 12.2 4 1
## 2 221 10.6 3 0
## 3 151 12.0 4 1
## 4 183 10.3 4 1
## 5 136 10.9 3 0
## 7 204 9.7 3 0
reg= glm (outcome ~ drug + age + sex + ascites + bili + chol + albumin, family='binomial', data=d)
library(MKmisc)
HLgof.test(fit = fitted(reg), obs = d$outcome)
## $C
##
## Hosmer-Lemeshow C statistic
##
## data: fitted(reg) and d$outcome
## X-squared = 12.459, df = 8, p-value = 0.1319
##
##
## $H
##
## Hosmer-Lemeshow H statistic
##
## data: fitted(reg) and d$outcome
## X-squared = 12.755, df = 8, p-value = 0.1205
library(ResourceSelection)
## ResourceSelection 0.3-0 2016-11-04
hoslem.test(d$outcome, fitted(reg), g=10)
##
## Hosmer and Lemeshow goodness of fit (GOF) test
##
## data: d$outcome, fitted(reg)
## X-squared = 12.459, df = 8, p-value = 0.1319