Skip to content

Commit fa6d0b4

Browse files
author
Quarto GHA Workflow Runner
committed
Built site for gh-pages
1 parent 8c12973 commit fa6d0b4

6 files changed

+35
-35
lines changed

.nojekyll

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b7865e9e
1+
314103b8

search.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@
405405
"href": "sessions/causal-mediation-analysis-introduction.html#what-is-a-cause",
406406
"title": "6  Introduction to causal mediation analysis",
407407
"section": "",
408-
"text": "Notation\n\n\n\nA = received treatment/intervention/exposure (e.g., 1 = intervention, 0 = no intervention)\nY = observed outcome (e.g., 1 = developed the outcome, 0 = no outcome)\n\\(Y^{a=1}\\) = Counterfactual outcome under treatment a=1 (i.e., the outcome had everyone, counter to the fact, received treatment a = 1)\n\\(Y^{a=0}\\) = Counterfactual outcome under treatment a =0 (i.e., the outcome had everyone, counter to the fact, received treatment a = 0)\n\n\n\n6.1.1 Individual causal effect\nWhen investigating health outcomes, we would ideally want to know if you do X, then Y will happen. We could have a specific question:\n\nWill eating more red meat give me higher blood glucose in 1 year?\n\nTo answer this question we would ideally have you consume more red meat over 1 year and measure your blood glucose levels. Then, we would turn back time, and make you eat something else over 1 year and then measure your blood glucose levels again. If there is a difference between your two outcomes, then we say there is a causal effect.\nBut we can never do this in the real world.\n\n\n6.1.2 Average causal effect\nInstead, we can perform a randomized controlled trial. We now ask a slightly different question:\n\nWill eating more red meat give adults higher blood glucose in 1 year?\n\nWe can randomely assigning one group to consume more red meat and the other group to consume more of something else over 1 year. Then we compare the average blood glucose levels after 1 year in each of the groups. If there is a difference, we could say there is an average causal effect.\n\n\n\n\n\n\nNotation\n\n\n\nWe now modify the terms a little.\n\\(E[Y^{a=1}]\\) the average counterfactual outcome, had all subjects in the population received treatment a = 1.\n\\(Pr[Y^{a=1}]\\) the proportion of subjects that would have developed the outcome Y had all subjects in the population of interest received treatment a = 1.\n\n\n\n\n6.1.3 Definition of a causal effect\nMore formally we can now define a causal effect @hernan_definition_2004:\n\\(E[Y^{a=1} = 1] - E[Y^{a=0} = 1] \\ne 0\\)\n\n\n6.1.4 Code example: estimating causal effect\nTo get an idea of what is going on, we will simulate a simple dataset with an outcome Y, treatment A and a confounder W.\n\nn <- 1e6\nw <- rnorm(n)\na <- rbinom(n, 1, 0.5)\ny <- rnorm(n, w + a)\n\nThen, we will run a linear regression model for the effect of the treatment on the outcome, adjusting for confounder w.\n\nlm_y <- lm(y ~ a + w)\n\nWe now use this model to predict the outcome, if all had received treatment = 1 and another prediction of the outcome had everyone not received treatment (A = 0).\n\npred_y1 <- predict(lm_y, newdata = data.frame(a = 1, w = w))\npred_y0 <- predict(lm_y, newdata = data.frame(a = 0, w = w))\n\nWe can now get the causal effect, which is the average of the difference in the treatment effect in each group. Or put more formally \\(E[Y^{a=1} = 1] - E[Y^{a=0} = 1]\\)\n\nmean(pred_y1 - pred_y0)\n\n[1] 0.9980484\n\n\nIt turns out that this average causal effect is the same as the regression coefficient in the linear model.\n\nsummary(lm_y)\n\n\nCall:\nlm(formula = y ~ a + w)\n\nResiduals:\n Min 1Q Median 3Q Max \n-4.5877 -0.6750 -0.0002 0.6752 4.7461 \n\nCoefficients:\n Estimate Std. Error t value Pr(>|t|) \n(Intercept) 0.0011520 0.0014150 0.814 0.416 \na 0.9980484 0.0020013 498.708 <2e-16 ***\nw 1.0012021 0.0009995 1001.668 <2e-16 ***\n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 1.001 on 999997 degrees of freedom\nMultiple R-squared: 0.556, Adjusted R-squared: 0.556 \nF-statistic: 6.262e+05 on 2 and 999997 DF, p-value: < 2.2e-16\n\n\nA regression-based approach can in some situations also be used. However, for more complicated situations, the regression-based approach fail. The causal intuition in the regression-based approach is also less clear.\n\n\n\n\n\n\nQuestion\n\n\n\nWhy is there no difference between the linear regression coefficient and the predicted mean difference?",
408+
"text": "Notation\n\n\n\nA = received treatment/intervention/exposure (e.g., 1 = intervention, 0 = no intervention)\nY = observed outcome (e.g., 1 = developed the outcome, 0 = no outcome)\n\\(Y^{a=1}\\) = Counterfactual outcome under treatment a=1 (i.e., the outcome had everyone, counter to the fact, received treatment a = 1)\n\\(Y^{a=0}\\) = Counterfactual outcome under treatment a =0 (i.e., the outcome had everyone, counter to the fact, received treatment a = 0)\n\n\n\n6.1.1 Individual causal effect\nWhen investigating health outcomes, we would ideally want to know if you do X, then Y will happen. We could have a specific question:\n\nWill eating more red meat give me higher blood glucose in 1 year?\n\nTo answer this question we would ideally have you consume more red meat over 1 year and measure your blood glucose levels. Then, we would turn back time, and make you eat something else over 1 year and then measure your blood glucose levels again. If there is a difference between your two outcomes, then we say there is a causal effect.\nBut we can never do this in the real world.\n\n\n6.1.2 Average causal effect\nInstead, we can perform a randomized controlled trial. We now ask a slightly different question:\n\nWill eating more red meat give adults higher blood glucose in 1 year?\n\nWe can randomely assigning one group to consume more red meat and the other group to consume more of something else over 1 year. Then we compare the average blood glucose levels after 1 year in each of the groups. If there is a difference, we could say there is an average causal effect.\n\n\n\n\n\n\nNotation\n\n\n\nWe now modify the terms a little.\n\\(E[Y^{a=1}]\\) the average counterfactual outcome, had all subjects in the population received treatment a = 1.\n\\(Pr[Y^{a=1}]\\) the proportion of subjects that would have developed the outcome Y had all subjects in the population of interest received treatment a = 1.\n\n\n\n\n6.1.3 Definition of a causal effect\nMore formally we can now define a causal effect @hernan_definition_2004:\n\\(E[Y^{a=1} = 1] - E[Y^{a=0} = 1] \\ne 0\\)\n\n\n6.1.4 Code example: estimating causal effect\nTo get an idea of what is going on, we will simulate a simple dataset with an outcome Y, treatment A and a confounder W.\n\nn <- 1e6\nw <- rnorm(n)\na <- rbinom(n, 1, 0.5)\ny <- rnorm(n, w + a)\n\nThen, we will run a linear regression model for the effect of the treatment on the outcome, adjusting for confounder w.\n\nlm_y <- lm(y ~ a + w)\n\nWe now use this model to predict the outcome, if all had received treatment = 1 and another prediction of the outcome had everyone not received treatment (A = 0).\n\npred_y1 <- predict(lm_y, newdata = data.frame(a = 1, w = w))\npred_y0 <- predict(lm_y, newdata = data.frame(a = 0, w = w))\n\nWe can now get the causal effect, which is the average of the difference in the treatment effect in each group. Or put more formally \\(E[Y^{a=1} = 1] - E[Y^{a=0} = 1]\\)\n\nmean(pred_y1 - pred_y0)\n\n[1] 1.001791\n\n\nIt turns out that this average causal effect is the same as the regression coefficient in the linear model.\n\nsummary(lm_y)\n\n\nCall:\nlm(formula = y ~ a + w)\n\nResiduals:\n Min 1Q Median 3Q Max \n-4.6001 -0.6757 0.0002 0.6737 4.8314 \n\nCoefficients:\n Estimate Std. Error t value Pr(>|t|) \n(Intercept) -0.0005136 0.0014139 -0.363 0.716 \na 1.0017906 0.0019996 500.994 <2e-16 ***\nw 0.9992255 0.0010008 998.462 <2e-16 ***\n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nResidual standard error: 0.9998 on 999997 degrees of freedom\nMultiple R-squared: 0.5551, Adjusted R-squared: 0.5551 \nF-statistic: 6.239e+05 on 2 and 999997 DF, p-value: < 2.2e-16\n\n\nA regression-based approach can in some situations also be used. However, for more complicated situations, the regression-based approach fail. The causal intuition in the regression-based approach is also less clear.\n\n\n\n\n\n\nQuestion\n\n\n\nWhy is there no difference between the linear regression coefficient and the predicted mean difference?",
409409
"crumbs": [
410410
"Sessions",
411411
"<span class='chapter-number'>6</span>  <span class='chapter-title'>Introduction to causal mediation analysis</span>"

sessions/causal-mediation-analysis-introduction.html

+13-13
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ <h3 data-number="6.1.4" class="anchored" data-anchor-id="code-example-estimating
421421
<div class="cell">
422422
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mean</span>(pred_y1 <span class="sc">-</span> pred_y0)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
423423
<div class="cell-output cell-output-stdout">
424-
<pre><code>[1] 0.9980484</code></pre>
424+
<pre><code>[1] 1.001791</code></pre>
425425
</div>
426426
</div>
427427
<p>It turns out that this average causal effect is the same as the regression coefficient in the linear model.</p>
@@ -434,19 +434,19 @@ <h3 data-number="6.1.4" class="anchored" data-anchor-id="code-example-estimating
434434

435435
Residuals:
436436
Min 1Q Median 3Q Max
437-
-4.5877 -0.6750 -0.0002 0.6752 4.7461
437+
-4.6001 -0.6757 0.0002 0.6737 4.8314
438438

439439
Coefficients:
440-
Estimate Std. Error t value Pr(&gt;|t|)
441-
(Intercept) 0.0011520 0.0014150 0.814 0.416
442-
a 0.9980484 0.0020013 498.708 &lt;2e-16 ***
443-
w 1.0012021 0.0009995 1001.668 &lt;2e-16 ***
440+
Estimate Std. Error t value Pr(&gt;|t|)
441+
(Intercept) -0.0005136 0.0014139 -0.363 0.716
442+
a 1.0017906 0.0019996 500.994 &lt;2e-16 ***
443+
w 0.9992255 0.0010008 998.462 &lt;2e-16 ***
444444
---
445445
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
446446

447-
Residual standard error: 1.001 on 999997 degrees of freedom
448-
Multiple R-squared: 0.556, Adjusted R-squared: 0.556
449-
F-statistic: 6.262e+05 on 2 and 999997 DF, p-value: &lt; 2.2e-16</code></pre>
447+
Residual standard error: 0.9998 on 999997 degrees of freedom
448+
Multiple R-squared: 0.5551, Adjusted R-squared: 0.5551
449+
F-statistic: 6.239e+05 on 2 and 999997 DF, p-value: &lt; 2.2e-16</code></pre>
450450
</div>
451451
</div>
452452
<p>A regression-based approach can in some situations also be used. However, for more complicated situations, the regression-based approach fail. The causal intuition in the regression-based approach is also less clear.</p>
@@ -548,8 +548,8 @@ <h2 data-number="6.7" class="anchored" data-anchor-id="confounding-assumptions">
548548
<p>DAG under no mediator-outcome relation affected by treatment:</p>
549549
<div class="cell">
550550
<div class="cell-output-display">
551-
<div class="grViz html-widget html-fill-item" id="htmlwidget-7ea9358b6c8c587d9c65" style="width:100%;height:464px;"></div>
552-
<script type="application/json" data-for="htmlwidget-7ea9358b6c8c587d9c65">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n W [label = \"W\"]\n A [label = \"A\"]\n M [label = \"M\"]\n Y [label = \"Y\"]\n edge [minlen = 2]\n A->M\n M->Y\n A->Y\n W->A\n W->Y\n W->M\n{rank = same; W; A; M; Y; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
551+
<div class="grViz html-widget html-fill-item" id="htmlwidget-fc923775471cb7c10718" style="width:100%;height:464px;"></div>
552+
<script type="application/json" data-for="htmlwidget-fc923775471cb7c10718">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n W [label = \"W\"]\n A [label = \"A\"]\n M [label = \"M\"]\n Y [label = \"Y\"]\n edge [minlen = 2]\n A->M\n M->Y\n A->Y\n W->A\n W->Y\n W->M\n{rank = same; W; A; M; Y; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
553553
</div>
554554
</div>
555555
<p>We can see that we not only have to take confounding between the treatment and outcome into account, but we also have to take mediator-outcome (<span class="math inline">\(A \leftarrow W \rightarrow Y\)</span>) confounding into account.</p>
@@ -571,8 +571,8 @@ <h2 data-number="6.7" class="anchored" data-anchor-id="confounding-assumptions">
571571
<p>DAG where the mediator-outcome relation is affected by treatment:</p>
572572
<div class="cell">
573573
<div class="cell-output-display">
574-
<div class="grViz html-widget html-fill-item" id="htmlwidget-32da8ad926b700152cce" style="width:100%;height:464px;"></div>
575-
<script type="application/json" data-for="htmlwidget-32da8ad926b700152cce">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n W1 [label = \"W1\"]\n A [label = \"A\"]\n M [label = \"M\"]\n Y [label = \"Y\"]\n W2 [label = \"W2\"]\n edge [minlen = 2]\n A->M\n M->Y\n A->Y\n W1->A\n W1->Y\n W1->M\n W2->M\n W2->Y\n A->W2\n W1->W2\n{rank = same; W1; A; M; Y; }\n{rank = max; W2 ; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
574+
<div class="grViz html-widget html-fill-item" id="htmlwidget-c9e6e5efc19c27dc2fd9" style="width:100%;height:464px;"></div>
575+
<script type="application/json" data-for="htmlwidget-c9e6e5efc19c27dc2fd9">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n W1 [label = \"W1\"]\n A [label = \"A\"]\n M [label = \"M\"]\n Y [label = \"Y\"]\n W2 [label = \"W2\"]\n edge [minlen = 2]\n A->M\n M->Y\n A->Y\n W1->A\n W1->Y\n W1->M\n W2->M\n W2->Y\n A->W2\n W1->W2\n{rank = same; W1; A; M; Y; }\n{rank = max; W2 ; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
576576
</div>
577577
</div>
578578
<p>From the DAG rules, we have a special problem that we cannot solve with traditional regression approaches. If we adjust for W2 we open a backdoor path by adjusting for the collider <span class="math inline">\(W1 \rightarrow W2 \leftarrow A\)</span>. We will work on how to solve this problem later in the course.</p>

sessions/motivation.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ <h2 data-number="4.2" class="anchored" data-anchor-id="motivation-for-mediation-
289289
</ol>
290290
<div class="cell">
291291
<div class="cell-output-display">
292-
<div class="grViz html-widget html-fill-item" id="htmlwidget-25957486d4ba206fe799" style="width:100%;height:464px;"></div>
293-
<script type="application/json" data-for="htmlwidget-25957486d4ba206fe799">{"x":{"diagram":"\ndigraph {\n graph [rankdir = LR] # Left to right graph\n node [shape = plaintext] \n X [label = \"Lifestyle intervention\"] \n M [label = \"Weight loss\"] \n Y [label = \"Type 2 diabetes\"]\n edge [minlen = 2]\n X -> M\n M -> Y\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
292+
<div class="grViz html-widget html-fill-item" id="htmlwidget-79ed8d07887d26c89456" style="width:100%;height:464px;"></div>
293+
<script type="application/json" data-for="htmlwidget-79ed8d07887d26c89456">{"x":{"diagram":"\ndigraph {\n graph [rankdir = LR] # Left to right graph\n node [shape = plaintext] \n X [label = \"Lifestyle intervention\"] \n M [label = \"Weight loss\"] \n Y [label = \"Type 2 diabetes\"]\n edge [minlen = 2]\n X -> M\n M -> Y\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
294294
</div>
295295
</div>
296296
<p>We might be interested in further refining the intervention so as to increase the magnitude of the effect. This might be done by altering or improving components of the intervention that target a particular mechanism for the outcome and discarding those components of which perhaps are not relevant for the outcome.</p>
@@ -314,8 +314,8 @@ <h2 data-number="4.2" class="anchored" data-anchor-id="motivation-for-mediation-
314314
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
315315
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a><span class="st">"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
316316
<div class="cell-output-display">
317-
<div class="grViz html-widget html-fill-item" id="htmlwidget-c2964597f6b85e652346" style="width:100%;height:464px;"></div>
318-
<script type="application/json" data-for="htmlwidget-c2964597f6b85e652346">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n X [label = \"Lifestyle intervention\"]\n M [label = \"Weight loss\"]\n N [label = \"?\"]\n Y [label = \"Type 2 diabetes\"]\n edge [minlen = 2]\n X->M\n M->Y\n N->M\n {rank = same; M; X; Y; }\n {rank = min; N; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
317+
<div class="grViz html-widget html-fill-item" id="htmlwidget-1c6fffe56e471958d64b" style="width:100%;height:464px;"></div>
318+
<script type="application/json" data-for="htmlwidget-1c6fffe56e471958d64b">{"x":{"diagram":"\ndigraph {\n graph []\n node [shape = plaintext]\n X [label = \"Lifestyle intervention\"]\n M [label = \"Weight loss\"]\n N [label = \"?\"]\n Y [label = \"Type 2 diabetes\"]\n edge [minlen = 2]\n X->M\n M->Y\n N->M\n {rank = same; M; X; Y; }\n {rank = min; N; }\n}\n","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
319319
</div>
320320
</div>
321321
</section>

0 commit comments

Comments
 (0)