Package 'mrsensemakr'

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

Help Index


Sensitivity Analysis for Mendelian Randomization

Description

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.

Usage

mr_sensemakr(
  outcome,
  exposure,
  instrument,
  covariates = NULL,
  data,
  benchmark_covariates = NULL,
  k = 1,
  alpha = 0.05
)

Arguments

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 covariates argument. The user has two options: (i) character vector of the names of covariates that will be used to bound the plausible strength of the unobserved confounders. Each variable will be considered separately; (ii) a named list with character vector names of covariates that will be used, as a group, to bound the plausible strength of the unobserved confounders. The names of the list will be used for the benchmark labels.

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

Value

An object of class mr_sensemakr, which is a list containing:

info

A list with the outcome, exposure, instrument, covariates, alpha level, and missing data information.

exposure

A list with the first-stage regression model, sensitivity statistics, and (if benchmarks provided) bounds on the bias.

outcome

A list with the reduced-form regression model, sensitivity statistics, and (if benchmarks provided) bounds on the bias.

mr

An object of class trad.mr with the traditional MR (2SLS) estimates.

Examples

## 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))

Sensitivity contour plots for MR analysis

Description

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).

Usage

## 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,
  ...
)

Arguments

x

an object of class mr_sensemakr.

type

character. Whether to plot the sensitivity contours for the "outcome" (reduced-form) or "exposure" (first-stage) regression. Default is "outcome".

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 NULL, uses the alpha from the original mr_sensemakr call.

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.

Value

Invisibly returns a list with contour data, bounds, and graphical parameters.


Print results of MR sensitivity analysis

Description

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.

Usage

## S3 method for class 'mr_sensemakr'
print(x, digits = 2, ...)

Arguments

x

an object of class mr_sensemakr.

digits

number of digits to round results to.

...

additional arguments passed to other print methods.

Value

The function is called for its side effect of printing to the console. Invisibly returns the input x.


Simulated Data for MR Sensitivity Analysis

Description

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.

Format

A data frame with 200,000 observations and 27 variables:

out.trait

Outcome trait.

exp.trait

Exposure trait.

prs

Polygenic risk score used as a genetic instrument.

age

Age of the individual.

sex

Sex of the individual.

alcohol

Alcohol consumption (putative pleiotropic pathway).

smoking

Smoking status (putative pleiotropic pathway).

pc1, pc2, pc3, pc4, pc5, pc6, pc7, pc8, pc9, pc10, pc11, pc12, pc13, pc14, pc15, pc16, pc17, pc18, pc19, pc20

Genomic principal components 1 through 20.