# Logistic regression: categorical predictor vs. quantitative predictor

Why is it the case that when I run logistic regression with one categorical predictor, my regression is not significant whereas if I run the logistic regression with the same variable except it is continuous, the logistic regression automatically becomes significant?

That is not a necessary result, but it is certainly plausible. If you turn a quantitive predictor into a single categorical predictor you lose a lot of information; with the categorical predictor you only know whether an observation is below or above a certain threshold (e.g. the mean or median), while with a quantitative predictor you also know how much below or above the threshold that observation is. It is not unreasonable to suspect that if you feed your model more information (i.e. add your variable as a quantitative predictor), you will get more precise results.

One of the reasons why this is not necessarily true is that if you add a variable to a regression model as a quantitative variable you assume the effect of that variable to be linear. If the effect is strongly non-linear, then that may undo the advantage of adding quantitative variables. There are however easy ways to check whether that is the case (plots of residuals against predictors), and easy ways to solve it (adding your variables as splines or polynomials are probably the easiest solutions).

• This is a good answer but, given the increasingly common use of tools like generalized additive models, the comment "if you add a variable to a regression model as a quantitative variable you assume the effect of that variable to be linear" is not quite true. But, given that the OP was most likely talking about linear logistic regression, I think it's a good point to make. +1! – Macro Jul 25 '13 at 17:06

It depends what you mean by "the same variable except it is continuous". Binning a truly continuous variable into two or more categories loses information as described by @Maarten. If you're comparing analyses treating the predictor values, say ${1,2,3,4,5,6,7,8,9,10}$, as either continuous or categorical, in the latter case you fit nine parameters & the resulting drop in residual degrees of freedom can make the regression insignificant, especially in smaller data-sets.

As @MaartenBuis wrote, you lose a lot of information by categorizing. Lagakos wrote an excellent article a while ago about the loss of power when mismodeling explanatory variables. In table IV you can see how much information you loose by discretizing by different schemas. You may also want to have a look at Frank Harrell's list on the categorization subject.

While the residual plot against the continuous predictor is a simple approach to checking the linearity assumption I find that the ANOVA is really convenient here. The rms-package in R allows you effortlessly to test the linearity, straight from the man-page for the lrm()-function:

#Fit a logistic model containing predictors age, blood.pressure, sex
#and cholesterol, with age fitted with a smooth 5-knot restricted cubic
#spline function and a different shape of the age relationship for males
#and females.  As an intermediate step, predict mean cholesterol from
#age using a proportional odds ordinal logistic model
#
n <- 1000    # define sample size
set.seed(17) # so can reproduce the results
age            <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
cholesterol    <- rnorm(n, 200, 25)
sex            <- factor(sample(c('female','male'), n,TRUE))
label(age)            <- 'Age'      # label is in Hmisc
label(cholesterol)    <- 'Total Cholesterol'
label(blood.pressure) <- 'Systolic Blood Pressure'
label(sex)            <- 'Sex'
units(cholesterol)    <- 'mg/dl'   # uses units.default in Hmisc
units(blood.pressure) <- 'mmHg'

# Specify population model for log odds that Y=1
L <- .4*(sex=='male') + .045*(age-50) +
(log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
# Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
y <- ifelse(runif(n) < plogis(L), 1, 0)
cholesterol[1:3] <- NA   # 3 missings, at random

ddist <- datadist(age, blood.pressure, cholesterol, sex)

fit <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
x=TRUE, y=TRUE)
#      x=TRUE, y=TRUE allows use of resid(), which.influence below
#      could define d <- datadist(fit) after lrm(), but data distribution
#      summary would not be stored with fit, so later uses of Predict
#      d or specifying all variable values to summary, Predict, nomogram
anova(fit)


Gives you the ANOVA output:

                Wald Statistics          Response: y

Factor                                           Chi-Square d.f. P
blood.pressure                                    0.23       1   0.6315
sex  (Factor+Higher Order Factors)               38.17       5   <.0001
All Interactions                                26.25       4   <.0001
age  (Factor+Higher Order Factors)               30.48       2   <.0001
All Interactions                                 3.68       1   0.0552
cholesterol  (Factor+Higher Order Factors)       24.15       6   0.0005
All Interactions                                22.74       3   <.0001
Nonlinear (Factor+Higher Order Factors)          5.11       4   0.2759
sex * age  (Factor+Higher Order Factors)          3.68       1   0.0552
sex * cholesterol  (Factor+Higher Order Factors) 22.74       3   <.0001
Nonlinear                                        4.54       2   0.1031
Nonlinear Interaction : f(A,B) vs. AB            4.54       2   0.1031
TOTAL NONLINEAR                                   5.11       4   0.2759
TOTAL INTERACTION                                26.25       4   <.0001
TOTAL NONLINEAR + INTERACTION                    26.98       6   0.0001
TOTAL                                            62.10      10   <.0001


As you see there is no strong support for non-linearity in this example. I find it surprisingly easy to test very complicated models in this way. Hope this helps.