bmediatR: Bayesian model selection for mediation analysis function

View source: R/bmediatR.R

bmediatRR Documentation

Bayesian model selection for mediation analysis function

Description

This function takes an outcome (y), candidate mediators (M), and a driver as a design matrix (X) to perform a Bayesian model selection analysis for mediation.

Usage

bmediatR(
  y,
  M,
  X,
  Z = NULL,
  Z_y = NULL,
  Z_M = NULL,
  w = NULL,
  w_y = NULL,
  w_M = NULL,
  kappa = c(0.001, 0.001),
  lambda = c(0.001, 0.001),
  tau_sq_mu = c(1000, 1000),
  tau_sq_Z = c(1000, 1000),
  phi_sq = c(1, 1, 1),
  ln_prior_c = "complete",
  options_X = list(sum_to_zero = TRUE, center = FALSE, scale = FALSE),
  align_data = TRUE,
  verbose = TRUE
)

Arguments

y

Vector or single column matrix of an outcome variable. Single outcome variable expected. Names or rownames must match across M, X, Z, Z_y, Z_M, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs.

M

Vector or matrix of mediator variables. Multiple mediator variables are supported. Names or rownames must match across y, X, Z, Z_y, Z_M, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs.

X

Design matrix of the driver. Names or rownames must match across y, M, Z, Z_y, Z_M, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. One common application is for X to represent genetic information at a QTL, either as founder strain haplotypes or variant genotypes, though X is generalizable to other types of variables.

Z

DEFAULT: NULL. Design matrix of covariates that influence the outcome and mediator variables. Names or rownames must match to those of y, M, X, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data=FALSE, dimensions and order must match across inputs. If Z is provided, it supercedes Z_y and Z_M.

Z_y

DEFAULT: NULL. Design matrix of covariates that influence the outcome variable. Names or rownames must match to those of y, M, X, Z_M, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. If Z is provided, it supercedes Z_y and Z_M.

Z_M

DEFAULT: NULL. Design matrix of covariates that influence the mediator variables. Names or rownames must match across y, M, X, Z_y, w, w_y, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. If Z is provided, it supercedes Z_y and Z_M.

w

DEFAULT: NULL. Vector or single column matrix of weights for individuals in analysis that applies to both y and M. Names must match across y, M, X, Z, Z_y, and Z_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. A common use would be for an analysis of strain means, where w is a vector of the number of individuals per strain. If no w, w_y, or w_M is given, observations are equally weighted as 1s for y and M. If w is provided, it supercedes w_y and w_M.

w_y

DEFAULT: NULL. Vector or single column matrix of weights for individuals in analysis, specific to the measurement of y. Names must match across y, M, X, Z, Z_y, Z_M, and w_M (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. A common use would be for an analysis of strain means, where y and M are summarized from a different number of individuals per strain. w_y is a vector of the number of individuals per strain used to measure y. If no w_y (or w) is given, observations are equally weighted as 1s for y.

w_M

DEFAULT: NULL. Vector or single column matrix of weights for individuals in analysis, specific to the measurement of M. Names must match across y, M, X, Z, Z_y, Z_M, and w_y (if provided) when align_data = TRUE. If align_data = FALSE, dimensions and order must match across inputs. A common use would be for an analysis of strain means, where y and M are summarized from a different number of individuals per strain. w_M is a vector of the number of individuals per strain use to measure M. If no w_M (or w) is given, observations are equally weighted as 1s for M.

kappa

DEFAULT: c(0.001, 0.001). Shape hyperparameters for the precisions of m and y. The DEFAULT represents uninformative priors on the precisions, in combination with the default prior for lambda.

lambda

DEFAULT: c(0.001, 0.001). Rate hyperparameters for the precisions of m and y. The DEFAULT represents uninformative priors on the precisions, in combination with the default prior for kappa.

tau_sq_mu

DEFAULT: c(1000, 1000). Variance components for the intercepts mu_m and mu_y. The DEFAULT represents diffuse priors, analogous to fixed effect terms.

tau_sq_Z

DEFAULT: c(1000, 1000). Variance components for the covariates encoded in Z_m and Z_y. The DEFAULT represents diffuse priors, analogous to fixed effect terms.

phi_sq

DEFAULT: c(1, 1, 1). Each element of (a, b, c) represents one of the relationships being evaluated for mediation, specifically the ratio of signal to noise. a is the effect of X on M, b is the effect of M on y, and c is the effect of X on y. The DEFAULT represents relationships that explain 50% of the variation in the outcome variable.

ln_prior_c

DEFAULT: "complete". The prior log case probabilities. See model_info() for description of likelihoods and their combinations into cases. Simplified pre-set options are available, including "complete", "partial", and "reactive".

options_X

DEFAULT: list(sum_to_zero = TRUE, center = FALSE, scale = FALSE). Optional transformations for the X design matrix. Sum_to_zero imposes a sum-to-zero contrast on the columns of X. Center sets the mean of each column to 0. Scale sets the variance of each column to 1.

align_data

DEFAULT: TRUE. If TRUE, expect vector and matrix inputs to have names and rownames, respectively. The overlapping data will then be aligned, allowing the user to not have to reduce data to overlapping samples and order them.

Value

bmediatR returns a list containing the following components:

ln_prob_data

a matrix with likelihoods of each hypothesis H1-H8 for each candidate mediator.

ln_post_c

a matrix with posterior probabilities of each causal model for each candidate mediator.

ln_post_odds

a matrix with posterior odds of individual models or combinations of models for each candidate mediator.

ln_prior_c

a single row matrix with posterior probabilities of each causal model.

ln_prior_odds

a single row matrix with prior odds of individual models or combinations of models.

ln_ml

the natural log of the marginal likelihood.

Note

See examples in vignettes with vignette("use_bmediatR", "bmediatR") or vignette("bmediatR_in_DO", "bmediatR").

Examples

bmediatR()

wesleycrouse/bmediatR documentation built on April 28, 2023, 4:01 p.m.