0
$\begingroup$

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:

  1. Cut my continuous variable into 4 bins (using pd.cut)
  2. 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
  3. 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?

Thanks!

$\endgroup$
0
$\begingroup$

You could use a Generalize Additive Model, where you estimate the functional form of the relationship between your independent and dependent variable, i.e. $\log \frac{p_i}{1 - p_i} = f(x_i)$. If you are working in python I would recommend having a look at the pyGAM library.

$\endgroup$
5
  • $\begingroup$ Hi, thanks for the response! I'm sorry if this is a dumb question but are you able to expand on this part more: estimate the functional form of the relationship between your independent and dependent variable, i.e. log$\frac{p_i}{1-p_i} = f(x_i)$ - I know that equation is what you get from Logistic Regression if you assume linearity. Is this what I should be looking for in the output of the GAM? Or will the GAM just give the functional form and if it is non linear then the assumption is violated? $\endgroup$
    – pche3675
    Dec 2 '20 at 11:44
  • $\begingroup$ If the relationship is linear, then the output from the GAM will look like a straight line, i.e. the estimated $f$ will look like $\beta x$. The equation is the same as in the linear case, but also take into account that the relationship might be non-linear. If the GAM gives you a non-linear $f$, then I would say that the relationship is not linear. You could also compare (for example) the AIC of a logistic regression with $f$ and one with a linear trent $\beta x$. $\endgroup$
    – J.C.Wahl
    Dec 2 '20 at 12:03
  • $\begingroup$ I see. Just to clarify, you mean doing something like this: pygam.readthedocs.io/en/latest/notebooks/… and then checking the trends on each plot? $\endgroup$
    – pche3675
    Dec 2 '20 at 14:16
  • $\begingroup$ Yes, that sounds like a reasonable approach:) $\endgroup$
    – J.C.Wahl
    Dec 2 '20 at 15:16
  • $\begingroup$ Thank you, you have really helped me out :) $\endgroup$
    – pche3675
    Dec 3 '20 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.