piecewise_mr: Piecewise linear Mendelian randomization

View source: R/piecewise.R

piecewise_mrR Documentation

Piecewise linear Mendelian randomization

Description

piecewise_mr performs a Mendelian randomization (MR) analysis by fitting a piecewise linear function to localised average causal effects.

Usage

piecewise_mr(
  y,
  x,
  g,
  covar = NULL,
  family = "gaussian",
  q = 10,
  xpos = "mean",
  nboot = 100,
  fig = TRUE,
  ref = mean(x),
  pref_x = "x",
  pref_x_ref = "x",
  pref_y = "y",
  ci_quantiles = 10,
  breaks = NULL
)

Arguments

y

vector of outcome values

x

vector of exposure values

g

the instrumental variable

covar

data.frame of covariates

family

a description of the error distribution and link function to be used in the model and is a character string naming either the gaussian (i.e. "gaussian" for continuous data) or binomial (i.e. "binomial" for binary data) family function (default: "gaussian")

q

the number of quantiles the exposure distribution is to be split into within which a causal effect will be fitted, known as localised average causal effects (LACE) (default: 10)

nboot

the number of bootstrap replications (default: 100)

fig

a logical statement as to whether the user wants the results displayed in a figure (default: TRUE)

ref

the reference point for the figure, this is the value of the function that represents the expected difference in the outcome compared with this reference value when the exposure is set to different values (default: mean(x))

pref_x

the prefix/label for the x-axis (default: "x")

pref_x_ref

the prefix for the reference value displayed on the y-axis (default: "x")

pref_y

the prefix/label for the y-axis (default: "y")

ci_quantiles

the number of quantiles at which confidence intervals are to be displayed (default: 10)

breaks

breaks on the y-axis of the figure

Value

piecewise_mr returns a list of non-linear MR results from the piecewise linear function MR approach:

n

number of individuals

model

the model specifications: number of quantiles (q), number of bootstrap replications performed (nboot)

coefficients

the regression estimates: regression coefficients (beta), standard errors of regression coefficients (se), lower 95% confidence interval (lci), upper 95% confidence interval (uci), p-value (pval)

lace

the localised average causal effect estimate in each quantile: regression coefficients (beta), standard errors of regression coefficients (se), lower 95% confidence interval (lci), upper 95% confidence interval (uci), p-value (pval)

xcoef

the association between the instrument and the exposure in each quantile: regression coefficients (beta), standard errors of regression coefficients (se)

p_tests

the p-value of the non-linearity tests: p-value from the quadratic test (quad), p-value from the Cochran Q test (Q)

p_heterogeneity

the p-value of heterogeneity: p-value of the Cochran Q heterogeneity test (Q), p-value from the trend test (trend).

Author(s)

James Staley jrstaley95@gmail.com

Examples

# IV (g), exposure (x) & outcome (y)
epsx <- rexp(10000)
u <- runif(10000, 0, 1)
g <- rbinom(10000, 2, 0.3)
epsy <- rnorm(10000)
ag <- 0.25
x <- 1 + ag * g + u + epsx
y <- 0.15 * x^2 + 0.8 * u + epsy

# Covariates (covar)
c1 <- rnorm(10000)
c2 <- rnorm(10000)
c3 <- rbinom(10000, 2, 0.33)
covar <- data.frame(c1 = c1, c2 = c2, c3 = as.factor(c3))

# Analyses
fp <- fracpoly_mr(
  y = y, x = x, g = g, covar = covar,
  family = "gaussian", q = 10, d = 1, ci = "model_se",
  fig = TRUE
)
summary(fp)
plm <- piecewise_mr(
  y = y, x = x, g = g, covar = covar,
  family = "gaussian", q = 10, nboot = 100,
  fig = TRUE
)
summary(plm)


jrs95/nlmr documentation built on Jan. 13, 2024, 5:11 a.m.