# Contrast to test significant interaction - why not include main effect?

Given a data set with a continuous outcome variable $Y$ and two nominal IV $X_1$ and $X_2$ which have 4 (A,B,C,D) and 3 (E,F,G) levels respectively, we can assign the first level of each as a reference level and create dummy or indicator variables:

$X_1: X_1B$ , $X_1C$ , $X_1D$

$X_2: X_2F$ , $X_2G$

An ordinary linear regression of $Y$ on these variables can be written as (including the interaction terms):

$Y = \beta_0 + \beta_1X_1B + \beta_2X_1C + \beta_3X_1D + \beta_4X_2F + \beta_5X_2G + \beta_6X_1B*X_2F + \beta_7X_1B*X_2G + \beta_8X_1C*X_2F + \beta_9X_1C*X_2G + \beta_{10}X_1D*X_2F + \beta_{11}X_1D*X_2G + e$

where $e$~$N(0,\sigma{^2})$, the error is normally distributed with constant variance.

If we wished to test the significance of the interactions $X_1$ x $X_2$ to determine if, say, the effect of $X_1$ on $Y$ differs at different levels of $X_2$, one method would be to use a contrast by constructing the appropriate matrix $L$ to multiply against the regression beta vector with the null hypothesis $L\beta=0$. See for example here.

My understanding is that we would be (with the example above) using null hypothesis involving just the interaction terms:

$Ho:$ $\beta_{6}=0$ and $\beta_{7}=0$ and $\beta_{8}=0$ and $\beta_{9}=0$ and $\beta_{10}=0$ and $\beta_{11}=0$

but, why wouldn't testing $\beta_{1}=0$ and $\beta_{2}=0$ be included because these are jointly interpreted as the effect of $X_1$ on $Y$ when $X_2=$level E (the reference level for $X_2$)?

If the interpretation of $\beta_6$ through $\beta_{11}$ = 0 is the following:

The effect of $X_1$ = B on Y is not different when $X_2$ = F

The effect of $X_1$ = B on Y is not different when $X_2$ = G

The effect of $X_1$ = C on Y is not different when $X_2$ = F

The effect of $X_1$ = C on Y is not different when $X_2$ = G

The effect of $X_1$ = D on Y is not different when $X_2$ = F

The effect of $X_1$ = D on Y is not different when $X_2$ = G

Isnt it possible that "The effect of $X_1$ = A on Y IS different when $X_2$ = E" and that this would suggest an interaction? I am missing the obvious I'm sure but it has not quite clicked for me. I am missing how the 6 statements above for $\beta_6$ through $\beta_{11}$ = 0 is equivalent to your equation 1.

• Comment on edit: this should be changed to be consistent with my equation 1 below. The root of your misunderstanding is directly related to the difference between my statement and yours. The interpretation is intricate enough that I don't think stating it in this form is very useful, but it would be something like: The difference between the effect of $X_1=B$ minus the effect of $X_1=A$ remains the same regardless of the level of $X_2$'' i.e. the difference is the same whether $X_2$ equals $E$, $F$, or $G$, etc for each line. – ahfoss Jan 7 '14 at 5:10
• Also, please see below where I corrected my mistake. – ahfoss Jan 7 '14 at 5:25

This is an interesting question, and actually quite subtle. It gets at the core of the definition of interactions, as well as the assumptions underlying dummy coding of categorical variables.

OP's question is that, when we are testing for interactions between the levels as given above, why do we (seemingly!) not bother to take into account interactions between one variable and the other variable's reference level?

The short answer is that we actually are taking these into account, as I'll explain here. First, to simplify subsequent notation, let $Y_{AE}$ denote the random variable $Y|\{X_1=A\} \cap \{X_2=E\}$, that is, $Y$ conditional on observing levels $A$ and $E$ in variables $X_1$ and $X_2$, respectively.

Now, recall that if we claim that there is no interaction between $X_1$ and $X_2$, this is equivalent to asserting that

$$E[Y_{AE}]-E[Y_{BE}] = E[Y_{AF}]-E[Y_{BF}] = E[Y_{AG}]-E[Y_{BG}] \qquad (Eq. 1)$$

that is, the expected difference between $Y|X_1=A$ and $Y|X_1=B$ is unrelated to the level of $X_2$, as long as $X_2$ is held constant. Similarly, no interaction means that

$$E[Y_{AE}]-E[Y_{AF}] = \cdots = E[Y_{DE}]-E[Y_{DF}].$$

Now, OP correctly states that given our choice of reference levels $A$ and $E$, the definition of $\beta_1$ is the expected difference between $Y$ when $X_1=B$ versus $X_1=A$, given that $X_2$ is held constant at $E$. In other words,

$$\beta_1 = E[Y_{AE}] - E[Y_{BE}],$$

but if there is no interaction between $X_1$ and $X_2$, it follows immediately from equation 1 above that $$\beta_1 = E[Y_{AE}]-E[Y_{BE}] = E[Y_{AF}]-E[Y_{BF}] = E[Y_{AG}]-E[Y_{BG}]$$

In other words, if there is no interaction, then $\beta_1$ is sufficient to explain the differences in $Y$ based on levels of $X_1$ when $X_2$ is held constant. This is why the test for an interaction involves leaving $\beta_1$ in the model and testing whether the interaction terms are zero.

The full answer to your question involves a simultaneous derivation for $\beta_1$ through $\beta_5$, but from this example you hopefully get the idea of what's going on.

• I feel like this is in the right direction but what I dont quite see yet is it appears you have expressed equation 1 as the definition of an interaction but then testing that $\beta_6$ through $\beta_{11}$ = 0 is not the same as equation 1 is it? What if indeed $\beta_6$ through $\beta_{11}$ = 0 BUT $E[Y_{AE}] - E[Y_{BE}]$ not equal to 0? – B_Miner Jan 1 '14 at 23:00
• In other words, isn't the linear contrast involving $\beta_6$ through $\beta_11$ just a subset of equation 1? Or I wonder if the fact that $X_2$ is dummy coded make a difference? – B_Miner Jan 1 '14 at 23:05
• I think the important distinction here is that "no interaction" means $E[Y_{AZ}] - E[Y_{BZ}]$ is the $same$ for all $Z$. The fact that $E[Y_{AZ}] - E[Y_{BZ}]$ is not zero is unrelated to an interaction, i.e. it can be due to a main effect of $X_1$. Equation 1 is indeed equivalent to asserting that $\beta_6 = \cdots = \beta_{11}=0$ – ahfoss Jan 2 '14 at 18:18
• ....still waiting for the light to come on :) How again can equation 1 be equivalent to $\beta_6$ through $\beta_{11}$? Maybe I don't understand interactions like I should. Is testing $\beta_6$=0 not saying that the effect of $X_1$ on $Y$ is not different when $X_2$ = F versus when $X_2$ <> F? I assumed it was, which is why $\beta_6$ through $\beta_{11}$ =0 seemed to be missing this test for the reference level. – B_Miner Jan 2 '14 at 20:48
• Oops, my mistake. Revised statement: Claiming that $\beta_6=0$ is saying that the difference between the effect of "$X_1=B$" and the effect of "$X_1=A$" is unchanged when $X_2=F$ vs $X_2=E$. – ahfoss Jan 7 '14 at 5:24

A tiny little imprecision in your formulation might be the main reason for your confusion:

"[...] to determine, if, say, the effect of X1 on Y differs at different levels of X2"

because X1 has more than two levels and thus more than one (main) effect on the mean of Y. Similarly, X2 has two such (main) effects. These effects are represented by the parameters $\beta_1, \dots, \beta_5$. Variations of these effects across levels of the other factors are represented by the parameters $\beta_6, \dots, \beta_{11}$.
Now, if there are no interactions, i.e. $\beta_6=\dots=\beta_{11}=0$, then we know that the effects of X1 may vary (e.g. level B has higher average Y than level A given X2) but none of these effects/differences depend on the level of X2 (i.e., the effects of X1 and X2 are additive). If you would further require $\beta_1 = \beta_2 = \beta_3 = 0$, this would thus mean that the average value of Y given X2 does not vary with X1 which is unrelated to the question of not having an interaction.
• This is a clear and correct post, but the OP seems to already understand this (I think). Rather, his/her question is asking $why$ this is correct. – ahfoss Jan 1 '14 at 18:43