Can I convert an object of class anova_test (rstatix) to an object of class aov, anova, or aovlist?

479 views Asked by At

Some sample data from the DATANOVIA guide on repeated measures ANOVA:

library(tidyverse)
library(ggpubr)
library(rstatix)

data("selfesteem", package = "datarium")

selfesteem <- selfesteem %>%
  gather(key = "time", value = "score", t1, t2, t3) %>%
  convert_as_factor(id, time)

res.aov <- anova_test(data = selfesteem, dv = score, wid = id, within = time)
get_anova_table(res.aov)

I would like to use the report package from the publishers EasyStats (https://github.com/easystats/report). It accepts ANOVA objects of class aov, anova, or aovlist. The object from rstatix ANOVA is of class anova_test, so incompatible with report.

Is there any way I can convert the object class, or should I do my repeated measures ANOVA using base R?

Response 1 (that has since been deleted):

class(res.aov) <- "aov" or class(res.aov) <- c("aov", class(res.aov)). You can add or change class attributes of objects

So I tried this:

> res.aov <- anova_test(data = selfesteem, dv = score, wid = id, within = time)

> report(res.aov)
Error in report.default(res.aov) : 
  The input you provided is not supported yet by report :(

Object summary

Then your suggestion:

> class(res.aov) <- c("aov", class(res.aov))
> report(res.aov)
Error in UseMethod("anova") : 
  no applicable method for 'anova' applied to an object of class "c('aov', 'anova_test', 'list', 'rstatix_test')"

Object summary 2 The class change appears to have worked, but there is still an issue in passing along the object to report. How do I proceed?

On a side note, if someone can clarify if these are equivalent, my issue can be resolved by passing my ANOVA to base R:

Is

anova_test(response ~ A * B + Error(subject/(A * B))) in rstatix

equivalent to

aov(response ~ A * B + Error(subject/(A * B))) in stats?

0

There are 0 answers