piecewise_mr | R Documentation |
piecewise_mr
performs a Mendelian randomization (MR) analysis
by fitting a piecewise linear function to localised average causal effects.
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
)
y |
vector of outcome values |
x |
vector of exposure values |
g |
the instrumental variable |
covar |
|
family |
a description of the error distribution and link function
to be used in the model and is a |
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: |
nboot |
the number of bootstrap replications (default: |
fig |
a |
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: |
pref_x |
the prefix/label for the x-axis (default: |
pref_x_ref |
the prefix for the reference value displayed on the y-axis
(default: |
pref_y |
the prefix/label for the y-axis (default: |
ci_quantiles |
the number of quantiles at which confidence intervals
are to be displayed (default: |
breaks |
breaks on the y-axis of the figure |
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 ( |
coefficients |
the regression estimates:
regression coefficients ( |
lace |
the localised average causal effect estimate in each quantile:
regression coefficients ( |
xcoef |
the association between the instrument and the exposure in each quantile:
regression coefficients ( |
p_tests |
the p-value of the non-linearity tests:
p-value from the quadratic test ( |
p_heterogeneity |
the p-value of heterogeneity:
p-value of the Cochran Q heterogeneity test ( |
James Staley jrstaley95@gmail.com
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.