thoughtsnippet
thoughtsnippet

Reputation: 93

Any way to use rma() outputs with broom package?

I am doing meta-analysis research and really fond of the metafor package in R. However, to be able to leverage all the great things you can do with R, for example managing many different models in a nested data.frame (Thanks to Hadley Wickham and David Robinson) I need to be able to use output from the metafor package rma()-models with broom.

Does anybody now how to do this. I am aware of the fact that it is not supported out of the box in broom (yet) but would very much appreciate a work-around so far.

Many thanks!

Upvotes: 0

Views: 469

Answers (1)

Andrew Taylor
Andrew Taylor

Reputation: 3488

Here is a very basic example of creating a new method for tidy that can handle rma class objects:

tidy.rma <- function(x) {
  return(data.frame(summary(x)$fit.stats))
}

This creates method rma for function tidy, and we define it to return a data.frame containing the fit statistics of the rma object.

You could instead make the tidy.rma function return a data.frame type object with any data you see fit. Mind you, you could have it return your favorite yo' momma joke and have it have nothing to do with the input rma model object at all. The tidy.rma method is completely your's to decide what it does.

Using the tidy function just like normal:

### Example from metafor package:
data(dat.bcg)
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
mod <-rma(yi, vi, data=dat, method="REML")
### And call tidy()
tidy(mod)

Provides a nice data.frame of the fit statistics:

             ML      REML
ll   -12.68777 -12.20237
dev   37.16141  24.40474
AIC   29.37554  28.40474
BIC   30.50544  29.37456
AICc  30.57554  29.73808

Upvotes: 2

Related Questions