mediation {bayestestR} | R Documentation |

`mediation()`

is a short summary for multivariate-response
mediation-models, i.e. this function computes average direct and average
causal mediation effects of multivariate response models.

```
mediation(model, ...)
## S3 method for class 'brmsfit'
mediation(
model,
treatment,
mediator,
response = NULL,
centrality = "median",
ci = 0.95,
method = "ETI",
...
)
## S3 method for class 'stanmvreg'
mediation(
model,
treatment,
mediator,
response = NULL,
centrality = "median",
ci = 0.95,
method = "ETI",
...
)
```

`model` |
A |

`...` |
Not used. |

`treatment` |
Character, name of the treatment variable (or direct effect)
in a (multivariate response) mediator-model. If missing, |

`mediator` |
Character, name of the mediator variable in a (multivariate
response) mediator-model. If missing, |

`response` |
A named character vector, indicating the names of the response
variables to be used for the mediation analysis. Usually can be |

`centrality` |
The point-estimates (centrality indices) to compute. Character (vector) or list with one or more of these options: |

`ci` |
Value or vector of probability of the CI (between 0 and 1)
to be estimated. Default to |

`method` |

`mediation()`

returns a data frame with information on the
*direct effect* (mean value of posterior samples from `treatment`

of the outcome model), *mediator effect* (mean value of posterior
samples from `mediator`

of the outcome model), *indirect effect*
(mean value of the multiplication of the posterior samples from
`mediator`

of the outcome model and the posterior samples from
`treatment`

of the mediation model) and the total effect (mean
value of sums of posterior samples used for the direct and indirect
effect). The *proportion mediated* is the indirect effect divided
by the total effect.

For all values, the `89%`

credible intervals are calculated by default.
Use `ci`

to calculate a different interval.

The arguments `treatment`

and `mediator`

do not necessarily
need to be specified. If missing, `mediation()`

tries to find the
treatment and mediator variable automatically. If this does not work,
specify these variables.

The direct effect is also called *average direct effect* (ADE),
the indirect effect is also called *average causal mediation effects*
(ACME). See also Tingley et al. 2014 and Imai et al. 2010.

A data frame with direct, indirect, mediator and
total effect of a multivariate-response mediation-model, as well as the
proportion mediated. The effect sizes are median values of the posterior
samples (use `centrality`

for other centrality indices).

There is an `as.data.frame()`

method that returns the posterior
samples of the effects, which can be used for further processing in the
different bayestestR package.

Imai, K., Keele, L. and Tingley, D. (2010) A General Approach to Causal Mediation Analysis, Psychological Methods, Vol. 15, No. 4 (December), pp. 309-334.

Tingley, D., Yamamoto, T., Hirose, K., Imai, K. and Keele, L. (2014). mediation: R package for Causal Mediation Analysis, Journal of Statistical Software, Vol. 59, No. 5, pp. 1-38.

The mediation package for a causal mediation analysis in the frequentist framework.

```
## Not run:
library(mediation)
library(brms)
library(rstanarm)
# load sample data
data(jobs)
set.seed(123)
# linear models, for mediation analysis
b1 <- lm(job_seek ~ treat + econ_hard + sex + age, data = jobs)
b2 <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data = jobs)
# mediation analysis, for comparison with Stan models
m1 <- mediate(b1, b2, sims = 1000, treat = "treat", mediator = "job_seek")
# Fit Bayesian mediation model in brms
f1 <- bf(job_seek ~ treat + econ_hard + sex + age)
f2 <- bf(depress2 ~ treat + job_seek + econ_hard + sex + age)
m2 <- brm(f1 + f2 + set_rescor(FALSE), data = jobs, cores = 4, refresh = 0)
# Fit Bayesian mediation model in rstanarm
m3 <- stan_mvmer(
list(
job_seek ~ treat + econ_hard + sex + age + (1 | occp),
depress2 ~ treat + job_seek + econ_hard + sex + age + (1 | occp)
),
data = jobs,
cores = 4,
refresh = 0
)
summary(m1)
mediation(m2, centrality = "mean", ci = 0.95)
mediation(m3, centrality = "mean", ci = 0.95)
## End(Not run)
```

[Package *bayestestR* version 0.13.1 Index]