r - Metafor: Error with mlab in the forest function while passing CI bounds from df - Stack Overflow

admin2025-04-25  2

I am working with vaccine effectiveness (VE) data and have the point estimates along with their confidence intervals (CI) in my df. I am trying to create a forest plot using the metafor package in R in the RevMan style, while passing the CI bounds from my dataset. However, I get the error "mlab" is not a graphical parameter when trying to get the mlab polygon to show up in the plot.

A reproducible example is below.

library(metafor)

dat <- data.frame(author = c("Amore-Coffea", "Deliciozza", "Kahve-Paradiso"),
                  year   = c(2000, 2004, 2002),
                  ve     = c(0.9, 0.85, 0.92),
                  ci_ll    = c(0.7, 0.7, 0.9),
                  ci_ul     = c(0.98, 0.9, 0.95))
                  
dat <- escalc(measure = "RR",              
              yi = log(1 - dat$ve),
              sei = (log(1 - dat$ci_ul) - log(1 - dat$ci_ll)) / (2 * 1.96),
              data = dat)
                  
res <- rma(yi, vi, data=dat, method="DL")
                  
sav <- forest(dat$ve, ci.lb=dat$ci_ll, ci.ub=dat$ci_ul, 
              slab = paste(dat$author, dat$year, sep = ", "),
              transf = function(x) x * 100,
              at = c(0, 25, 50, 75, 100),
              xlim = c(-200, 110), 
              xlab="", 
              efac=c(0,4), 
              textpos=c(-200,-25), 
              lty=c(1,1,0), 
              refline=NA,
              cex=0.78, 
              header=c("Study", "IV, Random, 95% CI"), 
              mlab="")

Is there a way to make mlab work in the forest function or should I be using addpoly? However, with addpoly, then the polygon shows up underneath the effect measure bar.

I am working with vaccine effectiveness (VE) data and have the point estimates along with their confidence intervals (CI) in my df. I am trying to create a forest plot using the metafor package in R in the RevMan style, while passing the CI bounds from my dataset. However, I get the error "mlab" is not a graphical parameter when trying to get the mlab polygon to show up in the plot.

A reproducible example is below.

library(metafor)

dat <- data.frame(author = c("Amore-Coffea", "Deliciozza", "Kahve-Paradiso"),
                  year   = c(2000, 2004, 2002),
                  ve     = c(0.9, 0.85, 0.92),
                  ci_ll    = c(0.7, 0.7, 0.9),
                  ci_ul     = c(0.98, 0.9, 0.95))
                  
dat <- escalc(measure = "RR",              
              yi = log(1 - dat$ve),
              sei = (log(1 - dat$ci_ul) - log(1 - dat$ci_ll)) / (2 * 1.96),
              data = dat)
                  
res <- rma(yi, vi, data=dat, method="DL")
                  
sav <- forest(dat$ve, ci.lb=dat$ci_ll, ci.ub=dat$ci_ul, 
              slab = paste(dat$author, dat$year, sep = ", "),
              transf = function(x) x * 100,
              at = c(0, 25, 50, 75, 100),
              xlim = c(-200, 110), 
              xlab="", 
              efac=c(0,4), 
              textpos=c(-200,-25), 
              lty=c(1,1,0), 
              refline=NA,
              cex=0.78, 
              header=c("Study", "IV, Random, 95% CI"), 
              mlab="")

Is there a way to make mlab work in the forest function or should I be using addpoly? However, with addpoly, then the polygon shows up underneath the effect measure bar.

Share Improve this question asked Jan 16 at 13:50 Chia-Yuan ChangChia-Yuan Chang 331 silver badge2 bronze badges 2
  • 1 Thanks for the well formatted question and welcome to StackOverflow. I believe you want to call forest() on res and not on dat$ve. Right now, you are just passing a vector of effect sizes to forest() but if you pass res which is an object of class rma, it will use the forest.rma method which will allow you to supply the mlab argument among others. mlab is not an argument of the default method for forest when a vector is passed as the first argument, but it is when a rma object is passed. For example try forest(res, mlab = 'Grand mean') – qdread Commented Jan 16 at 13:52
  • Thanks, @qdread! I do realize I can pass res through forest(). However, based on a previous post, when I pass the CIs in res and backtransform, the CIs are shown in a t-distribution, and different from the values in my data that I intend to present. This is why i found it necessary to use dat$ve and not res. – Chia-Yuan Chang Commented Jan 16 at 17:29
Add a comment  | 

1 Answer 1

Reset to default 0

You are passing estimates to the forest() function, in which case forest.default() will be called. It does not have an mlab argument (since there won't be a pooled estimate, there is no point in having a label for it). So you should remove mlab="" from your call to forest(). Instead, you should make a bit of extra space at the bottom of the plot with ylim=c(-2,6) and then add the summary estimate with addpoly(res, row=-1, transf = function(x) (1-exp(x)) * 100).

转载请注明原文地址:http://anycun.com/QandA/1745528616a90801.html