Package 'MVMR'

Title: MVMR
Description: An R package for performing multivariable Mendelian randomization analyses.
Authors: Wes Spiller [aut] (ORCID: <https://orcid.org/0000-0002-8169-5531>), Jack Bowden [aut] (ORCID: <https://orcid.org/0000-0003-2628-3304>), Eleanor Sanderson [aut] (ORCID: <https://orcid.org/0000-0001-5188-5775>), Tom Palmer [aut, cre] (ORCID: <https://orcid.org/0000-0003-4655-4511>)
Maintainer: Tom Palmer <[email protected]>
License: GPL-3
Version: 0.4.9
Built: 2026-10-19 10:25:05 UTC
Source: https://github.com/WSpiller/MVMR

Help Index


format_mvmr

Description

Reads in summary data. Checks and organises columns for use in calculating multivariable Mendelian Randomization analyses. Where variant IDs are not provided, a vector is generated for variant identification.

Usage

format_mvmr(BXGs, BYG, seBXGs, seBYG, RSID)

Arguments

BXGs

A matrix containing beta-coefficient values for genetic associations with each exposure. Columns should indicate exposure number, with rows representing estimates for a given genetic variant.

BYG

A numeric vector of beta-coefficient values for genetic associations with the outcome.

seBXGs

A matrix containing standard errors corresponding to the matrix of beta-coefficients BXGs.

seBYG

A numeric vector of standard errors corresponding to the beta-coefficients BYG.

RSID

A vector of names for genetic variants included in the analysis. If variant IDs are not provided a vector of ID numbers will be generated.

Value

A formatted data frame of class mvmr_format.

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Examples

r_input <- format_mvmr(
  BXGs = rawdat_mvmr[, c("LDL_beta", "HDL_beta")],
  BYG = rawdat_mvmr$SBP_beta,
  seBXGs = rawdat_mvmr[, c("LDL_se", "HDL_se")],
  seBYG = rawdat_mvmr$SBP_se,
  RSID = rawdat_mvmr$SNP
)
names(r_input)
class(r_input)

ivw_mvmr

Description

Fits an IVW multivariable Mendelian randomization model using first order weights.

Usage

ivw_mvmr(r_input, gencov = 0)

Arguments

r_input

A formatted data frame using the format_mvmr() function or an object of class MRMVInput from MendelianRandomization::mr_mvinput()

gencov

Retained for interface consistency with the other MVMR functions. The IVW point estimates do not depend on the covariance between the effect of the genetic variants on each exposure, so this argument is not used by ivw_mvmr(). A value of 0 is used by default.

Value

A dataframe containing MVMR results, including estimated coefficients, their standard errors, t-statistics, and corresponding (two-sided) p-values.

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Examples

r_input <- format_mvmr(
  BXGs = rawdat_mvmr[, c("LDL_beta", "HDL_beta")],
  BYG = rawdat_mvmr$SBP_beta,
  seBXGs = rawdat_mvmr[, c("LDL_se", "HDL_se")],
  seBYG = rawdat_mvmr$SBP_se,
  RSID = rawdat_mvmr$SNP
)
ivw_mvmr(r_input)

Convert an object of class MRMVInput from the MendelianRandomization package to the MVMR mvmr_format class

Description

Creates a data.frame with additional class mvmr_format from an object of class MRMVInput generated by MendelianRandomization::mr_mvinput().

Usage

mrmvinput_to_mvmr_format(dat)

Arguments

dat

Object from MendelianRandomization::mr_mvinput().

Value

Object of class mvmr_format, the MVMR format

Examples

if (require("MendelianRandomization", quietly = TRUE)) {
  bx <- as.matrix(rawdat_mvmr[, c("LDL_beta", "HDL_beta")])
  bxse <- as.matrix(rawdat_mvmr[, c("LDL_se", "HDL_se")])
  dat <- MendelianRandomization::mr_mvinput(
    bx = bx,
    bxse = bxse,
    by = rawdat_mvmr$SBP_beta,
    byse = rawdat_mvmr$SBP_se,
    snps = rawdat_mvmr$SNP
  )
  dat <- mrmvinput_to_mvmr_format(dat)
  head(dat)
  class(dat)
}

mvmr (legacy)

Description

Note: This function is from the old version of the MVMR package and will be replaced in the future: The gencov argument should be set to zero when using mvmr().

Usage

mvmr(r_input, gencov, weights)

Arguments

r_input

A formatted data frame using the format_mvmr() function or an object of class MRMVInput from MendelianRandomization::mr_mvinput()

gencov

Calculating heterogeneity statistics requires the covariance between the effect of the genetic variants on each exposure to be known. This can either be estimated from individual level data, be assumed to be zero, or fixed at zero using non-overlapping samples of each exposure GWAS. A value of 0 is used by default.

weights

A value specifying the inverse variance weights used to calculate IVW estimate and Cochran's Q statistic. Currently only first order weights are available (1).

Details

Fits an IVW multivariable Mendelian randomization model using first order weights. The function returns an object of class "MVMRIVW", containing regression estimates, estimated heterogeneity as a measure of instrument strength (Q_strength), and estimated heterogeneity as a measure of instrument validity (Q_valid).

Value

An object of class "MVMRIVW" containing the following components:

summary

A summary of the MVMR regression model, including estimated coefficients, standard errors, t-statistics, p-values, and heterogeneity statistics.

coef

The estimated coefficients, their standard errors, t-statistics, and corresponding (two-sided) p-values.

Q_strength

A data frame displaying modified Cochran's Q statistics for assessing instrument strength with respect to each exposure. The Q-statistic increases proportionally with instrument strength, and analogous to univariate MR analyses, a value equal to or greater than 10 can be used as a minimum threshold for instrument strength. Note that for these statistics it is not informative to evaluate p-values.

Q_valid

A modified form of Cochran's Q statistic measuring heterogeneity in causal effect estimates obtained using each genetic variant. Observed heterogeneity is indicative of a violation of the exclusion restriction assumption in MR (validity), which can result in biased effect estimates.

p_valid

A p-value corresponding to the heterogeneity measure for instrument validity (Q_valid)

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Examples

# Example using format_mvmr formatted data
r_input <- format_mvmr(
  BXGs = rawdat_mvmr[, c("LDL_beta", "HDL_beta")],
  BYG = rawdat_mvmr$SBP_beta,
  seBXGs = rawdat_mvmr[, c("LDL_se", "HDL_se")],
  seBYG = rawdat_mvmr$SBP_se,
  RSID = rawdat_mvmr$SNP
)
mvmr(r_input, 0, 1)

# Example using MRMVInput formatted data from the MendelianRandomization package
if (require("MendelianRandomization", quietly = TRUE)) {
  bx <- as.matrix(rawdat_mvmr[, c("LDL_beta", "HDL_beta")])
  bxse <- as.matrix(rawdat_mvmr[, c("LDL_se", "HDL_se")])
  dat <- MendelianRandomization::mr_mvinput(
    bx = bx,
    bxse = bxse,
    by = rawdat_mvmr$SBP_beta,
    byse = rawdat_mvmr$SBP_se,
    snps = rawdat_mvmr$SNP
  )
  mvmr(r_input = r_input, gencov = 0, weights = 1)
}

phenocov_mvmr

Description

Uses an external phenotypic covariance matrix and summary data to estimate covariance matrices for estimated effects of individual genetic variants on each exposure. The phenotypic covariance matrix should be constructed using standardised phenotype measures. The function returns a number of covariance matrices equal to the number of SNPs, where SNP and row numbers reference ordered exposures.

Usage

phenocov_mvmr(pcor, seBXGs)

Arguments

pcor

A phenotypic correlation matrix using exposures, constructed using individual level exposure data. Columns should be ordered by exposure so as to match format_mvmr().

seBXGs

A matrix containing standard errors corresponding in relation to the gene-exposure association for each SNP.

Value

A list of covariance matrices with respect to each genetic variant, retaining the ordering in seBXGs

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Examples

## Not run: 
phenocov_mvmr(pcor, summarydata[,c(3,4)])

## End(Not run)

pleiotropy_mvmr

Description

Calculates modified form of Cochran's Q statistic measuring heterogeneity in causal effect estimates obtained using each genetic variant. Observed heterogeneity is indicative of a violation of the exclusion restriction assumption in MR (validity), which can result in biased effect estimates. The function takes a formatted dataframe as an input, obtained using the function format_mvmr(). Additionally, covariance matrices for estimated effects of individual genetic variants on each exposure can also be provided. These can be estimated using external data by applying the snpcov_mvmr() or phenocov_mvmr() functions, are input manually. The function returns a dataframe including the conditional Q-statistic for instrument validity, and a corresponding P-value.

Usage

pleiotropy_mvmr(r_input, gencov = 0, estimator = c("ivw", "qmin"))

Arguments

r_input

A formatted data frame using the format_mvmr() function or an object of class MRMVInput from MendelianRandomization::mr_mvinput()

gencov

Calculating heterogeneity statistics requires the covariance between the effect of the genetic variants on each exposure to be known. This can either be estimated from individual level data, be assumed to be zero, or fixed at zero using non-overlapping samples of each exposure GWAS. A value of 0 is used by default.

estimator

The causal effect estimates at which the Q-statistic is evaluated: "ivw" (the default) for the inverse variance weighted estimates, or "qmin" for the estimates that minimise the Q-statistic.

Details

By default the Q-statistic is evaluated at the inverse variance weighted (IVW) estimates of the causal effects and compared with a chi-squared distribution on L - K degrees of freedom, where L is the number of genetic variants and K the number of exposures. This is the Q-statistic for heterogeneity in MVMR described in Sanderson, Spiller and Bowden (2021). It is not robust to weak instruments and will be inflated when the instruments are conditionally weak, so instrument strength should first be assessed with strength_mvmr(); if the instruments are weak the results should not be interpreted. Setting estimator = "qmin" instead evaluates the Q-statistic at the causal effect estimates that minimise it, which are robust to weak instruments, as discussed in Section 3.2 of Sanderson, Spiller and Bowden (2021).

Value

A Q-statistic for instrument validity and the corresponding p-value

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Sanderson, E., Spiller, W., and Bowden, J., Testing and correcting for weak and pleiotropic instruments in two-sample multivariable Mendelian randomization. Statistics in Medicine, 2021, 40, 25, 5434–5452. doi:10.1002/sim.9133

Examples

## Not run: 
pleiotropy_mvmr(r_input, covariances)

## End(Not run)

qhet_mvmr

Description

Fits a multivariable Mendelian randomization model adjusting for weak instruments. The functions requires a formatted dataframe using the format_mvmr() function, as well a phenotypic correlation matrix pcor. This should be obtained from individual level phenotypic data, or constructed as a correlation matrix where correlations have previously been reported. By default, confidence intervals are not produced but can be calculated by setting CI = TRUE. They are calculated using either a non-parametric bootstrap over the genetic variants (CI_method = "bootstrap", the default), with the number of bootstrap iterations specified using the iterations argument, or a leave-one-variant-out jackknife (CI_method = "jackknife"). Sanderson, Spiller and Bowden (2021) recommend the jackknife, as with a moderate number of variants bootstrap resamples can give very weak instruments. Note that calculating confidence intervals can take a substantial amount of time.

Usage

qhet_mvmr(
  r_input,
  pcor,
  CI,
  iterations,
  ncores = parallelly::availableCores(omit = 1),
  CI_method = c("bootstrap", "jackknife")
)

Arguments

r_input

A formatted data frame using the format_mvmr() function or an object of class MRMVInput from MendelianRandomization::mr_mvinput()

pcor

A phenotypic correlation matrix including the correlation between each exposure included in the MVMR analysis. It is used to construct the covariance between the estimated effects of each genetic variant on each exposure, as pcor multiplied by the outer product of the variant's standard errors. This is appropriate when the exposure GWAS were estimated in the same sample. If the exposure GWAS were estimated in non-overlapping samples these covariances are zero, and the identity matrix diag(K), where K is the number of exposures, should be supplied instead.

CI

Indicates whether 95 percent confidence intervals should be calculated.

iterations

Specifies number of bootstrap iterations for calculating 95 percent confidence intervals. Not used when CI_method = "jackknife".

ncores

Number of cores to use for parallel processing in the bootstrap or jackknife. Default is parallelly::availableCores(omit = 1). On Windows, this is automatically set to 1 regardless of user input. It is recommended to only set this to a maximum of parallelly::availableCores(omit = 1).

CI_method

Method used to calculate confidence intervals when CI = TRUE: "bootstrap" (the default) for bias-corrected and accelerated (BCa) non-parametric bootstrap intervals, or "jackknife" for normal-based intervals using the leave-one-variant-out jackknife standard error.

Details

Effects are estimated by minimising a Q-statistic that includes an additive heterogeneity parameter tau-squared. Following Sanderson, Spiller and Bowden (2021), tau-squared is chosen so that the minimised Q-statistic equals L - K, where L is the number of genetic variants and K the number of exposures. Tau-squared is constrained to be non-negative, and is fixed at zero when the minimised Q-statistic without heterogeneity is already no greater than L - K.

Value

A dataframe containing effect estimates with respect to each exposure, and when CI = TRUE their 95 percent confidence intervals. With CI_method = "jackknife" the jackknife standard errors are also returned.

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Sanderson, E., Spiller, W., and Bowden, J., Testing and correcting for weak and pleiotropic instruments in two-sample multivariable Mendelian randomization. Statistics in Medicine, 2021, 40, 25, 5434–5452. doi:10.1002/sim.9133

Examples

## Not run: 
qhet_mvmr(r_input, pcor, CI = TRUE, iterations = 1000)
qhet_mvmr(r_input, pcor, CI = TRUE, CI_method = "jackknife")

## End(Not run)

Raw multivariable MR summary data using lipid fractions as exposures and systolic blood pressure as an outcome.

Description

A dataset containing summary data on 145 genetic variants associated with either low-density lipoprotein (LDL), high-density lipoprotein (HDL), or triglycerides. Data includes variant rsid numbers, associations with each lipid fraction, the associations between genetic variants and systolic blood pressure, and corresponding standard errors.

Usage

rawdat_mvmr

Format

A data frame with 145 rows and 9 variables. A full description of the data is available by using the command vignette("MVMR").

Details

rawdat_mvmr

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

Source


snpcov_mvmr

Description

Uses individual level genetic and exposure data to generate covariance matrices for estimated effects of individual genetic variants on each exposure. The function returns a number of covariance matrices equal to the number of SNPs, where SNP and row numbers reference ordered exposures.

Usage

snpcov_mvmr(Gs, Xs)

Arguments

Gs

A matrix or dataframe containing genetic instrument measures. Columns should indicate genetic variant number, with rows representing an observed measure of the genetic variant.

Xs

A matrix or dataframe containing exposure measures. Columns should indicate exposure number, with rows representing an observed measure for the given exposure.

Value

A list of covariance matrices with respect to each genetic variant, retaining the ordering in Gs

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. doi:10.1093/ije/dyy262

Examples

## Not run: 
snpcov_mvmr(data[,1:10], data[,11:13])

## End(Not run)

strength_mvmr

Description

Calculates the conditional F-statistic for assessing instrument strength in two sample summary multivariable Mendelian randomization. The function takes a formatted dataframe as an input, obtained using the function format_mvmr(). Additionally, covariance matrices for estimated effects of individual genetic variants on each exposure can also be provided. These can be estimated using external data by applying the snpcov_mvmr() or phenocov_mvmr() functions, or are input manually. The function returns a dataframe including the conditional F-statistic with respect to each exposure. A conventional F-statistic threshold of 10 is used in basic assessments of instrument strength.

Usage

strength_mvmr(r_input, gencov = 0)

Arguments

r_input

A formatted data frame using the format_mvmr() function or an object of class MRMVInput from MendelianRandomization::mr_mvinput()

gencov

Calculating heterogeneity statistics requires the covariance between the effect of the genetic variants on each exposure to be known. This can either be estimated from individual level data, be assumed to be zero, or fixed at zero using non-overlapping samples of each exposure GWAS. A value of 0 is used by default.

Value

A dataframe showing the conditional F-statistic for each exposure.

Author(s)

Wes Spiller; Eleanor Sanderson; Jack Bowden.

References

Sanderson, E., et al., An examination of multivariable Mendelian randomization in the single-sample and two-sample summary data settings. International Journal of Epidemiology, 2019, 48, 3, 713–727. Available from: doi:10.1093/ije/dyy262

Sanderson, E., Spiller, W., and Bowden, J., Testing and correcting for weak and pleiotropic instruments in two-sample multivariable Mendelian randomization. Statistics in Medicine, 2021, 40, 25, 5434–5452. doi:10.1002/sim.9133

Examples

## Not run: 
strength_mvmr(data, covariances)

## End(Not run)