How can I perform Welch’s ANOVA in R, step-by-step?

Welch’s ANOVA in R is a statistical test used to compare the means of three or more groups. It is suitable for data that does not meet the assumptions of traditional ANOVA, such as equal variances across groups. The following is a step-by-step guide on how to perform Welch’s ANOVA in R:

1. Load the necessary packages: First, load the “car” and “userfriendlyscience” packages in R. These contain functions that are required for performing Welch’s ANOVA.

2. Import the data: Use the “read.csv” function to import your data into R. Make sure your data is in a data frame format.

3. Check data assumptions: Before conducting the test, it is important to check if the data meets the assumptions of Welch’s ANOVA. Use the “leveneTest” function from the “car” package to test for equal variances across groups.

4. Run the Welch’s ANOVA test: Use the “oneway.test” function from the “userfriendlyscience” package to perform Welch’s ANOVA. Specify the dependent variable and the grouping variable, and set the “var.equal” argument to “FALSE” to indicate unequal variances.

5. Interpret the results: The output generated by the “oneway.test” function will provide the F-statistic, degrees of freedom, and p-value. A significant p-value (less than 0.05) indicates that there is a significant difference between the group means.

6. Post-hoc tests (optional): If the ANOVA test is significant, you can perform post-hoc tests to determine which groups differ from each other. This can be done using the “pairwise.t.test” function.

In summary, Welch’s ANOVA in R can be performed by loading the necessary packages, importing the data, running the test, and interpreting the results. Additional steps, such as checking assumptions and conducting post-hoc tests, can also be included for a thorough analysis.

Perform Welch’s ANOVA in R (Step-by-Step)


Welch’s ANOVA is an alternative to the typical when the is violated.

The following step-by-step example shows how to perform Welch’s ANOVA in R.

Step 1: Create the Data

To determine if three different studying techniques lead to different exam scores, a professor randomly assigns 10 students to use each technique (Technique A, B, or C) for one week and then makes each student take an exam of equal difficulty. 

The exam scores of the 30 students are shown below:

#create data frame
df <-data.frame(group = rep(c('A','B', 'C'), each=10),
                score = c(64, 66, 68, 75, 78, 94, 98, 79, 71, 80,
                          91, 92, 93, 85, 87, 84, 82, 88, 95, 96,
                          79, 78, 88, 94, 92, 85, 83, 85, 82, 81))

#view first six rows of data frame
head(df)

   group score
1      A    64
2      A    66
3      A    68
4      A    75
5      A    78
6      A    94

Step 2: Test for Equal Variances

Next, we can perform to determine if the variances between each group is equal.

If the of the test statistic is less than some significance level (like α = .05) then we can reject the null hypothesis and conclude that not all groups have the same variance.

To perform Bartlett’s test we can use the bartlett.test function in base R, which uses the following syntax:

bartlett.test(formula, data)

Here’s how to use this function in our example:

#perform Bartlett's test
bartlett.test(score ~ group, data = df)

	Bartlett test of homogeneity of variances

data:  score by group
Bartlett's K-squared = 8.1066, df = 2, p-value = 0.01737

The p-value (.01737) from Bartlett’s test is less than α = .05, which means we can reject the null hypothesis that each group has the same variance.

Thus, the assumption of equal variances is violated and we can proceed to perform Welch’s ANOVA.

Step 3: Perform Welch’s ANOVA

To perform Welch’s ANOVA in R, we can use the oneway.test() function from base R as follows:

#perform Welch's ANOVA
oneway.test(score ~ group, data = df, var.equal = FALSE)

	One-way analysis of means (not assuming equal variances)

data:  score and group
F = 5.3492, num df = 2.00, denom df = 16.83, p-value = 0.01591

The overall p-value (.01591) from the ANOVA table is less than α = .05, which means we can reject the null hypothesis that the exam scores are equal between the three studying techniques.

We can then perform a post-hoc test to determine which group means are different. Refer to the following tutorials to see how to perform various post-hoc tests in R:

Reference to determine which post-hoc test is best to use depending on your situation.

Additional Resources

x