Skip to contents

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

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)
#> Call: fracpoly_mr
#> 
#> Number of individuals: 10000; Quantiles: 10; 95%CI: Model based SEs
#> 
#> Powers: 2
#> 
#> Coefficients:
#>   Estimate Std. Error 95%CI Lower 95%CI Upper   p.value    
#> 2 0.161437   0.011246    0.139395      0.1835 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Non-linearity tests
#> Fractional polynomial degree p-value: 0.465
#> Fractional polynomial non-linearity p-value: 6.9e-06
#> Quadratic p-value: 6.67e-06
#> Cochran Q p-value: 0.000403
#> 
#> Heterogeneity tests
#> Cochran Q p-value: 0.221
#> Trend p-value: 0.211

plm <- piecewise_mr(
  y = y, x = x, g = g, covar = covar,
  family = "gaussian", q = 10, nboot = 100,
  fig = TRUE
)
summary(plm)
#> Call: piecewise_mr
#> 
#> Number of individuals: 10000; Quantiles: 10; Number of bootstrap replications: 100
#> 
#> LACE:
#>     Estimate Std. Error 95%CI Lower 95%CI Upper   p.value    
#> 1   0.462085   0.162287    0.144002      0.7802 0.0044088 ** 
#> 2   0.259370   0.171506   -0.076781      0.5955 0.1304547    
#> 3   0.604121   0.164634    0.281437      0.9268 0.0002431 ***
#> 4   0.714367   0.179014    0.363499      1.0652 6.592e-05 ***
#> 5   0.997747   0.177273    0.650292      1.3452 1.820e-08 ***
#> 6   0.716973   0.178027    0.368041      1.0659 5.641e-05 ***
#> 7   0.884145   0.179979    0.531385      1.2369 8.993e-07 ***
#> 8   1.290672   0.168258    0.960886      1.6205 1.710e-14 ***
#> 9   0.984626   0.185613    0.620825      1.3484 1.128e-07 ***
#> 10  1.418118   0.341370    0.749033      2.0872 3.264e-05 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Non-linearity tests
#> Quadratic p-value: 6.67e-06
#> Cochran Q p-value: 0.000403
#> 
#> Heterogeneity tests
#> Cochran Q p-value: 0.221
#> Trend p-value: 0.201