
Estimate Mediation Indirect Effects
med_ind.Rdmed_ind estimates the indirect effects of an independent variable on a dependent variable
through a mediator using Monte Carlo simulations (Selig & Preacher, 2008). It calculates the distribution of the product
of path coefficients (a*b) and provides confidence intervals for the indirect effect, along
with a ggplot histogram for visualization.
Usage
med_ind(
a,
b,
var_a,
var_b,
cov_ab,
ci = 95,
iterations = 20000,
seed = 1,
theme = causalverse::ama_theme()
)Arguments
- a
The regression coefficient for the effect of the independent (causal) variable on the mediator.
- b
The regression coefficient for the effect of the mediator on the dependent (outcome) variable.
- var_a
The variance of the coefficient a.
- var_b
The variance of the coefficient b.
- cov_ab
The covariance between coefficients a and b.
- ci
The confidence interval width for the indirect effect (default is 95 for a 95% CI).
- iterations
The number of iterations for the Monte Carlo simulation (default is 20000).
- seed
The seed for random number generation to ensure reproducibility (default is 1).
- theme
Custom theme that follows ggplots2 (default is AMA style)
Value
A list containing the lower quantile, upper quantile, raw simulation data, and histogram plot of the indirect effects.