mr_forestplot: Mendelian Randomization forest plot

mr_forestplotR Documentation

Mendelian Randomization forest plot

Description

Mendelian Randomization forest plot

Usage

mr_forestplot(dat, sm = "", title = "", ...)

Arguments

dat

A data.frame with outcome id, effect size and standard error.

sm

Summary measure such as OR, RR, MD.

title

Title of the meta-analysis.

...

Additional arguments passed to meta::forest().

Details

Wrapper around meta::forest() for multi-outcome Mendelian Randomization. Works for binary and continuous outcomes, with or without summary statistics.

Examples

## Not run: 
## Example data -----------------------------------------------------------
tnfb <- '
             "multiple sclerosis"  0.69058600 0.059270400
   "systemic lupus erythematosus"  0.76687500 0.079000500
         "sclerosing cholangitis"  0.62671500 0.075954700
  "juvenile idiopathic arthritis" -1.17577000 0.160293000
                      "psoriasis"  0.00582586 0.000800016
           "rheumatoid arthritis" -0.00378072 0.000625160
     "inflammatory bowel disease" -0.14334200 0.025272500
         "ankylosing spondylitis" -0.00316852 0.000626225
                 "hypothyroidism" -0.00432054 0.000987324
              "allergic rhinitis"  0.00393075 0.000926002
         "IgA glomerulonephritis" -0.32696600 0.105262000
                  "atopic eczema" -0.00204018 0.000678061
'

tnfb <- as.data.frame(scan(file = textConnection(tnfb), what = list("",0,0)))
names(tnfb) <- c("outcome","Effect","StdErr")
tnfb$outcome <- gsub("\\b(^[a-z])","\\U\\1", tnfb$outcome, perl = TRUE)


## 1) Default meta-style forest plot (b, SE, CI + weights) ----------------
mr_forestplot(
  tnfb,
  colgap.forest.left = "0.05cm",
  fontsize = 14,
  leftcols  = c("studlab","effect","seTE","ci"),
  leftlabs  = c("Outcome","b","SE","95% CI"),
  rightcols = c("w.common","w.random"),
  rightlabs = c("Weight (FE)","Weight (RE)"),
  common = FALSE, random = FALSE,
  print.I2 = FALSE, print.pval.Q = FALSE, print.tau2 = FALSE,
  spacing = 1.6, digits.TE = 2, digits.seTE = 2
)


## 2) MR summary (OR + CI only) -------------------------------------------
mr_forestplot(
  tnfb,
  sm = "OR",
  backtransf = TRUE,
  colgap.forest.left = "0.05cm",
  fontsize = 14,
  leftcols  = "studlab",
  leftlabs  = "Outcome",
  rightcols = c("effect","ci"),
  rightlabs = c("OR","95% CI"),
  sortvar = tnfb$Effect,
  common = FALSE, random = FALSE,
  print.I2 = FALSE, print.pval.Q = FALSE, print.tau2 = FALSE,
  spacing = 1.6
)


## 3) MR summary with P-values --------------------------------------------
mr_forestplot(
  tnfb,
  sm = "OR",
  backtransf = TRUE,
  colgap.forest.left = "0.05cm",
  fontsize = 14,
  leftcols  = "studlab",
  leftlabs  = "Outcome",
  rightcols = c("effect","ci","pval"),
  rightlabs = c("OR","95% CI","P"),
  digits = 3, digits.pval = 2, scientific.pval = TRUE,
  sortvar = tnfb$Effect,
  common = FALSE, random = FALSE,
  print.I2 = FALSE, print.pval.Q = FALSE, print.tau2 = FALSE,
  addrow = TRUE,
  spacing = 1.6
)

## End(Not run)

gap documentation built on May 28, 2026, 9:07 a.m.