Sunday, February 18, 2018

Lowess smooth in logistic regression using R based on Applied Logistic Regression, 3th ed, HOSMER

To to determine linearity in the logit for a continuous variable, one can use lowess smoothed scatterplot as described in Applied Logistic Regression, 3rd Edition, in chapter 4.2.1 Methods to Examine the Scale of a Continuous Covariate in the Logit.

In the book this is illustrated using Scale_Example data from the book and STATA. I dont have stata, but this can be replicated with a good agreement in R.

For this, I will use logitloess function described here.



The data sets used in the book can be obtained here: http://wiley.mpstechnologies.com/wiley/BOBContent/searchLPBobContent.do # read in Scale_Example.txt that contains data for the example
mydata = read.table("~/Applied_Logistic_Regression_by_Hosmer_Lemeshow_3th_ed_2013/Scale Example/Scale_Example.txt")

# seperate data into x and y
y=mydata[,1]
x=mydata[,2]

# plot lowess graph
logitloess(x,y)

The resulting plot is very similar to the one provided in the book (Figure 4.1). Its not exactly same, but this could be due to differences in the implementation of the logitloess methods between R and STATA. Nevertheless, the conclusions from the plot obtained in R are same as those in the book.