R: Display Hosmer-Lemeshow statistic and table of probabilities...
HLTest
R Documentation
Display Hosmer-Lemeshow statistic and table of probabilities following logistic
regression using glm with binomial family.
Description
Provides a Hosmer-Lemeshow statistic and table following logistic regression.
Usage
HLTest(obj, g)
Arguments
obj
model name
g
number of groups
Format
x
The function has two arguments: model name, number of groups
Details
HLTest is a post-estimation function for logistic regression, following the use
of glm(). Usage displays a table of observed vs predicted groups and an overall
H-L goodness-of-fit statistic.
Value
list
Note
HLTest must be loaded into memory in order to be effectve. As a function in LOGIT,
it is immediately available to a user. My thanks to Bilger and Loughlin for the
use of their function.
Author(s)
Adapted from Loughlin, T.M. in Bilder and Loughlin, 2015
References
Hilbe, J. M. (2015), Practical Guide to Logistic Regression, Chapman & Hall/CRC.
Bilder, C.R. and Loughlin, T.M. (2015), Analysis of Categorical Data with R, Chapman & Hall/CRC.
Hilbe, J. M. (2009), Logistic Regression Models, Chapman & Hall/CRC.
library(MASS)
library(LOGIT)
data(medpar)
mylogit <- glm( died ~ los + white + hmo, family=binomial, data=medpar)
grp10 <- HLTest(obj=mylogit, g=10)
cbind(grp10$observed, round(grp10$expect, digits = 1))
grp10
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LOGIT)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LOGIT/HLTest.Rd_%03d_medium.png", width=480, height=480)
> ### Name: HLTest
> ### Title: Display Hosmer-Lemeshow statistic and table of probabilities
> ### following logistic regression using glm with binomial family.
> ### Aliases: HLTest
> ### Keywords: models
>
> ### ** Examples
>
> library(MASS)
> library(LOGIT)
> data(medpar)
> mylogit <- glm( died ~ los + white + hmo, family=binomial, data=medpar)
> grp10 <- HLTest(obj=mylogit, g=10)
> cbind(grp10$observed, round(grp10$expect, digits = 1))
Y0 Y1 Y0hat Y1hat
[0.0213,0.278] 101 52 117.7 35.3
(0.278,0.309] 104 42 102.9 43.1
(0.309,0.325] 112 45 107.2 49.8
(0.325,0.339] 109 37 97.2 48.8
(0.339,0.352] 119 42 105.0 56.0
(0.352,0.366] 137 54 121.8 69.2
(0.366,0.373] 20 3 14.5 8.5
(0.373,0.387] 199 77 171.0 105.0
(0.387,0.402] 61 81 85.5 56.5
(0.402,0.409] 20 80 59.1 40.9
> grp10
Hosmer and Lemeshow goodness-of-fit test with 10 bins
data: mylogit
X2 = 124.38, df = 8, p-value < 2.2e-16
>
>
>
>
>
> dev.off()
null device
1
>