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
  • 2
    $\begingroup$ What makes you think predictors have to be normally distributed? That is not an assumption of logistic regression. $\endgroup$
    – Noah
    Dec 7, 2021 at 5:06
  • $\begingroup$ So, am I checking the assumption (linearity between logit outcome vs predictor) correctly? $\endgroup$
    – R Beginner
    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
    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
    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 transfrom and try to guess appropriate parameters (e.g. Box-Cox for resopnse transfromation in lienar 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$
9
  • $\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$ Dec 7, 2021 at 13:20
  • $\begingroup$ @frank-harrel The idea behind my proposal of checking logLik was to introduce another (categorial) model parameter that chooses between log transform or not and to estimate this parameter via ML. Concerning spline regression, these introduce yet another set of arbitrary parameters, the knots. By which criterion do you optimize their number and position? $\endgroup$
    – cdalitz
    Dec 7, 2021 at 15:25
  • $\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$ Dec 7, 2021 at 16:29
  • $\begingroup$ @FrankHarrell So how would you know whether to use spline transformation or not? $\endgroup$
    – R Beginner
    Dec 7, 2021 at 18:20
  • $\begingroup$ @cdalitz Thank you for sharing. So I am a bit confused, how do I know if my predictor's range spans over several orders of magnitude? And how do you compare logLik(fit.raw) vs logLik(fit.log)? For example, how much difference between the two is needed to justify the use of log-transform one? $\endgroup$
    – R Beginner
    Dec 7, 2021 at 18:22

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.