0

I have done multiple anova.rma functions from the metafor package to compare 2 vs. 3 level models in a meta-analysis, and the output in the console is a nice table. I would like to write this to a csv so that I can store these results, however the object that is saved in the environment is a list and I am having trouble actually writing this output in a nice format. Does anyone have any suggestions?

Update: I added an example data and script so that maybe others can reproduce the problem I have been having easier https://github.com/jmmakoshark/anova.rma/blob/main/anova_rma_ex.csv https://github.com/jmmakoshark/anova.rma/blob/main/anova_rma_ex.r

output from console

  • 1
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064). Have you tried `write.table()` with the results from `summary()`? – MrFlick Sep 01 '22 at 18:05
  • Hi, sorry if there is not enough info I'm new to this. I've been working out of an online textbook and think that has the best example to illustrate the function: https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/multilevel-ma.html#model-fitting – jmmakoshark Sep 01 '22 at 19:40
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 02 '22 at 04:21

1 Answers1

0

There is an as.data.frame() method for anova.rma objects. So, just do as.data.frame(anova(...)) and then you get a plain data frame that you can write to a csv file.

Wolfgang
  • 2,810
  • 2
  • 15
  • 29
  • When I try that I get this error message, and I keep getting stuck here where I can't coerce > as.data.frame(anova(est_MILK2,est_MILK3)) Error in as.data.frame.default(anova(est_MILK2, est_MILK3)) : cannot coerce class ‘"anova.rma"’ to a data.frame – jmmakoshark Sep 02 '22 at 12:04
  • Do you have the most recent version (3.8-1) of metafor installed? https://cran.r-project.org/package=metafor – Wolfgang Sep 02 '22 at 14:08
  • 1
    I did not. I had 3.4 and just updated it, and now everything works. Thanks so much for the help! – jmmakoshark Sep 02 '22 at 14:30