O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Goodness of fit example on the PainGLM data

In the following example, we will apply the Hosmer-Lemeshow test to the PainGLM dataset. We will implement the Hosmer-Lemeshow test via the hoslem.test() function contained within the ResourceSelection package.

To set up the test, supply the observed values, with the fitted (predicted) values as part of the hoslem.test() function:

install.packages("ResourceSelection")library(ResourceSelection)hoslem.test(PainGLM$y,fitted(PainGLM)) 

The hoslem.test output is written to the console:

  Hosmer and Lemeshow goodness of fit (GOF) test 
 
data:  PainGLM$y, fitted(PainGLM) 
X-squared = 8.4981, df = 8, p-value = 0.3864 

From the p-value statistic (0.38) the test shows that there is no problem with the fit.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required