# Is it possible to test for a linear trend when running a logistic regression?

I have a dichotomous DV and a single factor with three levels. Is it possible to test for a linear trend in the log-odds for each level of my factor?

• "Linear" as a function of what? This just doesn't make any sense when the domain is a dichotomous variable or an unordered factor, but those are all you say you have. – whuber Apr 29 '15 at 18:58
• I might be misunderstanding the purpose of testing for a linear trend, but my aim was to examine if the likelihood of success increases linearly when advancing from level 1 to 2 to 3 of my factor. – David Apr 29 '15 at 19:06
• The crucial information you have added in that comment--and which needs to be included in your question--is that the factor is ordered. You should pause, though, to contemplate what it could mean to be "linear" when the numerical values given to any ordered factor are almost completely arbitrary. For instance, it would be exactly the same thing to encode their values as $-1, \pi, 10^6$ instead of $1,2,3$. The only meaningful sense of "linear" that could survive such recoding would be to ask whether the two successive differences between the coefficients (of factors 1, 2, 3) are equal. – whuber Apr 29 '15 at 19:10
• @whuber, OK to edit my answer to include your comment (if I get around to it)? (Alternately, feel free to edit it yourself if you like) – Ben Bolker Apr 29 '15 at 19:19

In R, you could specify that the factor is an ordered factor (ordered), which will parameterize a three-level factor in terms of constant, linear, and quadratic terms ... the f.L parameter below essentially measures the linear trend.

set.seed(101)
d <- data.frame(y=rbinom(60,prob=0.5,size=1),
f=ordered(rep(1:3,each=20)))
summary(glm(y~f,data=d))
## ...
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.51667    0.06612   7.815  1.4e-10 ***
## f.L         -0.03536    0.11452  -0.309    0.759
## f.Q          0.02041    0.11452   0.178    0.859


The contr.sdif (successive differences) contrast from the MASS package might also be of interest.

• Thanks a lot! So if I were to simply run a logistic regression normally, and use an ordered factor as my predictor, the values associated with that factor in the output would be a test of the linear trend? As a follow up, is there any problem to including random subject and item factors? – David Apr 29 '15 at 19:32
• yes, with the caveats pointed out by @whuber above. There aren't any issues associated with random factors other than the usual ones (do your random effects specifications accord with your experimental design? do you have enough data to estimate the random effects reliably? ...) – Ben Bolker Apr 29 '15 at 21:15