Package 'BWMR'

Title: Bayesian Weighted Mendelian Randomization (BWMR)
Description: Inference the causality based on BWMR method.
Authors: Jia Zhao [aut, cre] (ORCID: <https://orcid.org/0000-0002-9107-8852>)
Maintainer: Jia Zhao <[email protected]>
License: GPL (>= 3)
Version: 0.1.1
Built: 2026-05-31 07:23:27 UTC
Source: https://github.com/remlapmot/BWMR

Help Index


Bayesian Weighted Mendelian Randomization

Description

Performs variational EM inference for the BWMR model, estimating the causal effect of an exposure on an outcome using summary-level GWAS data.

Usage

BWMR(gammahat, Gammahat, sigmaX, sigmaY, alpha = 100, sqsigma0 = (1e+06)^2)

Arguments

gammahat

Numeric vector of SNP-exposure effect estimates.

Gammahat

Numeric vector of SNP-outcome effect estimates.

sigmaX

Numeric vector of standard errors for the SNP-exposure effects.

sigmaY

Numeric vector of standard errors for the SNP-outcome effects.

alpha

Numeric scalar; concentration parameter for the Beta prior on the proportion of valid instruments. Default is 100.

sqsigma0

Numeric scalar; prior variance for beta. Default is (1e6)^2, representing a diffuse prior.

Value

A list containing:

beta

Causal effect estimate.

se_beta

Standard error of the causal effect estimate.

P_value

P-value from a chi-squared test (1 df).

weights

Posterior mean weights for each SNP.

tau

Estimate of the pleiotropy noise parameter.

sigma

Estimate of the instrument strength parameter.

mu_pi

Posterior mean of the proportion of valid instruments.

plot1

Scatter plot of SNP effects with error bars (ggplot2).

plot2

ELBO convergence plot (ggplot2).

plot3

Bar chart of posterior mean weights per SNP (ggplot2).

plot4

Weighted scatter plot with regression line (ggplot2).

Examples

data(ExampleData)
result <- BWMR(
  gammahat = ExampleData$beta.exposure,
  Gammahat = ExampleData$beta.outcome,
  sigmaX   = ExampleData$se.exposure,
  sigmaY   = ExampleData$se.outcome
)
result$beta
result$P_value

Bayesian Weighted Mendelian Randomization (no plots)

Description

A faster version of BWMR() that omits diagnostic plots. Suitable for simulation studies or large-scale analyses where plotting is unnecessary.

Usage

BWMR_quick(
  gammahat,
  Gammahat,
  sigmaX,
  sigmaY,
  alpha = 100,
  sqsigma0 = (1e+06)^2
)

Arguments

gammahat

Numeric vector of SNP-exposure effect estimates.

Gammahat

Numeric vector of SNP-outcome effect estimates.

sigmaX

Numeric vector of standard errors for the SNP-exposure effects.

sigmaY

Numeric vector of standard errors for the SNP-outcome effects.

alpha

Numeric scalar; concentration parameter for the Beta prior on the proportion of valid instruments. Default is 100.

sqsigma0

Numeric scalar; prior variance for beta. Default is (1e6)^2, representing a diffuse prior.

Value

A list containing:

beta

Causal effect estimate.

se_beta

Standard error of the causal effect estimate.

P_value

P-value from a chi-squared test (1 df).

tau

Estimate of the pleiotropy noise parameter.

sigma

Estimate of the instrument strength parameter.

mu_pi

Posterior mean of the proportion of valid instruments.

Examples

data(ExampleData)
result <- BWMR_quick(
  gammahat = ExampleData$beta.exposure,
  Gammahat = ExampleData$beta.outcome,
  sigmaX   = ExampleData$se.exposure,
  sigmaY   = ExampleData$se.outcome
)
result$beta
result$P_value

Example Mendelian randomization genotype summary level dataset

Description

An example Mendelian randomization dataset.

Usage

ExampleData

Format

ExampleData

A data frame with 76 rows and 5 columns:

SNP

SNP genotype

beta.exposure

SNP-exposure estimates

beta.outcome

SNP-outcome estimates

se.exposure

Standard errors of the SNP-exposure estimates

se.outcome

Standard errors of the SNP-outcome estimates