3

I've just ran a mixed ANOVA using ezANOVA and I need to create a data frame with the output for extraction into an Rmd but I cannot find any information on how to do it.

I've previously used aov() and broom::tidy(), however tidy() cannot format the output I get from the ezANOVA. I've tried as.data.frame but it results is a very messy data frame so I'd rather not use it. Does anybody know of a solution which gives an easy to read data frame similar to tidy()?

My ANOVA:

library(ez)

aov <- b <- ezANOVA(data=exp1.long,
        dv=consensus,
        wid=participant_id,
        within=trait,
        between=age_group,
        type=3,
        detailed=T 
        )

Julia M
  • 133
  • 1
  • 9
  • 1
    Welcome to stackoverflow! By following this guide [how to ask](https://stackoverflow.com/help/how-to-ask) you provide a solid basis for answering this question. In particular, it's mostly necessary to provide an [verifiable example](https://stackoverflow.com/help/mcve) (a minimum, complete, and verifiable example). Check out [this page](https://stackoverflow.com/a/5963610/4573108) for tips regarding R-specific MCVEs. Good look and thank you for contributing! – mischva11 Apr 20 '19 at 21:06

2 Answers2

1

Have you tried adding return_aov = TRUE?

 b <- ezANOVA(data=exp1.long,
      dv=consensus,
      wid=participant_id,
      within=trait,
      between=age_group,
      type=3,
      detailed=T 
    return_aov = TRUE
    )

The return_aov command, if set on TRUE, computes and returns an aov object corresponding to the requested ANOVA (useful for computing post-hoc contrasts).

See for details: https://rdrr.io/cran/ez/man/ezANOVA.html

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
HvG
  • 43
  • 8
0

The trick is:

df <- as.data.frame(print(aov))

We can then check the resulting df class to confirm it worked correctly:

class(df)
"data.frame"

And check the output (note: used my own data):

df
  ANOVA.Effect ANOVA.DFn ANOVA.DFd   ANOVA.F    ANOVA.p ANOVA.p..05    ANOVA.ges
2        COND1         1        53 4.1938628 0.01947959           * 0.0070548612
3        COND2         1        53 3.6018758 0.02962809           * 0.0040817987
4  COND1:COND2         1        53 0.8371797 0.24026453             0.0008646178

Explanation: It is true that the return_aov = TRUE argument adds an aov object, which can provide similar results when used as summary(aov$aov). However, the result is still not a dataframe, and trying as.data.frame(summary(aov$aov)) outputs Error in as.data.frame.default(summary(aov$aov)) : cannot coerce class ‘"summary.aovlist"’ to a data.frame.

Hopefully, this provides the outcome you were looking for.

rempsyc
  • 785
  • 5
  • 24