# Hypothesis testing for logistic regression with categorical predictor

I want to perform logistic regression in R, where one of my predictors, $$x_i$$ is categorical (takes on the values A, B, and C). A is the reference category. The model is set up as follows:

$$logit(P(Y_i = 1)) = \beta_0 + \beta_1I(x_i=B) + \beta_2I(x_i=C)$$

I want do a hypothesis test for whether the percentage chance of success is the same given $$x_i = A$$, $$x_i = B$$, or $$x_i = C$$. For example, to test if there is a significant difference in probability of success between $$x_i = A$$ and $$x_i = B$$, I can test the null hypothesis, $$H_0: \beta_1 = 0$$. To test if there is a significant difference in probability of success between $$x_i = A$$ and $$x_i = C$$, I can test the null hypothesis, $$H_0: \beta_2 = 0$$.

But how do I test whether there is a significant difference between $$x_i = B$$ and $$x_i = C$$? My confusion is that $$A$$ is the reference category, so I don't know how to directly test the hypothesis.

UPDATE: For the difference between B and C, would I be testing $$H_0: \beta_2 - \beta_3 = 0$$? And if so, how could this be done from the logistic regression output in R?

• @JimG i I think you misunderstand. The reference level is included in the intercept by default. Aug 6, 2020 at 18:21
• @JimG I think you are missing the issue. For regression with categorical predictors, the predictors are turned into dummy variables (one for each level of the predictor), with one of the levels used by default as the reference level. I am still using $x_i=A$ in my logistic regression. Predictions for $x_i=A$ just correspond to the intercept, $\beta_0$.
– bob
Aug 6, 2020 at 18:32
• Never mind. Thanks for the refresher. I was thinking in terms of multiple logistic regression
– user293277
Aug 6, 2020 at 18:42

In R you can use glht (generalized linear hypothesis test) command in the multcomp package to define the contrasts of interest and test them, though I would advise against much reliance on p value "significance"

• Would $\beta_2 - \beta_3 = 0$ be the contrast of interest for testing a significant difference between $x_i=B$ and $x_i = C$?
– bob
Aug 6, 2020 at 18:29
• Yes that's right. I would personally be more interested in the differences in estimates but if you seek p values that's one way to do it Aug 6, 2020 at 18:32
• After using glht (thanks for that suggestion, btw), running summary(glht(model_object, c("varB = 0", "varC = 0"))), I'm seeing different p-values than those same variables have in the output of the logistic regression. That doesn't make sense to me?
– bob
Aug 6, 2020 at 18:39
• For reference for anyone reading this, glht adjusts for multiple tests by default. This was the reason for the p-values not matching up. If you only do one contrast with each call to glht(), the corresponding values will match up with the original regression output.
– bob
Aug 7, 2020 at 4:45
• @bob Ahh yes, that makes complete sense. I should have thought of that ! Aug 7, 2020 at 5:01

Use the likelihood ratio test (LRT) to compare the different β's as described here: https://courses.washington.edu/b515/l13.pdf
pp. 20-24. And if you don't follow it, start from page 1.

• It tests the β coefficients, as described in the reference.
– user293277
Aug 6, 2020 at 19:18
• so if the model is Y ~X1 where X1 has levels A, B and C, what is the code to perform an LRT for the contrast between each of the levels of X1 (A vs B, B vs C and A vs C) ? Aug 6, 2020 at 20:38
• Robert, the levels are encoded, they ARE different variables.
– user255758
Aug 6, 2020 at 21:55
• @Jason_93 the dummies are typically encoded behind the scenes Aug 7, 2020 at 1:31
• Yes, code. Questions about software are off topic here, but it's perfectly normal for answers and comments to be illustrated with code. Aug 7, 2020 at 1:34