Fligner-Killeen test for homoscedasticity

Enter the name for this tabbed section: Description
This test evaluates whether a series of k samples were taken from populations with equal variances. It is based on the absolute values of the samples to the group median. These values are then ranked, then normalised and then summed.
Enter the name for this tabbed section: R Syntax
In R, the test can be performed using the function:

fligner.test{stats}

fligner.test(var1, var2, data = my data)
flinger.test(var1~var2, data = my data
  • var1 is a vector with the values observed in the samples.
  • var2 is a grouping variable of the same length as var1.
The functions has the same syntax as the Bartlett test and takes either two variables or a formula as arguments.
If we are dealing with an experiment with more than 1 factor, the factors needs to be collapsed into a single factor using the interaction() function.
Enter the name for this tabbed section: Example
Fligner-Killeen test

Let’s first create two variables that will be part of the dataframe to be assessed for homoscedasticity (Equality of variance). We will use the same variables as in Bartlett’s test.

# a continuous variable (here counts)
count <- c(250, 260, 230, 270, 310, 330, 280, 360, 250, 230, 220, 260, 340, 270, 300, 320, 250, 240, 270, 290)
# and a grouping variable (here sample)
sample <- gl(5, 4, labels = c("A", "B","C","D","E"))
# We can create a dataframe with the two variables
mydata <- data.frame(count, sample)

Note the use of the function gl() to create the grouping factor. We are now ready to carry out bartlett’s test:

# perform the bartlett' test on the data.
fligner.test(count, sample, data = mydata)
## 
##  Fligner-Killeen test of homogeneity of variances
## 
## data:  count and sample
## Fligner-Killeen:med chi-squared = 2.8973, df = 4, p-value = 0.5752

The test reveals that we should not reject the null hypothesis of equality of variance between populations.

Because the test is very often performed as part of an linear model or anova, we can also use the “formula” based syntax

# perform the bartlett' test on the data.
fligner.test(count~sample, data = mydata)
## 
##  Fligner-Killeen test of homogeneity of variances
## 
## data:  count by sample
## Fligner-Killeen:med chi-squared = 2.8973, df = 4, p-value = 0.5752

The test also works with more complex design but require the use of the interaction () function Let’s first create a dataset we can work with: here the ToothGrowth dataset from R base install The dataset includes two factors (Supp for Supplement type) and Dose and measures the growth of rat teeth with addition of vitamin C. We need to correct dose which is considerd as a number.

tg <-ToothGrowth
tg$dose <-factor(tg$dose)

To plot the combinations of factors and dose, we can use the interaction () function

plot(len ~ interaction(dose, supp), data = tg)

At first glance,the difference in the width of the box plot suggest heteroscedasticity. We need to test this using the Fligner-Killeen test.

Because we have more than 1 factor, we need to use the interaction function to collapse the factors into one. Otherwise, we would have the right degrees of freedom in the test.

fligner.test(len ~ interaction(dose, supp), data = tg)
## 
##  Fligner-Killeen test of homogeneity of variances
## 
## data:  len by interaction(dose, supp)
## Fligner-Killeen:med chi-squared = 7.7488, df = 5, p-value = 0.1706

Contrary to our expectations the data do not support heteroscedasticity (p-value = 0.1706)