# [R-meta] Plotting interaction effect from a rma.mv() fit

Viechtbauer, Wolfgang (SP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Wed Mar 17 13:03:30 CET 2021

```Please keep the mailing list in CC.

That is not how predict() works for rma objects. If you want to obtain the predicted value for level 1 of the outcome factor when time = 1, you would use:

predict(fit, addx=T, newmods = c(0,0,0, 1, 0,0,0))

(the spaces in c() have no meaning, they are just there to make this easier to read)

For the other three levels, it would be:

predict(fit, addx=T, newmods = c(1,0,0, 1, 1,0,0))
predict(fit, addx=T, newmods = c(0,1,0, 1, 0,1,0))
predict(fit, addx=T, newmods = c(0,0,1, 1, 0,0,1))

Best,
Wolfgang

>-----Original Message-----
>From: Simon Harmel [mailto:sim.harmel using gmail.com]
>Sent: Tuesday, 16 March, 2021 23:39
>To: Viechtbauer, Wolfgang (SP)
>Subject: Re: [R-meta] Plotting interaction effect from a rma.mv() fit
>
>Dear Wolfgang,
>
>Am I missing something that causes `predict.rma()` not find  "factor(outcome)"? --
>Many thanks
>
>library(metafor)
>fit <- rma.mv(d ~ factor(outcome)*time, V = SE^2, random= ~1|id, data = dat)
>
>predict.rma(gg, addx=T, newmods = c("factor(outcome)"=1, time=1))
>Error: Could not find variable 'factor(outcome)' in the model.
>
>On Tue, Mar 16, 2021 at 5:12 AM Viechtbauer, Wolfgang (SP)
><wolfgang.viechtbauer using maastrichtuniversity.nl> wrote:
>Dear Simon,
>
>Not aware of any packages that interface with rma.mv, but this is relatively easy
>to do by hand. Just use predict() with the newmods argument to compute the
>predicted values as a function of 'time' for each level of 'outcome' and then
>create a plot with those lines.
>
>Best,
>Wolfgang
>
>>-----Original Message-----
>>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org] On
>>Behalf Of Simon Harmel
>>Sent: Tuesday, 16 March, 2021 5:25
>>To: R meta
>>Subject: [R-meta] Plotting interaction effect from a rma.mv() fit
>>
>>Dear All,
>>
>>Are there plotting packages (e.g., `effects::plot(allEffects())`,
>>`sjPlot::plot_model()`, `emmeans::emmip()`  ) to plot the predictions of a
>>say rma.mv() model?
>>
>>For example, is it possible to plot the interaction effect below?
>>
>>library(metafor)