0
$\begingroup$

I am working on the logistic regression and I am unsure if I should log-transform my predictor before conducting the analysis. My predictor (continuous variable; pre-test score) is not normally distributed. However, its relationship with the logit of my outcome variable appears to be linear based on the following code (visualized by the plot).

My question is

1) is this correct code to assess the relationship between the logit outcome vs predictor? and
2) If so, does the linear relationship mean that I do not need to log transform my predictor even the predictor itself is not normally distributed?

lr.fit4 <- glm(disease~ pre_score, data=mydata, family=binomial(link="logit"))
logodds <- lr.fit4$linear.predictors
plot(logodds ~ mydata$pre_score)
$\endgroup$
4
  • 3
    $\begingroup$ What makes you think predictors have to be normally distributed? That is not an assumption of logistic regression. $\endgroup$
    – Noah
    Commented Dec 7, 2021 at 5:06
  • $\begingroup$ So, am I checking the assumption (linearity between logit outcome vs predictor) correctly? $\endgroup$
    – R Beginner
    Commented Dec 7, 2021 at 5:21
  • 1
    $\begingroup$ No; the plot will by definition show an exactly linear fit. It doesn't tell you anything. Instead of assessing linearity, why don't you just fit a flexible model? $\endgroup$
    – Noah
    Commented Dec 7, 2021 at 6:31
  • $\begingroup$ @Noah So as long as I use a flexible model (spline or GAM), then the assumption of logistic regression will always be met? $\endgroup$
    – R Beginner
    Commented Dec 7, 2021 at 19:17

1 Answer 1

0
$\begingroup$

According to the documentation of glm, the property glm$linear.predictors is "the fit on link scale", i.e. in your case

$$\mbox{linear.predictors} = \beta_0 + \beta_1\cdot \mbox{pre_score}$$

It is thus a linear relationship by definition and your test is pointless.

Concerning the question about log-transform: as pointed out by Noah in the comments, predictors do not need to be normally distributed, and there is no necessity to introduce a transform to achieve this. The log-transform is recommended, however, if the variable range spans over several orders of magnitude. In that case, a regression can be dominated by the large values, which might be remedied by a log-transformation. Note that you should use $\log(1+x)$ if your variable $x$ can become zero.

There are methods that parametrize the transform and try to guess appropriate parameters (e.g. Box-Cox for response transformation in linear models), which typically is based on maximizing the log-likelihood. You can try the same approach here and check whether the log-likelihood increases with the log transform:

fit.raw <- glm(disease ~ pre_score, data=mydata, family=binomial)
fit.log <- glm(disease ~ log(1+pre_score), data=mydata, 
               family=binomial)
logLik(fit.raw)
logLik(fit.log)    
$\endgroup$
10
  • 1
    $\begingroup$ That procedure ignores model uncertainty and will result in inaccurate confidence intervals and p-values. As mentioned by @Noah above, fit a model that does not assume linearity and which is honest about the number of parameters in the model, e.g., use a regression spline. Details are in RMS. And don't normalize. $\endgroup$ Commented Dec 7, 2021 at 13:20
  • 1
    $\begingroup$ For regression splines you don't optimize on the knots. Put knots where data density is enough to estimate changes in shape if you don't have prior information. RMS course notes has details $\endgroup$ Commented Dec 7, 2021 at 16:29
  • 1
    $\begingroup$ @r-beginner "several orders of magnitude" is physicists lingo for several powers of ten. E.g. if the variable values range from 1 to 10000. Concerning logLik: larger is better. If you use spline regression, as suggested by Frank Harrel, you make no assumptions about the shape of the connection, but introduce a bunch of further fit parameters (the number of spline knots). $\endgroup$
    – cdalitz
    Commented Dec 7, 2021 at 18:27
  • 1
    $\begingroup$ Use a spline function if you do not already know from other data that the relationship is linear $\endgroup$ Commented Dec 7, 2021 at 18:30
  • 1
    $\begingroup$ I don’t see many linear relationships and use splines for just about anything. From a spline fit you can things like interquartile-range odds ratios as covered here in Chapter 5. And I don’t expect logs to fix non linearity. Allow for non linearity when you don’t know beforehand that relationships are linear, and when you have adequate sample size. $\endgroup$ Commented Jun 19 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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