You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -27,6 +27,7 @@ Note that this is sometimes mixed up with [mediation analysis](https://en.wikipe
27
27
28
28
```{code-cell} ipython3
29
29
import arviz as az
30
+
import daft
30
31
import matplotlib.pyplot as plt
31
32
import numpy as np
32
33
import pandas as pd
@@ -149,11 +150,32 @@ def plot_moderation_effect(result, m, m_quantiles, ax=None):
149
150
150
151
I've taken inspiration from a blog post {cite:t}`vandenbergSPSS` which examines whether age influences (moderates) the effect of training on muscle percentage. We might speculate that more training results in higher muscle mass, at least for younger people. But it might be the case that the relationship between training and muscle mass changes with age - perhaps training is less effective at increasing muscle mass in older age?
151
152
152
-
The schematic box and arrow notation often used to represent moderation is shown by an arrow from the moderating variable to the line between a predictor and an outcome variable.
153
+
The schematic box and arrow notation often used in the _statistical_ literature to represent moderation is shown by an arrow from the moderating variable to the line between a predictor and an outcome variable.
153
154
154
155

155
156
156
-
It can be useful to use consistent notation, so we will define:
157
+
+++
158
+
159
+
It is useful to draw the same diagram out using the visual notation of _structural causal modeling_ (see below). This notation shows that both age and training causally influence muscle mass. The causal relationship also states that muscle mass is a function of both age and training. There is no specific visual notation in the SCM approach to represent moderation. Instead, that would be captured by the functional form of the relationship $f$. Note that the operator $:=$ is similar to the traditional $=$ operator, but it is used to denote a _causal_ or directional relationship rather than just equality.
pgm.add_text(-0.25, -0.75, r"muscle mass := $f$(training, age)")
174
+
175
+
pgm.render();
176
+
```
177
+
178
+
Because we want to focus on the moderation concept and not the specific example. it can be useful to use consistent and more abstract notation, so we will define:
157
179
- $x$ as the main predictor variable. In this example it is training.
158
180
- $y$ as the outcome variable. In this example it is muscle percentage.
159
181
- $m$ as the moderator. In this example it is age.
result = pm.sample(draws=1000, tune=1000, random_seed=42, nuts={"target_accept": 0.9})
282
+
result = pm.sample()
261
283
```
262
284
263
285
Visualise the trace to check for convergence.
@@ -280,7 +302,7 @@ az.plot_pair(
280
302
marginals=True,
281
303
point_estimate="median",
282
304
figsize=(12, 12),
283
-
scatter_kwargs={"alpha": 0.01},
305
+
scatter_kwargs={"alpha": 0.05},
284
306
);
285
307
```
286
308
@@ -363,6 +385,7 @@ But readers are strongly encouraged to read {cite:t}`mcclelland2017multicollinea
363
385
- Updated by Benjamin T. Vincent in March 2022
364
386
- Updated by Benjamin T. Vincent in February 2023 to run on PyMC v5
365
387
- Updated to use `az.extract` by [Benjamin T. Vincent](https://github.com/drbenvincent) in February 2023 ([pymc-examples#522](https://github.com/pymc-devs/pymc-examples/pull/522))
388
+
- Updated by [Benjamin T. Vincent](https://github.com/drbenvincent) in May 2024 to incorporate causal concepts
0 commit comments