Search code examples
rplotmetafor

Bivariate model and 'predict.rma()' function ('metafor' package)


Suppose I have the following model result:

> summary(msa_res@objects[[1]])

Model Results:

         estimate      se     zval    pval    ci.lb    ci.ub     
intrcpt    0.9397  0.0667  14.0850  <.0001   0.8090   1.0705  ***
MAT_e     -0.0079  0.0035  -2.2691  0.0233  -0.0147  -0.0011    *
Naddl     -0.0385  0.0133  -2.9005  0.0037  -0.0645  -0.0125   **

I want to plot regression lines using the predict function for MAT_e and Naddl moderators:

preds_MAT_e <- predict(msa_res@objects[[1]], newmods=c(-5:30))
preds_Naddl <- predict(msa_res@objects[[1]], newmods=c(1:6))

But I get this type of error:

Error in predict.rma(msa_res@objects[[1]], newmods = c(-5:30)) : 
  Dimensions of 'newmods' do not match dimensions of the model.

I guess this is because I am not specifying which moderator should be considered by predict() function. Note that the function above works fine for univariate models e.g. with MAT_e only.


Solution

  • When you have two predictors, you need to specify values for both predictors. So, for example:

    predict(msa_res@objects[[1]], newmods=cbind(-5:30, 1))
    

    or

    predict(msa_res@objects[[1]], newmods=cbind(10, 1:6))
    

    So you can hold one predictor constant while varying the other.