5
$\begingroup$

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?

$\endgroup$
  • 4
    $\begingroup$ @JimG i I think you misunderstand. The reference level is included in the intercept by default. $\endgroup$ – Robert Long Aug 6 at 18:21
  • $\begingroup$ @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$. $\endgroup$ – bob Aug 6 at 18:32
  • $\begingroup$ Never mind. Thanks for the refresher. I was thinking in terms of multiple logistic regression $\endgroup$ – user293277 Aug 6 at 18:42
6
$\begingroup$

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"

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Would $\beta_2 - \beta_3 = 0$ be the contrast of interest for testing a significant difference between $x_i=B$ and $x_i = C$? $\endgroup$ – bob Aug 6 at 18:29
  • $\begingroup$ 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 $\endgroup$ – Robert Long Aug 6 at 18:32
  • $\begingroup$ 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? $\endgroup$ – bob Aug 6 at 18:39
  • 1
    $\begingroup$ 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. $\endgroup$ – bob Aug 7 at 4:45
  • $\begingroup$ @bob Ahh yes, that makes complete sense. I should have thought of that ! $\endgroup$ – Robert Long Aug 7 at 5:01
-1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ It tests the β coefficients, as described in the reference. $\endgroup$ – user293277 Aug 6 at 19:18
  • 4
    $\begingroup$ 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) ? $\endgroup$ – Robert Long Aug 6 at 20:38
  • 1
    $\begingroup$ Robert, the levels are encoded, they ARE different variables. $\endgroup$ – user255758 Aug 6 at 21:55
  • 2
    $\begingroup$ @Jason_93 the dummies are typically encoded behind the scenes $\endgroup$ – Robert Long Aug 7 at 1:31
  • 2
    $\begingroup$ Yes, code. Questions about software are off topic here, but it's perfectly normal for answers and comments to be illustrated with code. $\endgroup$ – Robert Long Aug 7 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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