Search code examples
rplotstatisticsmetafor

metafor: omitting studies in a forest plot


I want to omit some studies with huge standard errors from a forest plot because they make difficult its interpretation. But I don't want to change the estimation. Below a toy example:

### load BCG vaccine data
data(dat.bcg)

### meta-analysis of the log relative risks using a random-effects model
res <- rma(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg,
           slab=paste(author, year, sep=", "))

### Let's say I want to omit the first study, the rows argument doesn't work as expected
forest(res, rows = c(2:13))

Error in forest.rma(res, rows = c(2:13)) : 
Number of outcomes does not correspond to the length of the 'rows' argument.

Any ideas?


Solution

  • You can construct the forest plot with forest(), passing the estimates and corresponding sampling variances to the function. Using the subset argument, you can omit studies you do not want to include in the plot. Then add the summary estimate based on the model (using the full dataset) to the plot with addpoly(). Using the toy example:

    ### load BCG vaccine data
    data(dat.bcg)
    
    ### load BCG vaccine data
    data(dat.bcg)
    
    ### calculate log relative risks and corresponding sampling variances
    dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, 
                  data=dat.bcg, slab=paste(author, year, sep=", "))
    
    ### meta-analysis of the log relative risks using a random-effects model
    res <- rma(yi, vi, data=dat)
    res
    
    ### forest plot of all studies
    forest(dat$yi, dat$vi, ylim=c(-1.5,16))
    addpoly(res, row=-1)
    abline(h=0)
    
    ### forest plot omitting 1st study
    forest(dat$yi, dat$vi, ylim=c(-1.5,15), subset=-1)
    addpoly(res, row=-1)
    abline(h=0)