wviechtb/metafor

Forest plot for WMD a la RevMan style

apavlo89 opened this issue · 1 comments

Can anyone help with creating a mean differences forest plot that has RevMan style (without the risk of bias stuff preferably)?

I am trying to use this code and modify it for mean differences but I completely suck at plotting... This is first time using R I use python :/ https://www.metafor-project.org/doku.php/plots:forest_plot_revman

This is the code I've created up to now which I think is correct however the plot is all jumbled up - note I haven't changed description names yet from the example

`library(jmv)
library(haven)
library(jmvReadWrite)
library(jmvconnect)
library(metafor)

Load dataset

dat <- read.csv('Blood loss - Laparoscopy VS Laparotomy.csv')

n1i <- dat[["n1i"]]
m1i <- dat[["m1i"]]
sd1i <- dat[["sd1i"]]
n2i <- dat[["n2i"]]
m2i <- dat[["m2i"]]
sd2i <- dat[["sd2i"]]
author <- dat[["author"]]
year <- dat[["year"]]

calculate log Risk Ratios and corresponding sampling variances (and use

the 'slab' argument to store study labels as part of the data frame)

dat <- escalc(measure="MD", n1i=n1i,m1i=m1i, sd1i=sd1i,n2i=n2i,m2i=m2i, sd2i=sd2i,data=dat,
slab=paste(author, year), drop00=TRUE)
dat

note: using drop00=TRUE to leave the log Risk Ratio missing for the study

with no events in either group (note the NAs for study 3)

fit random-effects model (using DL estimator as RevMan does)

res <- rma(yi, vi, data=dat, method="REML")
res

estimated average Risk Ratio (and 95% CI/PI)

pred <- predict(res, transf=exp, digits=2)
pred

############################################################################

need the rounded estimate and CI bounds further below

pred <- formatC(c(pred$pred, pred$ci.lb, pred$ci.ub), format="f", digits=2)

total number of studies

k <- nrow(dat)

set na.action to "na.pass" (instead of the default, which is "na.omit"),

so that even study 3 (with a missing log Risk Ratio) will be shown in the

forest plot

options(na.action = "na.pass")

get the weights and format them as will be used in the forest plot

weights <- paste0(formatC(weights(res), format="f", digits=1), "%")
weights[weights == "NA%"] <- ""

adjust the margins

par(mar=c(10.8,0,1.3,1.3), mgp=c(3,0.2,0), tcl=-0.2)`

This is not the right place to ask for help (the Issues here are for making bug reports). For ways to obtain help with the metafor package, see: https://www.metafor-project.org/doku.php/help