I am using splines to test the linearity assumption of Logistic Regression as per what is mentioned in this website: https://www.statisticssolutions.com/logistic-regression-assumptions/ :
Linearity with an ordinal or interval independent variable and the odds ratio can be checked by creating a new variable that divides the existing independent variable into categories of equal intervals and running the same regression on these newly categorized versions as categorical variables. Linearity is demonstrated if the beta coefficients increase or decrease in linear steps (Garson, 2009).
I just want to check that my implementation is right. I am using
Python. My steps are:
- Cut my continuous variable into 4 bins (using
- Convert this into dummy variables so that I end up with 4 categoric variables that are either 0 or 1 depending on if the variable value originally fell into that bin
- Perform a logistic regression on each categoric variable and obtain the beta parameter - when doing the regression I fit each categoric variable to my list of classes
I just performed this for one variable (this actually had 3 bins) and I got: -2.46, -0.25, 2.099. Given that the interval between each beta coefficient differs by 0.4 is this enough to say that my continuous variable doesn't break the linear assumption?
Would it be better to use more splines? Also, what is a good amount of samples to have in each bin? Does this even matter?