I am conducting a meta-analysis and need to analyse multiple moderators. I am using the rma.uni function and have code which will stay the same for all moderators I'm testing:
res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), data = outcomeData)
I want to add the argument "mods = ~ x", where x is the moderator I am testing (e.g. YEAR or AUTHOR) and then do a for loop of a combined list of moderators.
I have tried a couple of different ways but I'm having trouble interprettign the error messages.
mod.test <- c("AUTHOR", "YEAR")
for (i in mod.test){
res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), mods = ~ i, data = outcomeData)
print(res)
}
and
mod.test <- c("AUTHOR", "YEAR")
for (x in mod.test){
i <- paste("mods = ~ ", x)
res <- rma.uni(method = "HS", measure = "SMD", m1i = EXPM, m2i = CONM, sd1i = EXPSD, sd2i = CONSD, n1i = EXPN, n2i = CONN, slab=paste(AUTHOR, YEAR, sep=", "), mods = ~ i, data = outcomeData)
print(res)
}
both give the error:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Thanks for any help.