run_mr_analysis: Run MR Analysis for Multiple Outcomes

View source: R/mr_workflows.R

run_mr_analysisR Documentation

Run MR Analysis for Multiple Outcomes

Description

Performs causal inference analysis using multiple Mendelian Randomization (MR) methods across one or more outcomes and exposures. Returns a combined results data frame. To save the output, use standard R functions such as write.csv() or saveRDS() on the returned object.

Usage

run_mr_analysis(
  MR_input_data,
  outcome.form = NULL,
  use_ivw = TRUE,
  use_raps = TRUE,
  use_median = TRUE,
  use_egger = TRUE,
  use_mr_presso = TRUE,
  use_mr_horse = TRUE,
  use_mr_grip = TRUE,
  NbDistribution = 1000,
  SignifThreshold = 0.05,
  mr_horse_n_iter = 5000,
  mr_horse_n_burnin = 1000,
  mr_grip_parameters = NULL
)

Arguments

MR_input_data

Harmonised MR input data frame. Must contain Outcome and Exposure columns.

outcome.form

Character vector indicating the effect scale for each outcome: "Beta", "OR" (odds ratio), or "HR" (hazard ratio). A single value is recycled across all outcomes. Defaults to "Beta".

use_ivw

Logical; whether to run the Inverse Variance Weighted (IVW) method. Default is TRUE.

use_raps

Logical; whether to run the Robust Adjusted Profile Score (MR-RAPS) method. Default is TRUE.

use_median

Logical; whether to run the Weighted Median method. Default is TRUE.

use_egger

Logical; whether to run MR-Egger regression. Default is TRUE.

use_mr_presso

Logical; whether to run the Mendelian Randomization Pleiotropy RESidual Sum and Outlier (MR-PRESSO) method. Default is TRUE.

use_mr_horse

Logical; whether to run the MR-Horse method. Default is TRUE.

use_mr_grip

Logical; whether to run the Generalized Regression with Instrument Pairs (MR-GRIP) method. Default is TRUE.

NbDistribution

Integer; number of simulated distributions for MR-PRESSO. Default is 1000.

SignifThreshold

Numeric; significance threshold for the MR-PRESSO outlier test. Default is 0.05.

mr_horse_n_iter

Integer; number of Markov chain Monte Carlo (MCMC) iterations for MR-Horse. Default is 5000.

mr_horse_n_burnin

Integer; number of MCMC burn-in samples for MR-Horse. Default is 1000.

mr_grip_parameters

Accepted for API compatibility; not used by MR-GRIP.

Value

A data frame combining results across all outcomes and exposures. Each row represents one outcome-exposure pair. Columns include estimates, confidence intervals (CI), and p-values for each method, together with diagnostic flags (e.g., F-statistic below 10, significant heterogeneity). Use write.csv() or saveRDS() to save the returned object.

Examples

data("fi_49item")
input1 <- harmonize_mr_data(df = fi_49item)$input_df
outcome1 <- run_mr_analysis(
  MR_input_data     = input1,
  outcome.form      = "Beta",
  use_ivw           = TRUE,
  use_raps          = FALSE,
  use_median        = FALSE,
  use_egger         = FALSE,
  use_mr_presso     = FALSE,
  use_mr_horse      = FALSE,
  use_mr_grip       = FALSE,
  NbDistribution    = 1000,
  SignifThreshold   = 0.05,
  mr_horse_n_iter   = 5000,
  mr_horse_n_burnin = 1000,
  mr_grip_parameters = NULL
)


data("fried_frailty")
input2 <- harmonize_mr_data(df = fried_frailty)$input_df
outcome2 <- run_mr_analysis(
  MR_input_data     = input2,
  outcome.form      = "OR",
  use_ivw           = TRUE,
  use_raps          = TRUE,
  use_median        = TRUE,
  use_egger         = TRUE,
  use_mr_presso     = TRUE,
  use_mr_horse      = TRUE,
  use_mr_grip       = TRUE,
  NbDistribution    = 1000,
  SignifThreshold   = 0.05,
  mr_horse_n_iter   = 5000,
  mr_horse_n_burnin = 1000,
  mr_grip_parameters = NULL
)



data("merged_data")
input3 <- harmonize_mr_data(df = merged_data)$input_df
outcome3 <- run_mr_analysis(
  MR_input_data     = input3,
  outcome.form      = c("Beta","OR"), ## First outcome use Beta and second outcome use OR
  use_ivw           = TRUE,
  use_raps          = TRUE,
  use_median        = TRUE,
  use_egger         = TRUE,
  use_mr_presso     = TRUE,
  use_mr_horse      = TRUE,
  use_mr_grip       = TRUE,
  NbDistribution    = 1000,
  SignifThreshold   = 0.05,
  mr_horse_n_iter   = 5000,
  mr_horse_n_burnin = 1000,
  mr_grip_parameters = NULL
)


autoMR documentation built on June 12, 2026, 9:07 a.m.