0

I want to conduct a (10) x (2) repeated measures ANOVA but can't seem to produce the results for Mauchly's test of sphericity in my output. I have tried using both the anova_test function from the rstatix package and the ezANOVA function from the ez package, but neither produce results from Mauchly's sphericity test. For context, my data looks like this:

   subject session reward_size  during_cs_rate
   <fct>   <fct>   <fct>                 <dbl>
 1 M3      1       Small Reward          0.056
 2 M3      1       Large Reward          0.056
 3 M3      2       Small Reward          0.024
 4 M3      2       Large Reward          0.088
 5 M3      3       Small Reward          0.16 
 6 M3      3       Large Reward          0.232
 7 M3      4       Small Reward          0.016
 8 M3      4       Large Reward          0.04 
 9 M3      5       Small Reward          0.016
10 M3      5       Large Reward          0.032
# … with 150 more rows

I have 8 subjects and two within-subjects factors: session (10 levels) and reward size (2 levels). A factorial repeated measured ANOVA should produce Mauchly's test of sphericity for the session factor. Yet, this is what I get:

>  cr_aov <- anova_test(data = pav_master,
                               dv = during_cs_rate,
                               wid = subject,
                               within = c(session, reward_size),
                               effect.size = "pes")
>  get_anova_table(cr_aov)

ANOVA Table (type III tests)

               Effect DFn DFd     F        p p<.05   pes
1             session   9  63 6.793 9.48e-07     * 0.492
2         reward_size   1   7 0.615 4.59e-01       0.081
3 session:reward_size   9  63 2.622 1.20e-02     * 0.272

I get the exact same results with the ezANOVA function. I have found that if I slice my data so that I cut the first factor to just 8 levels (same as my sample size), the ANOVA finally produces the results for Mauchly's test.

> test_data <- pav_master %>%
      arrange(session) %>%
      slice(1:128)
    
> anova_test(data = test_data,
             dv = during_cs,
             wid = subject,
             within = c(session, reward_size))
    
> test_aov

ANOVA Table (type III tests)

$ANOVA
               Effect DFn DFd     F        p p<.05      ges
1             session   7  49 5.073 0.000221     * 2.21e-01
2         reward_size   1   7 0.002 0.964000       1.57e-05
3 session:reward_size   7  49 1.927 0.085000       4.70e-02

$`Mauchly's Test for Sphericity`
               Effect        W     p p<.05
1             session 5.00e-03 0.815      
2 session:reward_size 5.65e-05 0.066      

$`Sphericity Corrections`
               Effect   GGe      DF[GG] p[GG] p[GG]<.05   HFe      DF[HF]    p[HF] p[HF]<.05
1             session 0.512 3.58, 25.08 0.005         * 1.114  7.8, 54.61 0.000221         *
2 session:reward_size 0.435 3.04, 21.31 0.155           0.807 5.65, 39.57 0.104000 

Does this mean I need my sample size to be larger or equal to the number of levels for my within-subjects factors? Is there some way I can force R to run the Mauchly test and show me the results without changing my sample size?

  • `ezANOVA` from package {ez} returns the Mauchly results while `anova_test` from package {rstatix} does not. There seem to be different datasets and ANOVA results hanging around in your session (your dependent variable is named *during_cs* in one code snippet vs *during_cs_rate* in the other), so Mauchly's test was displayed because at that time you accessed the proper ANOVA output (from ezANOVA, not rstatix) which by chance was calculated from the modified dataset with the "cut factor". Try `ezANOVA(data = pav_master, dv = during_cs_rate, wid = subject, within = c(session, reward_size))` –  May 28 '22 at 08:57
  • Sorry I know the variables don’t line up, but that’s because I put bits and pieces of my code into the question. during_cs and during_cs_rate are essentially the same variable (one is just the other but divided by 5). I didn’t put it in my question but the ezANOVA also doesn’t show Mauchly’s test. I saw someone suggest on another forum that the ANOVA might require the sample size to be equal or larger the number of cells within the design to conduct a Mauchly test. Do you happen to know if this is the case? It would explain why cutting my data produces the results for the test. – LKeevers May 29 '22 at 09:47
  • Usig your *uncut* data "pav_master" (reconstructed with `rnorm` values for "during_cs_rate" *as the only difference*, as you did not make these data available) and `ezANOVA(...)` as detailled in my previous comment I get the desired Mauchly result. 8 Subjects x 10 sessions x 2 reward sizes. I'd suggest starting a new R session, workspace clean except your original *pav_master*, call ezANOVA on *pav_master* and inspect the output. –  May 29 '22 at 10:20
  • Hmm, I tried what you suggested but had no luck. I used ezANOVA on the uncut data and it only produces the standard ANOVA table, no Mauchly result or sphericity correction, even in a new R session and clean environment. However, when I simply slice the data to remove the last two levels of session, and apply exactly the same ezANOVA function, I get all the necessary Mauchly results. All I'm changing in my code is ```ezANOVA(data = pav_master...etc``` to ```ezANOVA(data = pav_master %>% arrange(session) %>% slice(1:128)...etc``` – LKeevers May 29 '22 at 23:10
  • Interestingly enough, I just changed the variable from during_cs to during_cs_rate and it worked, despite the fact that they are both in the same data frame, and one is just the other but divided by a constant. Not sure why this is, but it works. Thanks for the help and apologies for my lack of detail in the question. All the best! – LKeevers May 30 '22 at 07:01

0 Answers0