Testing the omnibus hypothesis via one-way ANOVA is simple process in R. This tutorial will explore how R can be used to perform a one-way ANOVA to test the difference between two (or more) group means.
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 two groups (control and treatment) of 30. The values represent a scale that ranges from 1 to 5. For instance, this dataset could be conceptualized as a comparison between two professional training programs, where the control group participated the company’s longstanding program and the treatment group participated in an experimental program. The values could represent the attitudes of employees towards the training programs on a scale from 1 (poor) to 5 (excellent).
Beginning StepsTo begin, we need to read our dataset into R and store its contents in a variable.
- > #read the one-way ANOVA dataset into an R variable using the read.csv(file) function
- > dataOneWay <- read.csv("dataset_ANOVA_OneWay.csv")
- > #display the data
- > dataOneWay
The first ten rows of our one-way ANOVA dataset.
One-Way ANOVANow that our data are ready, we can conduct a one-way omnibus ANOVA test using the anova(object) function.
- > #use anova(object) to test the omnibus hypothesis in one-way ANOVA
- > #is the difference between the group means statistically significant?
- > anova(lm(Values ~ Group, dataOneWay))
Our one-way ANOVA table.
The output of our ANOVA test indicates that the difference between our group means is statistically significant (p < .001). Conceptually, this suggests that employee attitudes towards the experimental training program were significantly higher than their attitudes towards the preexisting program.
Note that the object argument in our anova(object) function contained a linear model generated by the lm(formula, data) function. This is the same type of model that is used when conducting linear regression in R. A more detailed explanation of the lm(formula, data) function and examples of its use are available in my Simple Linear Regression article.