Using R and the Metafor package, I'd like to know how I can run many random effect models on all combinations of all of my moderators. I know I can pre-select any combination of moderators to include manually, though I'm unsure how to loop over all of my moderators so that I can run the rma function as many times as there are moderator combinations (I assume with a loop).
Example of rma function with all 7 moderators
mod <- rma(smd, se, mods=~ A + B + C + D + E + F + G, data=dat)
I can't manually keep running the function over and over adjusting moderator combinations as that would be far too time consuming. Is there such a way to automate this process? My moderators are columns (variables) in a 'moderator' data-frame.
I assume I can loop over my mod variables changing them on each iteration, though I'm not sure how best to implement this. I have tried using a for loop to iterate over the moderators, updating the rma function accordingly but the function doesn't seem accept this. Here is a basic example of what I tried, this is just to see if I can insert one moderator at a time into the function:
for (i in colnames(mods1)){
rma(smd, sei=se, mods=~ mods1[i], data=dat)
}
>> invalid type (list) for variable 'mods1[i]'
Any help is appreciated.