Tutorial FilesBefore we begin, you may want to download the sample data (.csv) used in this tutorial. Be sure to right-click and save the file to your R working directory. This dataset contains a hypothetical sample of 60 participants who are divided into three stress reduction treatment groups (mental, physical, and medical) and two gender groups (male and female). The stress reduction values are represented on a scale that ranges from 1 to 5. This dataset can be conceptualized as a comparison between three stress treatment programs, one using mental methods, one using physical training, and one using medication across genders. The values represent how effective the treatment programs were at reducing participant's stress levels, with higher numbers indicating higher effectiveness.
Beginning StepsTo begin, we need to read our dataset into R and store its contents in a variable.
- > #read the dataset into an R variable using the read.csv(file) function
- > dataTwoWayInteraction <- read.csv("dataset_ANOVA_TwoWayInteraction.csv")
- > #display the data
- > dataTwoWayInteraction
Omnibus TestLet's run a general omnibus test to assess the main effects and interactions present in the dataset.
- > #use anova(object) to test the omnibus hypothesis
- > #Are main effects or interaction effects present in the independent variables?
- > anova(lm(StressReduction ~ Treatment * Gender, dataTwoWayInteraction))
Divide the DataThe significant omnibus interaction suggests that we should ignore the main effects and instead investigate the simple main effects for our independent variables. To do so, we need to divide our dataset along each level of our treatment variable. We can create subsets of our dataset using the subset(data, condition) function, where data is the original dataset and condition contains the parameters defining the subset.
- > #use subset(data, condition) to divide the original dataset
- > #medical subset
- > dataMedical <- subset(dataTwoWayInteraction, Treatment == "medical")
- > #mental subset
- > dataMental <- subset(dataTwoWayInteraction, Treatment == "mental")
- > #physical subset
- > dataPhysical <- subset(dataTwoWayInteraction, Treatment == "physical")
Group ANOVAsWith datasets representing each of our treatment groups, we can now run an ANOVA for each that investigates the impact of gender. You may notice that this is effectively running three one-way ANOVAs with gender being the independent variable. Therefore, we should control for Type I error by dividing our typical .05 alpha level by three (.017).
- > #run ANOVA on the treatment subsets to investigate the impacts of gender within each
- > #medical
- > anova(lm(StressReduction ~ Gender, dataMedical))
- > #mental
- > anova(lm(StressReduction ~ Gender, dataMental))
- > #physical
- > anova(lm(StressReduction ~ Gender, dataPhysical))
At an alpha level of .017, the gender effect within the mental (p = .014) and physical (p < .001) groups was statistically significant. In the mental condition, the means are 3 for males and 4 for females. In the physical condition, the means are 4 for males and 2 for females. These results suggest that the mental treatment is more effective in reducing stress for females than males, while the physical treatment is more effective for males than females. Further, there is insufficient statistical support for a gender difference in the medical treatment.