(mediation_analysis)=
:::{post} February, 2022 :tags: mediation, path analysis, regression :category: beginner :author: Benjamin T. Vincent :::
This notebook covers Bayesian mediation analysis. This is useful when we want to explore possible mediating pathways between a predictor and an outcome variable._
It is important to note that the approach to mediation analysis has evolved over time. This notebook was heavily influenced by the approach of {cite:t}hayes2017introduction as set out in his textbook "Introduction to Mediation, Moderation and Conditional Process Analysis."
Readers should be aware that mediation analysis is commonly confused with moderation analysis for which we have a separate example ({ref}moderation_analysis).
The simple mediation model is very simple where $m$ is a linear function of $x$, and $y$ is a linear function of $x$ and $m$:
where $i$ indexes each observation (row in the dataset), and $i_M$ and $i_Y$ are intercept parameters. Note that $x_i$, $m_i$, and $y_i$ are observed data.
[Image blocked: No description]
Using definitions from {cite:t}hayes2017introduction, we can define a few effects of interest:
Visualise the trace to check for convergence.
We have good chain mixing and the posteriors for each chain look very similar, so no problems in that regard.
First we will use a pair plot to look at joint posterior distributions.
We can take a closer look at the indirect, total, and direct effects:
Above, we stated that the total effect could also be estimated by evaluating the alternative model $y_i \sim \mathrm{Normal}(i_{Y*} + c \cdot x_i, \sigma_{Y*})$. Here we will check this by comparing the posterior distribution for $c'$ in the mediation model, and the posterior distribution for $c$ in this alternative model.
As we can see, the posterior distributions over the direct effects are near-identical for the mediation model (black curve) and the direct model (red curve).
This notebook has focused on the approach of Bayesian parameter estimation. For many situations this is entirely sufficient, and more information can be found in {cite:t}yuan2009bayesian. It will tell us, amongst other things, what our posterior beliefs are in the direct effects, indirect effects, and total effects. And we can use those posterior beliefs to conduct posterior predictive checks to visually check how well the model accounts for the data.
However, depending upon the use case it may be preferable to test hypotheses about the presence or absence of an indirect effect ($x \rightarrow m \rightarrow y$) for example. In this case, it may be more appropriate to take a more explicit hypothesis testing approach to see examine the relative credibility of the mediation model as compared to a simple direct effect model (i.e. $y_i = \mathrm{Normal}(i_{Y*} + c \cdot x_i, \sigma_{Y*})$). Readers are referred to {cite:t}nuijten2015default for a hypothesis testing approach to Bayesian mediation models and to {cite:t}kruschke2011bayesian for more information on parameter estimation versus hypothesis testing.
As stated at the outset, the procedures used in mediation analysis have evolved over time. So there are plenty of people who are not necessarily up to speed with modern best practice. The approach in this notebook sticks to that outlined by {cite:t}hayes2017introduction, but it is relevant to be aware of some of this history to avoid confusion - which is particularly important if defending your approach in peer review.
:::{bibliography} :filter: docname in docnames :::
:::{include} ../page_footer.md :::