A one-way ANOVA is used to determine whether or not there is a significant difference between the means of three or more independent groups.

One of the assumptions of a one-way ANOVA is that the variances of the populations that the samples come from are equal.

One of the most common ways to test for this is by using a **Brown-Forsythe test**, which is a statistical test that uses the following hypotheses:

**H**The variances among the populations are equal._{0}:**H**: The variances among the populations are not equal._{A}

If the p-value of the test is less than some significance level (e.g. α = .05) then we reject the null hypothesis and conclude that the variances are not equal among the different populations.

This tutorial provides a step-by-step example of how to perform a Brown-Forsythe test in R.

**Step 1: Enter the Data**

Suppose we’d like to know whether or not three different workout programs lead to different levels of weight loss.

To test this, we recruit 90 people and randomly assign 30 to use each program. We then measure the weight loss of each person after one month.

The following dataset contains information on how much weight people lost on each program:

#make this example reproducible set.seed(0) #create data frame data <- data.frame(program = as.factor(rep(c("A", "B", "C"), each = 30)), weight_loss = c(runif(30, 0, 3), runif(30, 0, 5), runif(30, 1, 7))) #view first six rows of data frame head(data) # program weight_loss #1 A 2.6900916 #2 A 0.7965260 #3 A 1.1163717 #4 A 1.7185601 #5 A 2.7246234 #6 A 0.6050458

**Step 2: Summarize & Visualize the Data**

Before we perform a Brown-Forsythe test, we can create boxplots to visualize the variance of weight loss for each group:

boxplot(weight_loss ~ program, data = data)

We can also calculate the variance of weight loss in each group:

#load dplyr package library(dplyr) #calculate variance of weight loss by group data %>% group_by(program) %>% summarize(var=var(weight_loss)) # A tibble: 3 x 2 program var 1 A 0.819 2 B 1.53 3 C 2.46

We can see that the variances between the groups differ, but to determine if these differences are statistically significant we can perform the Brown-Forsythe test.

**Step 3: Perform the Brown-Forsythe Test**

To perform a Brown-Forsythe test in R, we can use the **bf.test()** function from the onewaytests package:

#load onewaytests package library(onewaytests) #perform Brown-Forsythe test bf.test(weight_loss ~ program, data = data) Brown-Forsythe Test (alpha = 0.05) ------------------------------------------------------------- data : weight_loss and program statistic : 30.83304 num df : 2 denom df : 74.0272 p.value : 1.816529e-10 Result : Difference is statistically significant. -------------------------------------------------------------

The p-value of the test turns out to be less than 0.000 and, as the output declares, the differences in variances between the three groups is statistically significant.

**Next Steps**

If you fail to reject the null hypothesis of the Brown-Forsythe Test, then you can proceed to perform a one-way ANOVA on the data.

However, if you reject the null hypothesis then this means the assumption of equal variances is violated. In this case, you have two options:

**1. Proceed with a One-Way ANOVA anyway.**

It turns out that a one-way ANOVA is actually robust to unequal variances as long as the largest variance is no larger than 4 times the smallest variance.

In step 2 from the example above, we found that the smallest variance was 0.819 and the largest variance was 2.46. Thus, the ratio of the largest to smallest variance is 2.46 / .819 = **3.003**.

Since this value is less than 4, we could simply proceed with the one-way ANOVA.

**2. Perform a Kruskal-Wallis Test**

If the ratio of the largest variance to the smallest variance is greater than 4, we may instead choose to perform a Kruskal-Wallis test. This is considered the non-parametric equivalent to the one-way ANOVA.

You can find a step-by-step example of a Kruskal-Wallis test in R here.

Great post! This really helped me out when performing this test for my own data. It was very easy to follow.