I'm new to stats and I'm not sure how to interpret the output of my glm model.

I have two fixed factors, task which has two levels (task A and task B), and condition which has four levels (conditions a, b, c, and d). Both factors are sum-coded (because I don't have a clear baseline/reference level).

> contrasts(data$condition_c) <- contr.sum(4)
> contrasts(data$condition_c)
  [,1] [,2] [,3]
a    1    0    0
b    0    1    0
c    0    0    1
d   -1   -1   -1
> contrasts(data$task_c) <- contr.sum(2)
> contrasts(data$task_c)
taskA     1
taskB    -1

My dependent variable is binary so I'm using logistic regression. The model output looks like this:

glm(formula = DV ~ task_c * condition_c, family = "binomial", 
    data = data)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.3678  -1.0629   0.3536   0.9301   1.8400  

                     Estimate Std. Error z value             Pr(>|z|)    
(Intercept)           0.26432    0.07572   3.491             0.000482 ***
task_c1               0.20972    0.07572   2.770             0.005611 ** 
condition_c1         -0.22247    0.11058  -2.012             0.044237 *  
condition_c2         -0.09502    0.11226  -0.846             0.397350    
condition_c3          1.98070    0.16615  11.921 < 0.0000000000000002 ***
task_c1:condition_c1 -0.22080    0.11058  -1.997             0.045856 *  
task_c1:condition_c2  0.23499    0.11226   2.093             0.036332 *  
task_c1:condition_c3  0.28610    0.16615   1.722             0.085087 . 

Can anyone help me understand the main effect of condition and the interaction between task and condition? Thanks!

Am I correct to say that for the main effect of condition, the model summary says that while conditions a and c are significantly different from the grand mean, condition b isn't? What about condition d? And I'm completely lost for the interaction.

  • $\begingroup$ Welcome to Cross Validated! With interactions you shouldn't rely solely on the reports of "significance" of individual model coefficients; you need to use post-modeling tools (like those in the R car or emmeans packages) to evaluate your hypotheses reliably. I find treatment contrasts easier to explain than sum contrasts; the model is fundamentally the same regardless of how the predictors are coded. It doesn't really matter whether or not you have clear baseline/reference levels for your categorical predictors; you can still just choose 1 as reference arbitrarily (or let R do it for you). $\endgroup$
    – EdM
    Dec 4, 2023 at 18:30

1 Answer 1


Start with the intercept. As you have chosen sum/deviation coding, that is a type of average outcome over all levels of the predictors: "the mean of means of the dependent variable at each level of the categorical variable," as this UCLA web page puts it. You have two such categorical variables, so the intercept is the estimate at the average over all levels of both of them. With logistic regression, this is in a log-odds scale.

The main effect of condition

With an interaction between task and condition, the association of one with outcome depends on the value of the other. With sum/deviation contrasts, the "main effect" coefficient for any level of one of those 2 predictors is the associated difference (here, a log-odds difference) from the intercept ("grand-mean" outcome), evaluated at the "grand mean" over the levels of the other. Is that really of interest by itself, without considering the significant interaction between task and condition?

What might be of more interest is the overall association between condition and outcome, taking all of its levels and interactions into account, sometimes called a "chunk test." A UCLA web page on logistic regression illustrates that with the wald.test() function of the R aod package. If you work within the rms package (highly recommended if you are going to do a lot of regression analysis), its anova() function (unlike that of base R statistics) provides that type of test.

What about condition d?

With 4 levels of condition you only get 3 coefficients. The intercept ("grand mean") includes the effect associated with the 4th level. If you know the "grand mean" over all 4 levels and the differences of the other 3 levels from the grand mean (their individual coefficients under sum/deviation coding), it's simple algebra to get the point estimate of the 4th level, condition d. For confidence intervals around that estimate, however, you need to know the variance-covariance matrix of the coefficient estimates. That's not included in this model summary, although it's included in the model and accessible via the vcov() function.

Post-modeling tools like those provided by the emmeans package can perform such calculations for you. These tools take the choice of predictor coding into account, so that you can typically just use the default R dummy/treatment coding for categorical predictors.*

The interaction between task and condition

Two-way interaction coefficients represent additional differences beyond what you would otherwise predict, based on the intercept and the individual coefficients for those specific levels of the predictors. I find it easier to think through those interactions with dummy/treatment coding. You can get outcome predictions for any combinations of predictor values, taking all coefficients into account, with post-modeling tools like those in the emmeans and rms packages.

*The only situation I can think of where categorical-variable coding matters is when you perform so-called "Type III ANOVA" tests on a model; dummy/treatment contrasts don't work then. But you probably shouldn't be doing those tests anyway; see the help page for the Anova() function in the R car package.


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.