Interactions – main effects are not the only effects

Lisa Pilkington

01 Feb 2026

ANOVA Significance Tests Factors

In “Two-way ANOVA – Twice the Fun!”, we introduced the concept of exploring the effect of multiple factors on a result. In that instance we were looking at the main effects of each factor – i.e. the individual impact of each factor.

This, however, is not always a true reflection of what happens in reality – in many instances, the level of one factor can impact the effect of another – this is known as an interaction.

To include interaction effects, all that needs to be done is the addition of an interaction term in the two-way analysis. To conduct a two-way ANOVA with an interaction term, the code is:

anovaexample <- lm(measurements~Factor1 + Factor2 + Factor1:Factor2, data = ExampleDataframe.df)

anova(anovaexample)

  • The term "anovaexample" is the name of a linear model.
  • "<-lm(...)" instructs R to create a linear model, using information from the dataframe (in this case the dataframe is called "ExampleDataframe.df"). The “measurements” is the response (i.e. quantitative data) and “Factor1”, “Factor2”… are the names of the factors being explored. The main effects of the factors are included in the through their separate terms and their interaction effect is investigated through the interaction term (in this case “Factor1:Factor2”).
  • The term "anova(...)" instructs R to conduct an ANOVA analysis on the relationship that you defined as your linear model (in this case, the linear model is called "anovaexample").

If you have more than two factors, you can also include more than two interaction terms.

In the generated output, one should look at the interaction term(s) first:

  • if the interaction term has a non-significant p-value (p-value > 0.05), it means that the interaction term is not significant and the levels of one factor do not affect the impact of the other. In this case, one should just focus on the main effects (and exploring their impact; i.e. analysing the p-values and side-by-side plots as outlines in “Two-way ANOVA – twice the fun!
  • if the interaction term is significant (p-value < 0.05), it means that all of the factors involved in that interaction are significant and impact the result – interaction plots (see below) should be used to understand these effects.

An interaction plot allows you to visualise the effects of the factors and assess if there is an interaction (and the nature of it) in the way that they influence the response.

Interaction plots have the response as the y-variable, one of the factors as the x-variable and the other factor as the trace variable (i.e. different lines for each level of it).

To generate an interaction plot, the code is:

interaction.plot(x.factor = ExampleDataFrame.df$Factor1, trace.factor = ExampleDataFrame.df$Factor2, response = ExampleDataFrame.df$measurement, ylab = "measurement", xlab = "Factor1",trace.label = "Factor2", fun = mean)

The term "interaction.plot(...)"instructs R to create an interaction plot of the response (in this case the column is called measurements) which is the y-variable, looking at the effect of two factors; one factor is displayed on the x-axis (in this case Factor1) and one factor is the trace factor – where each line relates to a level of this factor (in this case Factor2), with all of these vectors in a dataframe (in this case the data frame is called ExampleDataframe.df).

  • ylab = " measurement"" says what the y-axis label of the graph should be, in this case I have titled it simply; measurement.
  • xlab = " Factor1"" says what the x-axis label of the graph should be, in this case I have titled it simply; Factor1.
  • trace.label = " Factor2"" says what the label of the traces should be, in this case I have titled it simply; Factor2.
  • fun = mean" specifies that the means of each group/point should be plotted.

To interpret an interaction plot, in general:

  • if the lines on the interaction plot are parallel then there is no interaction effect.
  • if the lines intersect OR they are not parallel (i.e. have notably different gradients) then there is likely an interaction effect.

Interactions are not always present, but when they are we need to take action to understand them and their impact!