Search code examples
matrixerror-handlingcharactermetafor

metafor package, rma.uni, mods, Model matrix contains character variables


I'm trying to run a meta-regression with MD's as dependent variable. I want to add a numeric moderator (year published) to the rma.uni function. Formula so far:

metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Pain$Author, Pain$Year), weighted=TRUE, subset=(Pain$outcomegruppe=="9"), mods =("Pain$Year") )

I always get the error message:

Error in metafor::rma.uni(yi = MCID12, sei = SE12, method = "FE", data = Pain, : Model matrix contains character variables.

My "Year" veriable is definetly numeric. As soon as I don't use the "mods" argument, everything works normal. Could anyone help me with this problem? Thanks in advance!


Solution

  • Don't put Year in quotes. Also, you don't need the Pain$ parts and weighted=TRUE is the default. This should do it:

    metafor::rma.uni(yi=MCID12, sei=SE12, method="FE", data=Pain, slab=paste(Author, Year), 
                     subset=(outcomegruppe=="9"), mods=~Year)