| Title: | Sensitivity Analysis Tools for Mendelian Randomization |
|---|---|
| Description: | Implements sensitivity analysis tools for Mendelian Randomization, as discussed in Cinelli et al. (2020) <doi:10.1101/2020.10.21.347773>. Provides functions for computing sensitivity statistics, robustness values, and bias-adjusted estimates for instrumental variable analyses, along with sensitivity contour plots for visualizing the impact of potential violations of the exclusion restriction. |
| Authors: | Carlos Cinelli [aut, cre] |
| Maintainer: | Carlos Cinelli <[email protected]> |
| License: | GPL-3 |
| Version: | 0.3.0 |
| Built: | 2026-05-13 08:49:14 UTC |
| Source: | https://github.com/carloscinelli/mrsensemakr |
Performs sensitivity analysis for Mendelian Randomization (MR) studies, computing robustness values, partial R-squared measures, and bias-adjusted estimates for instrumental variable regressions. The method assesses how strong residual biases (due to violations of the exclusion restriction) would need to be to invalidate the MR findings.
mr_sensemakr( outcome, exposure, instrument, covariates = NULL, data, benchmark_covariates = NULL, k = 1, alpha = 0.05 )mr_sensemakr( outcome, exposure, instrument, covariates = NULL, data, benchmark_covariates = NULL, k = 1, alpha = 0.05 )
outcome |
A character vector with the name of the outcome trait. |
exposure |
A character vector with the name of the exposure trait. |
instrument |
A character vector with the name of the genetic instrument. |
covariates |
A character vector with the name of the control covariates, such as age, sex, genomic principal components, batch effect dummies and putative pleiotropic pathways. |
data |
An object of the class data.frame containing the variables used in the analysis. |
benchmark_covariates |
Covariates for benchmarking. Must be a subset of the |
k |
numeric vector. Parameterizes how many times stronger residual biases are related to the treatment and the outcome in comparison to the observed benchmark covariates. |
alpha |
significance level |
An object of class mr_sensemakr, which is a list containing:
A list with the outcome, exposure, instrument, covariates, alpha level, and missing data information.
A list with the first-stage regression model, sensitivity statistics, and (if benchmarks provided) bounds on the bias.
A list with the reduced-form regression model, sensitivity statistics, and (if benchmarks provided) bounds on the bias.
An object of class trad.mr with the traditional MR (2SLS) estimates.
## loads package library(mrsensemakr) ## simulated data example data("sim_data") ## create vectors indicating variable names in the data outcome <- "out.trait" # name of outcome trait exposure <- "exp.trait" # name of exposure trait instrument <- "prs" # genetic instrument (e.g, polygenic risk score) age.sex <- c("age", "sex") # age and sex variables (if applicable) alc.smok <- c("alcohol", "smoking") # putative pleoitropic vars. pcs <- paste0("pc", 1:20) # first 20 principal components pc1 ... pc20 ## runs MR sensitivity analysis mr.sense <- mr_sensemakr(outcome = outcome, exposure = exposure, instrument = instrument, covariates = c(age.sex, alc.smok, pcs), data = sim_data, benchmark_covariates = list(alc.smok = alc.smok, pcs = pcs)) ## print results mr.sense ## sensitivity contour plots plot(mr.sense, benchmark_covariates = list(alc.smok = alc.smok, pcs = pcs), k = list(alc.smok = 25, pcs = 35))## loads package library(mrsensemakr) ## simulated data example data("sim_data") ## create vectors indicating variable names in the data outcome <- "out.trait" # name of outcome trait exposure <- "exp.trait" # name of exposure trait instrument <- "prs" # genetic instrument (e.g, polygenic risk score) age.sex <- c("age", "sex") # age and sex variables (if applicable) alc.smok <- c("alcohol", "smoking") # putative pleoitropic vars. pcs <- paste0("pc", 1:20) # first 20 principal components pc1 ... pc20 ## runs MR sensitivity analysis mr.sense <- mr_sensemakr(outcome = outcome, exposure = exposure, instrument = instrument, covariates = c(age.sex, alc.smok, pcs), data = sim_data, benchmark_covariates = list(alc.smok = alc.smok, pcs = pcs)) ## print results mr.sense ## sensitivity contour plots plot(mr.sense, benchmark_covariates = list(alc.smok = alc.smok, pcs = pcs), k = list(alc.smok = 25, pcs = 35))
Produces sensitivity contour plots for the outcome or exposure regressions of a Mendelian Randomization analysis. Contours show the t-value of the instrument coefficient as a function of hypothetical partial R-squared values of unobserved variables with both the instrument and the outcome (or exposure).
## S3 method for class 'mr_sensemakr' plot( x, type = c("outcome", "exposure"), benchmark_covariates = NULL, k = 1, alpha = NULL, nlevels = 7, lim.x = NULL, lim.y = NULL, ... )## S3 method for class 'mr_sensemakr' plot( x, type = c("outcome", "exposure"), benchmark_covariates = NULL, k = 1, alpha = NULL, nlevels = 7, lim.x = NULL, lim.y = NULL, ... )
x |
an object of class |
type |
character. Whether to plot the sensitivity contours for the
|
benchmark_covariates |
covariates for benchmarking. Must be a named list of character vectors specifying groups of covariates to use as benchmarks for bounding the plausible strength of unobserved confounders. |
k |
numeric vector or named list. Parameterizes how many times stronger residual biases are in comparison to the observed benchmark covariates. |
alpha |
significance level for the sensitivity analysis. If |
nlevels |
number of contour levels. |
lim.x |
limit of the x-axis. |
lim.y |
limit of the y-axis. |
... |
additional arguments passed to plotting functions. |
Invisibly returns a list with contour data, bounds, and graphical parameters.
Prints a summary of the Mendelian Randomization sensitivity analysis, including traditional MR estimates, sensitivity statistics for the exposure and outcome regressions, and (if available) benchmark bounds.
## S3 method for class 'mr_sensemakr' print(x, digits = 2, ...)## S3 method for class 'mr_sensemakr' print(x, digits = 2, ...)
x |
an object of class |
digits |
number of digits to round results to. |
... |
additional arguments passed to other print methods. |
The function is called for its side effect of printing to the console.
Invisibly returns the input x.
A simulated dataset for illustrating Mendelian Randomization sensitivity analysis. The data contain an outcome trait, an exposure trait, a polygenic risk score (PRS) used as a genetic instrument, demographic covariates, putative pleiotropic pathways, and genomic principal components.
A data frame with 200,000 observations and 27 variables:
Outcome trait.
Exposure trait.
Polygenic risk score used as a genetic instrument.
Age of the individual.
Sex of the individual.
Alcohol consumption (putative pleiotropic pathway).
Smoking status (putative pleiotropic pathway).
Genomic principal components 1 through 20.