Bayesian inverse variance weighted model with a choice of prior distributions fitted using Stan.

mr_egger_stan(
  data,
  prior = 1,
  n.chains = 3,
  n.burn = 1000,
  n.iter = 5000,
  seed = 12345,
  rho = 0.5,
  ...
)

Arguments

data

A data of class mr_format.

prior

An integer for selecting the prior distributions;

  • 1 selects a non-informative set of priors;

  • 2 selects weakly informative priors;

  • 3 selects a pseudo-horseshoe prior on the causal effect;

  • 4 selects joint prior of the intercept and causal effect estimate.

n.chains

Numeric indicating the number of chains used in the HMC estimation in rstan, the default is 3 chains.

n.burn

Numeric indicating the burn-in period of the Bayesian HMC estimation. The default is 1000 samples.

n.iter

Numeric indicating the number of iterations in the Bayesian HMC estimation. The default is 5000 iterations.

seed

Numeric indicating the random number seed. The default is 12345.

rho

Numeric indicating the correlation coefficient input into the joint prior distribution. The default is 0.5.

...

Additional arguments passed through to rstan::sampling().

Value

An object of class stanfit.

References

Bowden J, Davey Smith G, Burgess S. Mendelian randomization with invalid instruments: effect estimation and bias detection through Egger regression. International Journal of Epidemiology, 2015, 44, 2, 512-525. doi: 10.1093/ije/dyv080 .

Stan Development Team (2020). "RStan: the R interface to Stan." R package version 2.19.3, https://mc-stan.org/.

Examples

# \donttest{ if (requireNamespace("rstan", quietly = TRUE)) { # Note we recommend setting n.burn and n.iter to larger values egger_fit <- mr_egger_stan(bmi_insulin, n.burn = 500, n.iter = 1000) print(egger_fit) }
#> Warning: There were 273 divergent transitions after warmup. See #> http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup #> to find out why this is a problem and how to eliminate them.
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> http://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> http://mc-stan.org/misc/warnings.html#tail-ess
#> Inference for Stan model: mregger. #> 3 chains, each with iter=1000; warmup=500; thin=1; #> post-warmup draws per chain=500, total post-warmup draws=1500. #> #> mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat #> intercept -0.06 0.00 0.04 -0.14 -0.09 -0.06 -0.04 0.02 203 1.01 #> estimate 4.09 0.16 2.32 -0.57 2.62 3.96 5.62 8.65 213 1.01 #> sigma 7.72 0.07 1.23 5.43 6.74 7.77 8.71 9.78 315 1.01 #> lp__ -35.45 0.06 1.05 -38.22 -35.92 -35.26 -34.67 -34.12 272 1.00 #> #> Samples were drawn using NUTS(diag_e) at Thu Oct 7 10:00:31 2021. #> For each parameter, n_eff is a crude measure of effective sample size, #> and Rhat is the potential scale reduction factor on split chains (at #> convergence, Rhat=1).
# }