The means of the distribution change for each treatment, but the difference between them does not change for each gender. What about data with no interaction? How does that look? Let’s first simulate it. Plot(allEffects(aov2), multiline=TRUE, ci.style="bars") # Multiple R-squared: 0.9797, Adjusted R-squared: 0.978 # Residual standard error: 0.8899 on 36 degrees of freedom Notice you can use it with either aov or lm objects. Using the effects package we can create a formal interaction plot with standard error bars to indicate the uncertainty in our estimates. The only reason to use aov is to create an aov object for use with functions such as model.tables. Lm and aov both give the same results but show different summaries. If we look at the interaction plot again, we see that trt=”yes” and gender=”female” has about the same mean response as trt=”no” and gender=”male”.
What does -10 mean exactly? In some sense, at least in this example, it basically offsets the main effects of gender and trt. Because of this it’s difficult to interpret the coefficient for the interaction. For those settings, we add all the coefficients together to get the mean response for gender=”female” when trt=”yes”. The remaining combination to estimate is gender=”female” and trt=”yes”. Likewise, The coefficient for “trtyes” is what you add to the intercept to get the mean response for trt=”yes” when gender=”male”. (Compare it to the model.tables output above.) The coefficient for “genderfemale” is what you add to the intercept to get the mean response for gender=”female” when trt=”no”. The intercept in the linear model output is simply the mean response for gender=”male” and trt=”no”. If we want a test for the significance of main effects, we can use anova(lm1), which outputs the same anova table that aov created. Nor does it mean the main effects are significant. It does not contradict the ANOVA results. This just means the coefficients are significantly different from 0.
(Incidentally we can get these same coefficients from the aov1 object by using coef(aov1).) Notice everything is “significant”. # Residual standard error: 0.9111 on 36 degrees of freedom Finally we combine our vectors into a data frame. Notice we create an interaction by sampling from the distributions in a different order for each gender. Next we generate the response by randomly sampling from two different normal distributions, one with mean 15 and the other with mean 10. Then it generates treatment labels, 10 each of “yes” and “no”, alternating twice so we have 10 treated and 10 untreated for each gender. The following code first generates a vector of gender labels, 20 each of “male” and “female”. Using R, we can simulate data such as this. If the response to treatment depends on gender, then we have an interaction. Let’s say we have gender (male and female), treatment (yes or no), and a continuous response measure. The simplest type of interaction is the interaction between two two-level categorical variables. This means variables combine or interact to affect the response. If it does then we have what is called an “interaction”.
When doing linear modeling or ANOVA it’s useful to examine whether or not the effect of one variable depends on the level of one or more variables.