rstatix
rstatix copied to clipboard
Repeated measure anova error
Hi,
I am trying to do rep measures ANOVA using the rSTATIX package but it is showing the following
Error: Problem with mutate()
input data
.
x 0 (non-NA) cases
i Input data
is map(.data$data, .f, ...)
.
I am not sure whats the problem is, tried everything but unsuccessful. Worked fine for normal two-way ANOVA but not for repeated. Please help.
Hi @Jenna56
could you provide us with a reprex (reproducible example)? As you can see below, a repeated measures ANOVA can be done as expected with rstatix
.
library(tidyverse)
library(rstatix)
ChickWeight %>%
anova_test(dv = weight, wid = Chick, within = Time, between = Diet)
#> ANOVA Table (type III tests)
#>
#> $ANOVA
#> Effect DFn DFd F p p<.05 ges
#> 1 Diet 3 41 5.075 4.00e-03 * 0.161
#> 2 Time 11 451 280.945 6.41e-194 * 0.769
#> 3 Diet:Time 33 451 3.766 9.34e-11 * 0.118
#>
#> $`Mauchly's Test for Sphericity`
#> Effect W p p<.05
#> 1 Time 2.68e-17 1.03e-251 *
#> 2 Diet:Time 2.68e-17 1.03e-251 *
#>
#> $`Sphericity Corrections`
#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF]
#> 1 Time 0.114 1.26, 51.48 2.01e-24 * 0.116 1.28, 52.34 8.63e-25
#> 2 Diet:Time 0.114 3.77, 51.48 1.00e-02 * 0.116 3.83, 52.34 1.00e-02
#> p[HF]<.05
#> 1 *
#> 2 *
Created on 2021-10-06 by the reprex package (v2.0.1)
I am experiencing the same issue but only when trying to pass a formula instead of the way you specified the ANOVA. Attached you can find the data I am using for my analysis, which looks like:
# A tibble: 344 × 4
subj_id exp_cond dimension score
<dbl> <chr> <chr> <dbl>
1 7 control edu_mot1_challenge 3.75
2 7 control edu_mot1_interest 3.4
3 7 control edu_mot1_success 2.75
4 7 control edu_mot1_failure 1.2
5 7 control edu_mot2_challenge 5
6 7 control edu_mot2_interest 5.6
7 7 control edu_mot2_success 6.5
8 7 control edu_mot2_failure 2.6
9 1 experimental edu_mot1_challenge 5.5
10 1 experimental edu_mot1_interest 4.6
# … with 334 more rows
When I execute my repeated measures ANOVA the same way you did, it works.
data %>%
anova_test(dv = score,
wid = subj_id,
within = dimension,
between = exp_cond,
type = 2)
My output then looks like:
ANOVA Table (type II tests)
$ANOVA
Effect DFn DFd F p p<.05 ges
1 exp_cond 1 41 0.000165 9.90e-01 1.24e-06
2 dimension 7 287 74.487000 7.46e-61 * 5.57e-01
3 exp_cond:dimension 7 287 0.478000 8.50e-01 8.00e-03
$`Mauchly's Test for Sphericity`
Effect W p p<.05
1 dimension 0.07 1.29e-10 *
2 exp_cond:dimension 0.07 1.29e-10 *
$`Sphericity Corrections`
Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF] p[HF]<.05
1 dimension 0.515 3.6, 147.69 1.48e-32 * 0.57 3.99, 163.67 8.30e-36 *
2 exp_cond:dimension 0.515 3.6, 147.69 7.32e-01 0.57 3.99, 163.67 7.51e-01
However, when I try to pass a formula like so, which resembles the formula notation given on the help page, then I only see an error.
data %>%
anova_test(score ~ exp_cond*dimension + Error(subj_id/(exp_cond*dimension)))
Within-Ss ANOVA (repeated measures ANOVA): y ~ w1*w2 + Error(id/(w1*w2))
Error message:
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
Is this really a bug or did I just specify the formula the wrong way?
Here's my sys.info output:
Sys.info()
sysname
"Darwin"
release
"20.6.0"
version
"Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101"
nodename
"XXXX-macbook-m1.fritz.box"
machine
"arm64"
login
"root"
user
"XXXX"
effective_user
"XXXX"
OK I just realised that it was my bad because I needed to specify the formula for a mixed ANOVA. Sometimes typing things out really helps to change one's POV :)