In statistics, an interaction occurs when the effect of one variable depends on the level or value of another. Interactions are most easily recognised through graphs, where parallel lines indicate no interaction and non-parallel or crossing lines indicate that one effect is being modified by another. They can arise between two or more factors, between continuous variables, or between factors and co-variates. While interaction terms are straightforward to define mathematically, they are often hardest to interpret from tables alone, which is why well-designed figures are usually the most reliable way to understand what an interaction means in practice.
What is an Interaction in Statistics?
Along with several others, ‘interaction’ is a word re-purposed from general English to have a particular meaning in the field of statistics. The meaning in standard English overlaps only a little with the statistical meaning, which can lead to confusion. In statistics, ‘interaction’ relates to the effect of one variable (factor or co-variate) being modified by changes in another variable. That is, the interacting variables are not acting independently. Usually, an important interaction is identified by assessing it via a statistical test within a formal analysis. If an important interaction is ignored, then any interpretation of the analysis results can be biassed or misleading. Thus, interactions need to be explored.
An interaction is easiest to understand through graphs, as in Figure 1. Here, there are two factors—Insecticide (1 or 2) and Application Form (Liquid, Pellet) —giving four treatment combinations. In panel (a), the lines are close to parallel, with the small increase in response between Liquid and Pellet being almost the same for both insecticides. In panel (b) however, the change in response between Liquid and Pellet is much larger for Insecticide 2 than for Insecticide 1. In panel c, there is a cross-over interaction, with the change between Liquid and Pellet being an increase for Insecticide 1 and a decrease for Insecticide 2. In summary, parallelism implies there is no interaction, and lack of parallelism implies an interaction.

Figure 1: Interaction and non-interaction in a 2×2 factorial treatment structure.
Parallel lines indicate no interaction, while non-parallel or crossing lines show that the effect of application form depends on the insecticide.
Note: In figure 1, lines have been drawn connecting Liquid and Pellet for each Insecticide. This substantially aids interpretation and is particularly helpful when interpreting an interaction. Some people argue that lines imply a response relationship, so should not be drawn when the variable on the x-axis is categorical and not ordered. In practice, however, this misunderstanding is unlikely for most readers, and the visual clarity gained by connecting the points usually outweighs this concern. Figure 2 shows how lines and colours improve interpretation.

Figure 2: Effect of lines and colour on interpreting an interaction.
Connecting treatment means and using colour makes the interaction easier to see, especially
when differences are small.
For more tips on creating better graphs, see Presenting Results with Integrity: Designing a Good Graph.
Formal Definition of an Interaction
In an analysis of data where a factorial treatment structure is used (the blog on Treatment structures discusses this in more detail), then the underlying model includes main effects and interaction effects. A main effect for a factor is essentially the factor means over all of the data minus a baseline. For Genstat’s ANOVA, the baseline is the grand mean. A two-way interaction effect is the extra change for a particular combination of the levels of the two factors over the baseline, plus the effects for each of the factors. The baseline and formulation of these effects varies between statistical packages and techniques: in Genstat, in contrast to ANOVA, which uses the grand mean as a baseline, standard regression uses the mean for the combination comprising level one of all factors as a baseline. For ANOVA in Genstat, the formulation for a replicated factorial treatment structure (A*B; two-way no blocks) is:
yijk is the observed response for factor A at level i and factor B at level j in replicate k
μ is the grand mean
Ai is the main effect of factor A at level i, defined as the difference between the mean at level A=i and the grand mean
Bj is the main effect of factor B at level j, defined similarly as the difference between the mean at level B=j and the grand mean
ABij is the interaction effect for the combination of factor A level i and factor B level j, defined as the difference between the mean for the treatment combination A=i and B=j and the grand mean plus the two main effects
εijk is the residual
Table 1 shows a numerical example illustrating the calculations. It uses the data in the Genstat example file ‘Ratfactorial.gsh’. In this trial, there were two treatment factors: Diet (Beef, Cereal or Pork) each at two protein Amounts (High, Low). Here, the blocking factor is ignored. The calculations for effects of just one treatment, Beef High, are given in Table 1.

Interactions with three or more variablesTreatment structures can easily be extended to use 3 or more variables. For example, with three treatment factors (A, B and C) the treatment structure can be written as:
A*B*C = A + B + C + A.B + A.C + B.C + A.B.C
That is, for three variables, there are three two-way interactions plus one three-way interaction. It can be difficult to interpret the results from an analysis with three treatment factors: you might get both A.C and A.B being significant in an analysis without also having the other two-way interaction B.C nor the three-way A.B.C significant. Furthermore, interpretation of a three-way interaction can be challenging. However, it is usually more straightforward if one or more of the three factors has just two levels, as in Figure 3:

Figure 3: Exploring interactions in a three-factor treatment structure.
The response for one treatment (red) differs strongly from the others for the ‘Fast’ set, driving the interactions.
When you have more than three variables in the treatment model, interpretation becomes increasingly more difficult as the number of variables increases. This is a key reason why higher order interactions are often pooled into the residual term. In Genstat, the ANOVA command (and others) defaults to doing this. This restriction is not applied if the analysis is carried out via menus.
Interactions Including Co-Variates
Above, variables in treatment terms have been called ‘variables’. This is because for general methods like regression or REML, the variables in the term can be variates/co-variates (continuous, quantitative) not just factors (categorical). For example, in a regression analysis, you might have Time starved (continuous) and factor Motion (Walk, Run, Jump), with 12 animals per Motion, fitting the model to amount Eaten:

This gives the outline accumulated ANOVA as in Table 2 Outline tables are useful for checking that the model entered is as required, and also that the factors have been entered correctly. In addition, the residual degrees of freedom relates to the ‘power’ of a trial (higher is better; very large (>30) is a waste of resources).
Table 2: Outline ANOVA table (‘dummy ANOVA’) for a factor and a continuous variate, including an interaction between them.

(Note that the model with no interaction Motion+Time, can be fitted using analysis of covariance (ANCOVA))
As above, interpretation is generally easiest via a figure (e.g. Figure 4). This shows how the linear relationship between Time starved and amount Eaten varies both in the intercept (Motion main effect) and slope (interaction between Motion and Time).

Figure 4: Interaction between a factor and a continuous co-variate.
The slope between Time starved and amount Eaten differs across Motion levels, indicating an interaction. Plotting the data for a trial with a factor by co-variate treatment structure along with the fitted regression lines. There is clearly an interaction between Time starved and the Motion factor, with differing slopes for each of the Motion factor levels.
If a second continuous variable Age is included, the model can be fitted as a ’multiple linear regression with groups’. Note that the Explanatory variates (X) box includes both co-variates along with the * symbol to get the main effects and all interactions:

This gives the dummy accumulated ANOVA table as in Table 3:
Table 3: Dummy ANOVA table for a factor and two continuous variates, including all interactions.

Including an interaction between two variates is essentially equivalent to fitting a surface (flat, linear). If a factor is also included, then a separate surface is fitted for each of the levels of the factor. The surfaces will be parallel if interactions between the variates and the factor are not included. In general, interactions between two or more variates or factors can be difficult to understand!
Special Constructions:
Some models look like they contain interactions but actually do not. For example, the explanatory model (code with the FIT command) might be:
ConVsTrt/AÂ
which equals
ConVsTrt + ConVsTrt.A
Here, ‘ConVsTrt’ is a two-level factor, ‘Nil’ for a control and ‘Treated’. If A is a factor with levels Nil, a1, a2, and factor ConVsTrt is set up to match Nil for A and ‘Treated’ where A is a1 or a2, then the above model compares Nil with the mean of a1 and a2, and then nested within that compares a1 with a2. The term ConVsTrt.A is essentially a main effect for A.
This approach can be extended to include more treatment factors, taking care to make sure the nesting within the Nil and other levels for A and B is correct. With two treatment factors, A and B, the following is a ‘control plus factorial’ treatment structure (see Treatment structures).
ConVsTrt/(A*B) = ConVsTrt + ConVsTrt.A + ConVsTrt.B + ConVsTrt.A.B
Here, ConVsTrt.A.B is essentially the A by B interaction. The correspondence between the factors levels for the three factors is given in Table 4.
Table 4: Relationship between three factors in a control plus factorial trial.

Other extensions are to have more than one level of nesting, or else extend ConVsTrt to separate the treatments into more than two groups:
ConVsTrt/G1vsG2/(G1a*G1b+G2c*G2d)
ConVsTrt compares the Nil with the mean over all treatments. ConVsTrt.G1vsG2 compares the mean of the G1 treatments with that for G2. And the other factors assess the main effects for the G1 or G2 factors and the two-way interactions between a and b for G1 and, separately, for a and b for G2.
The correspondence between the five factors for a control plus two-factorial treatment structure is given in Table 5.
Table 5: Relationship between factors in a control plus double factorial trial.

With complex structures such as this one, care needs to be taken to make sure the nesting of the factors is correct. Creating a dummy ANOVA table (available in Genstat) can be a very useful tool to aid this checking:
GxE
Genotype by Environment or GxE is a special kind of interaction, exploring how genotypic differences vary between environments. This is explored in detail in the blog The G×E interaction phenomenon
Key takeaways for interpreting interactionsInteractions and some more complex treatment structures can help identify important information in an analysis. Interpreting the results can be challenging. However, a well-designed figure is frequently the best way to interpret an interaction, as in Figures 3 and 4.