4

I'm trying to do a mixed anova with 1 between- and 3 within-subjects factors.

My data looks like the following:

> head(rt_dat_allconds)
# A tibble: 6 x 6
# Groups:   participant, search_difficulty, cue_validity [3]
  participant search_difficulty cue_validity cue_colour     mrt  cond
        <dbl> <fct>             <fct>        <fct>        <dbl> <dbl>
1         642 difficult         FALSE        Match (Colo… 1.08      1
2         642 difficult         FALSE        Mismatch (O… 1.00      1
3         642 difficult         TRUE         Match (Colo… 0.961     1
4         642 difficult         TRUE         Mismatch (O… 0.978     1
5         642 easy              FALSE        Match (Colo… 0.945     1
6         642 easy              FALSE        Mismatch (O… 0.885     1

I'm trying to run these lines of code for my anova:

res.aov <- anova_test(data=rt_dat_allconds, dv=mrt, wid=participant, between=cond, within=c(search_difficulty, cue_validity, cue_colour))
get_anova_table(res.aov)

However, when I run the line that begins with 'res.aov' I get the following error:

"Error: Can't subset columns that don't exist. x The columns participant, search_difficulty, and cue_validity don't exist."

I'm not sure why it can't identify the columns. I can use those column names to do a variety of dplyr functions like group_by etc.

Any ideas would be great. Thanks!

Phil
  • 7,287
  • 3
  • 36
  • 66
anntree
  • 261
  • 3
  • 10

1 Answers1

2

If you run anova_test in a grouped tibble, it will try to run a grouped anova, which runs a separate ANOVA for each group in the data. I believe that is not what you desire. Let me illustrate this with an example:

# Setting up
library(tidyverse)
library(rstatix)
data("ToothGrowth")
df <- ToothGrowth

This is the ANOVA on the ungrouped data

> df %>%
+   anova_test(len ~ dose)

ANOVA Table (type II tests)

  Effect DFn DFd       F        p p<.05   ges
1   dose   1  58 105.065 1.23e-14     * 0.644

This is the ANOVA on the grouped data

> df %>%
+   group_by(supp) %>%
+   anova_test(len ~ dose)

# A tibble: 2 x 8
  supp  Effect   DFn   DFd     F        p `p<.05`   ges
* <fct> <chr>  <dbl> <dbl> <dbl>    <dbl> <chr>   <dbl>
1 OJ    dose       1    28  36.0 1.82e- 6 *       0.563
2 VC    dose       1    28 118.  1.51e-11 *       0.808

Note how different the results are. This is because the second is equivalent to:

> df %>%
+   filter(supp == "OJ") %>%
+   anova_test(len ~ dose)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

  Effect DFn DFd      F        p p<.05   ges
1   dose   1  28 36.013 1.82e-06     * 0.563
> df %>%
+   filter(supp == "VC") %>%
+   anova_test(len ~ dose)
Coefficient covariances computed by hccm()
ANOVA Table (type II tests)

  Effect DFn DFd       F        p p<.05   ges
1   dose   1  28 117.948 1.51e-11     * 0.808

So, in line with Ronak Shah comment on the question, avoid grouping the data before using anova_test, unless you desire a grouped ANOVA.

Mateus
  • 86
  • 7