0
votes

After a regression model has been estimated, it is typical to extract predicted values. But I can't figure out how to do this in metafor::rma(

library(metafor)

res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg,
       mods = ~ ablat + year, 
       data=dat.bcg)

predict(res, 
    newdata = expand.grid(
      year = 1980,
      ablat = 30:55
      )
    )

which returns 13 fitted values (the rows in the data used to estimate the rma object, rather than the 25 rows in expand.grid( object.

How can I do out of sample predictions on a new data.frame?

1

1 Answers

1
votes

The help file for ?predict.rma specifies the parameter as newmods rather than newdata and it seems to require a matrix rather than a data.frame. This should work

predict(res, 
        newmods = as.matrix(expand.grid(
          ablat = 30:55,
          year = 1980
        ))
)