Say for the sake of the argument I have a 2x2x2 ANOVA on factors A, B, and C with levels (A1, A2), (B1, B2), and (C1, C2). Also, the design is fully balanced.

I have the following 8 groupings as a result:

  1. (A1, B1, C1) = T1
  2. (A1, B1, C2) = T2
  3. (A1, B2, C1) = T3
  4. (A1, B2, C2) = T4
  5. (A2, B1, C1) = T5
  6. (A2, B1, C2) = T6
  7. (A2, B2, C1) = T7
  8. (A2, B2, C2) = T8

The Main Effect of A is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_2} + \bar{X}_{T_3} + \bar{X}_{T_4}) - \frac{1}{4}*(\bar{X}_{T_5} + \bar{X}_{T_6} + \bar{X}_{T_7} + \bar{X}_{T_8})$

The Main Effect of B is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_2} + \bar{X}_{T_5} + \bar{X}_{T_6}) - \frac{1}{4}*(\bar{X}_{T_3} + \bar{X}_{T_4} + \bar{X}_{T_7} + \bar{X}_{T_8})$

The Main Effect of C is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_3} + \bar{X}_{T_5} + \bar{X}_{T_7}) - \frac{1}{4}*(\bar{X}_{T_2} + \bar{X}_{T_4} + \bar{X}_{T_6} + \bar{X}_{T_8})$

The Interaction Effect of A and B is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_2} + \bar{X}_{T_7} + \bar{X}_{T_8}) - \frac{1}{4}*(\bar{X}_{T_3} + \bar{X}_{T_4} + \bar{X}_{T_5} + \bar{X}_{T_6})$

The Interaction Effect of A and C is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_3} + \bar{X}_{T_6} + \bar{X}_{T_8}) - \frac{1}{4}*(\bar{X}_{T_2} + \bar{X}_{T_4} + \bar{X}_{T_5} + \bar{X}_{T_7})$

The Interaction Effect of B and C is

$\frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_5} + \bar{X}_{T_4} + \bar{X}_{T_8}) - \frac{1}{4}*(\bar{X}_{T_2} + \bar{X}_{T_6} + \bar{X}_{T_3} + \bar{X}_{T_7})$

I got these "Global" tests we'll call them by basically taking the main effect and interaction term for a two-way ANOVA (say, just on factors A and B) and then adding two extra terms to each to account for the added levels from the C factor.

What I am not sure about is constructing the full interaction term. What would this look like? I think it would look something like subtracting the main effects of A and B from each other while accounting for the varying levels in C but I'm not exactly sure what that would look like.

Thank you for taking the time to read all this and consider its contents. To the best of my knowledge the information presented above regarding the expression of the main effects and interaction effects is correct but please feel free to correct me if I'm wrong. I'm just here to learn. Thanks again!

  • $\begingroup$ Hi @EdM. What I mean by main effect is best given an example. Say I have a 2x2 ANOVA with factors A and B with levels of (A1, A2) and (B1, B2). What I mean by the main effect of A here is that it is testing for a difference in means among the levels in A. So the null hypothesis here would be $\mu_A_1 = \mu_A_2$ and the alternative being nonequal. If there were three levels to A instead of 2 it'd just be that there is a difference among the three levels. Mutatis mutandis for the main effect of B. Does this help? It'd be nice if the explanation could be under these terms but I can accept others. $\endgroup$ Jul 7, 2023 at 20:33

2 Answers 2


The general convention for a 2 factor design is the designate the low factor as -1 and the high factor as +1.
To determine the interaction term for ABC multiple the 1 and -1 together and the sign of the result is the which side that result is.

$\frac{1}{4}*(\bar{X}_{T_2} + \bar{X}_{T_3} + \bar{X}_{T_5} + \bar{X}_{T_8}) - \frac{1}{4}*(\bar{X}_{T_1} + \bar{X}_{T_4} + \bar{X}_{T_6} + \bar{X}_{T_7})$

For example Run 2 (A1, B1, C2) = T2: would equal $-1 * -1 * 1 = 1$ thus it goes on the left side. This assumes your terminology is 2 being the high side.


Your terminology isn't quite standard, and might lead to confusion in more complicated scenarios. For example, Winer's "Statistical Principles in Experimental Design" (2nd edition, McGraw-Hill, 1971), defines "main effects" for each level of a categorical variable, expressed as the associated difference from the grand mean. What you describe are called "differential main effects" in that text, the difference between two individual "main effects" within a categorical variable (p. 316).

With only 2 levels of a categorical predictor A, a test of the "differential main effect" between its two levels is equivalent to what you seek as a test of the overall "main effect" of A. With more levels, however, you need to combine all the "main effects" or "differential main effects" to evaluate the overall significance of A.

I would get lost if I tried to present the interaction terms in the way that you show. Similar to the handling of "main effects," the classic treatment in the Winer text defines interaction effects for each combination of levels of the interacting predictors, and then goes on to define "differential interaction effects" and "simple interaction effects," which I don't find very simple.

There are several ways to code categorical predictors for a model. Several are explained on this page. The comparisons you display are close to what you might get with deviation coding. Also explained on that page, all codings lead to the same model. The model-coefficient values will differ depending on coding, but all models will return the same predictions and the same inference about the predictors.

I find it simplest to think about interactions when the categorical predictors are dummy coded (also called "treatment coded"), the default in R. One of its $k$ levels is chosen as the reference, and the categorical predictor is then described as a set of ($k-1$) values of "0" or "1," with a "1" representing which (if any) non-reference level is in place for an observation. Then your 3-way ANOVA (with outcome y and dummy-coded binary predictors A, B and C) can be represented as the following linear model with 8 regression coefficients ($\beta$s):

y ~ $\beta_0$ + $\beta_a$ A + $\beta_b$ B + $\beta_c$ C + $\beta_{ab}$ AB + $\beta_{ac}$ AC + $\beta_{bc}$ BC + $\beta_{abc}$ ABC

Let's say that A1, B1, and C1 are the reference levels. Then each of A, B, and C in the above formula has a value of 1 only when the corresponding categorical predictor is not at its reference level. In an interaction (product) term, if any predictor in the term is at its reference, that whole term is thus 0.

In that coding, each coefficient has a simple interpretation: a difference from what would be predicted from lower-level coefficients. In your terminology with a completely balanced design:

$\beta_0$, the intercept, is $\bar{X}_{T_1}$: all predictors at their reference levels.

$\beta_a$ is $\bar{X}_{T_5}-\bar{X}_{T_1}$, the difference from the intercept associated with non-reference A (dummy-coded value of 1), with the other predictors maintained at reference (dummy-coded values of 0). Similarly for the other single-predictor coefficients: $\beta_b$ is $\bar{X}_{T_3}-\bar{X}_{T_1}$ (A and C at reference) and $\beta_c$ is $\bar{X}_{T_2}-\bar{X}_{T_1}$ (A and B at reference).

$\beta_{ab}$ is the extra difference from what would be predicted based solely on those individual coefficients, with C maintained at reference: $\bar{X}_{T_7}-\beta_0-\beta_a-\beta_b$ Substituting the above gives $$\beta_{ab}=\bar{X}_{T_7} -(\bar{X}_{T_1})-(\bar{X}_{T_5}-\bar{X}_{T_1})-(\bar{X}_{T_3}-\bar{X}_{T_1}) \\ = \bar{X}_{T_7} - \bar{X}_{T_5}-\bar{X}_{T_3}+\bar{X}_{T_1}.$$

Similarly, $\beta_{ac}$ is $\bar{X}_{T_6} - \bar{X}_{T_5}-\bar{X}_{T_2}+\bar{X}_{T_1} $. $\beta_{bc}$ is $\bar{X}_{T_4} - \bar{X}_{T_3}-\bar{X}_{T_2}+\bar{X}_{T_1}$.

Finally, the 3-way interaction coefficient is the difference between $\bar{X}_{T_8}$ (mean outcome with all predictors at non-reference) and what you would have predicted based on all the lower-level coefficients:

$$\beta_{abc} = \bar{X}_{T_8} - \beta_0 - \beta_a -\beta_b - \beta_{ab} - \beta_{ac}-\beta_{bc}$$

Substituting gives:

$$\beta_{abc} = \bar{X}_{T_8} - \bar{X}_{T_7} + \bar{X}_{T_5} - \bar{X}_{T_6} + \bar{X}_{T_2} - \bar{X}_{T_4} + \bar{X}_{T_3} .$$

Those coefficients based on dummy coding are much easier to associate with cell means than what we might have gotten if I tried to carry through your formulation. More generally, in situations with unbalanced designs or generalized linear models, the cell means used above would instead be the modeled estimates for the indicated (combinations of) predictors.

The downside of dummy coding is that there is then a temptation to consider, for example, $\beta_a$ as the "main effect" coefficient for A. That's incorrect: it only represents the difference from the intercept associated with the shift from A1 -> A2 when B and C are at reference levels (B1,C1). Even the 2-way interaction coefficients are only for the situation when the predictor omitted from the interaction is at its reference.

Tools for post-modeling calculations allow evaluation of overall associations of predictors with outcome. For example, with a balanced design you can perform a linear regression model with dummy-coded predictors and use the basic R anova() function on the model to get an analysis of variance table.

Final note:

I'm pretty sure that if I had managed to work through the 3-way interaction coefficient in the way you requested, I would have come up with the same final result. An interaction in a factorial design is the extent to which the result for a treatment combination cannot be predicted from the corresponding lower-level "main" and "interaction" effects. Although I worked this through with dummy coding, the outcome with all 3 predictors at non-reference levels is still $\bar{X}_{T_8}$ and the remaining terms in the formula for $\beta_{abc}$ come from what would be predicted based on the lower-level "main" and "interaction"effects. The net combination should add up the same however the predictors were coded.

  • $\begingroup$ Thanks for writing all this out. This was very informative and helpful! $\endgroup$ Jul 10, 2023 at 15:51
  • $\begingroup$ @MatthewGraham I would suggest double-checking what I have written as the 3-way interaction coefficient. I can't necessarily rule out having made some mistake when doing all of the substitutions. If you find an error let me know, so that future readers of this page won't be misled. $\endgroup$
    – EdM
    Jul 10, 2023 at 16:09

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.