Statistical tests such as repeated measures ANOVA assume sphericity, meaning that the variances of the differences between all possible pairs of groups are equal. Whereas assumption of normality of distribution may be overlooked in some cases due to the robustness of ANOVA, the assumption of sphericity in repeated measures ANOVA must be met. Violating this assumption may severely compromise the interpretation of the test results.

Mauchly’s sphericity test checks this assumption for you. The null hypothesis H0 in this test states that there is no difference in variances for all pairwise group comparisons. In R, the main function is mauchly.test(). However, running it is not that straight forward. It involves building a matrix with the dataset to be tested, whereas your data is usually nicely arranged in a dataframe.

Let’s see how this is done using the same example as for repeated measures ANOVA. Here, 5 rats are weighed 4 times with intervals of 4 weeks (week8 to 20). This is the code for the dataframe:

# response variable
rat.weight <- c(164,164,158,159,155,220,230,226,227,222,261,275,264,280,272,306,326,320,330,312)

# predictor variable
time.point <- as.factor(c(rep("week08",5), rep("week12",5), rep("week16",5), rep("week20",5)))

# individual ID
rat.ID <- as.factor(rep(c("rat1","rat2","rat3", "rat4", "rat5"),4))

# dataframe
my.dataframe <- data.frame(rat.ID,time.point,rat.weight)



We start by creating a matrix called neo that contains the data rat.weight. In that matrix, the 5 individuals will be shown in rows, and time points in column. Here is the code:

neo <- matrix(rat.weight, nrow = 5, ncol = 4)
neo
##      [,1] [,2] [,3] [,4]
## [1,]  164  220  261  306
## [2,]  164  230  275  326
## [3,]  158  226  264  320
## [4,]  159  227  280  330
## [5,]  155  222  272  312



Now that the matrix is in place, we can used mauchly.test() (in combination with lm()) to test for sphericity:

mauchly.test(lm(neo ~ 1), X = ~ 1)
## 
##  Mauchly's test of sphericity
##  Contrasts orthogonal to
##  ~1
## 
## 
## data:  SSD matrix from lm(formula = neo ~ 1)
## W = 0.15303, p-value = 0.4294

The output returns a p-value over 0.05 meaning that the null hypothesis stating that there is no difference in variances for all pairwise group comparisons is accepted.