Skip to content

Commit b6cce66

Browse files
add manual code examples to estimand slides
1 parent b406246 commit b6cce66

File tree

9 files changed

+60
-16
lines changed

9 files changed

+60
-16
lines changed

slides/pdf/07-using-pscores.pdf

10.6 KB
Binary file not shown.

slides/raw/07-using-pscores.html

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ <h2>Matching in R (ATM)</h2>
703703
<h2><em>Your Turn 1</em></h2>
704704
<div class="cell" data-layout-align="center">
705705
<div class="cell-output-display">
706-
<div class="countdown" id="timer_23d23eeb" data-update-every="1" tabindex="0" style="right:0;bottom:0;">
706+
<div class="countdown" id="timer_3820d331" data-update-every="1" tabindex="0" style="right:0;bottom:0;">
707707
<div class="countdown-controls"><button class="countdown-bump-down"></button><button class="countdown-bump-up">+</button></div>
708708
<code class="countdown-time"><span class="countdown-digits minutes">10</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code>
709709
</div>
@@ -723,65 +723,82 @@ <h2>Propensity scores</h2>
723723
<h2>Target estimands: ATE</h2>
724724
<p>Average Treatment Effect (ATE)</p>
725725
<p><span class="math display">\[\Large w_{ATE} = \frac{Z_i}{p_i} + \frac{1-Z_i}{1 - p_i}\]</span></p>
726+
<div class="cell" data-layout-align="center">
727+
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1"></a>(Z <span class="sc">/</span> p) <span class="sc">+</span> ((<span class="dv">1</span> <span class="sc">-</span> Z) <span class="sc">/</span> (<span class="dv">1</span> <span class="sc">-</span> p))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
728+
</div>
726729
</section>
727730
<section id="target-estimands-att-atc" class="slide level2" data-background-color="#23373B">
728731
<h2>Target estimands: ATT &amp; ATC</h2>
729732
<div class="fragment">
730733
<p>Average Treatment Effect Among the Treated (ATT) <span class="math display">\[\Large w_{ATT} = \frac{p_i Z_i}{p_i} + \frac{p_i (1-Z_i)}{1-p_i}\]</span></p>
734+
<div class="cell" data-layout-align="center">
735+
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1"></a>((p <span class="sc">*</span> Z) <span class="sc">/</span> p) <span class="sc">+</span> ((p <span class="sc">*</span> (<span class="dv">1</span> <span class="sc">-</span> Z)) <span class="sc">/</span> (<span class="dv">1</span> <span class="sc">-</span> p))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
731736
</div>
732-
<div class="fragment">
737+
</div>
738+
</section>
739+
<section id="target-estimands-att-atc-1" class="slide level2" data-background-color="#23373B">
740+
<h2>Target estimands: ATT &amp; ATC</h2>
733741
<p>Average Treatment Effect Among the Controls (ATC) <span class="math display">\[\Large w_{ATC} = \frac{(1-p_i)Z_i}{p_i} + \frac{(1-p_i)(1-Z_i)}{(1-p_i)}\]</span></p>
742+
<div class="cell" data-layout-align="center">
743+
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1"></a>(((<span class="dv">1</span> <span class="sc">-</span> p) <span class="sc">*</span> Z) <span class="sc">/</span> p) <span class="sc">+</span> (((<span class="dv">1</span> <span class="sc">-</span> p) <span class="sc">*</span> (<span class="dv">1</span> <span class="sc">-</span> Z)) <span class="sc">/</span> (<span class="dv">1</span> <span class="sc">-</span> p))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
734744
</div>
735745
</section>
736746
<section id="target-estimands-atm-ato" class="slide level2" data-background-color="#23373B">
737747
<h2>Target estimands: ATM &amp; ATO</h2>
738748
<div class="fragment">
739749
<p>Average Treatment Effect Among the Evenly Matchable (ATM) <span class="math display">\[\Large w_{ATM} = \frac{\min \{p_i, 1-p_i\}}{Z_ip_i + (1-Z_i)(1-p_i)}\]</span></p>
750+
<div class="cell" data-layout-align="center">
751+
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1"></a><span class="fu">pmin</span>(p, <span class="dv">1</span> <span class="sc">-</span> p) <span class="sc">/</span> (Z <span class="sc">*</span> p <span class="sc">+</span> (<span class="dv">1</span> <span class="sc">-</span> Z) <span class="sc">*</span> (<span class="dv">1</span> <span class="sc">-</span> p))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
740752
</div>
741-
<div class="fragment">
753+
</div>
754+
</section>
755+
<section id="target-estimands-atm-ato-1" class="slide level2" data-background-color="#23373B">
756+
<h2>Target estimands: ATM &amp; ATO</h2>
742757
<p>Average Treatment Effect Among the Overlap Population <span class="math display">\[\Large w_{ATO} = (1-p_i)Z_i + p_i(1-Z_i)\]</span></p>
758+
<div class="cell" data-layout-align="center">
759+
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1"></a>(<span class="dv">1</span> <span class="sc">-</span> p) <span class="sc">*</span> Z <span class="sc">+</span> p <span class="sc">*</span> (<span class="dv">1</span> <span class="sc">-</span> Z)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
743760
</div>
744761
</section>
745762
<section id="histogram-of-propensity-scores" class="slide level2">
746763
<h2>Histogram of propensity scores</h2>
747764

748-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-14-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
765+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-19-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
749766
<section id="ate" class="slide level2">
750767
<h2>ATE</h2>
751768

752-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-15-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
769+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-20-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
753770
<section id="att" class="slide level2">
754771
<h2>ATT</h2>
755772

756-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-16-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
773+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-21-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
757774
<section id="atc" class="slide level2">
758775
<h2>ATC</h2>
759776

760-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-17-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
777+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-22-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
761778
<section id="atm" class="slide level2">
762779
<h2>ATM</h2>
763780

764-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-18-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
781+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-23-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
765782
<section id="ato" class="slide level2">
766783
<h2>ATO</h2>
767784

768-
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-19-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
785+
<img data-src="07-using-pscores_files/figure-revealjs/unnamed-chunk-24-1.png" style="width:80.0%" class="r-stretch quarto-figure-center"></section>
769786
<section id="ate-in-r" class="slide level2">
770787
<h2>ATE in R <img data-src="img/hex/propensity.png" class="absolute" style="top: 0px; right: 0px; width: 140px; "></h2>
771788
<p><br></p>
772789
<p>Average Treatment Effect (ATE) <span class="math inline">\(w_{ATE} = \frac{Z_i}{p_i} + \frac{1-Z_i}{1 - p_i}\)</span></p>
773790
<div class="cell" data-layout-align="center">
774-
<div class="sourceCode cell-code" id="cb11" data-code-line-numbers="|4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1"></a><span class="fu">library</span>(propensity)</span>
775-
<span id="cb11-2"><a href="#cb11-2"></a>df <span class="ot">&lt;-</span> propensity_model <span class="sc">|&gt;</span></span>
776-
<span id="cb11-3"><a href="#cb11-3"></a> <span class="fu">augment</span>(<span class="at">type.predict =</span> <span class="st">"response"</span>, <span class="at">data =</span> nhefs_complete) <span class="sc">|&gt;</span></span>
777-
<span id="cb11-4"><a href="#cb11-4"></a> <span class="fu">mutate</span>(<span class="at">w_ate =</span> <span class="fu">wt_ate</span>(.fitted, qsmk)) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
791+
<div class="sourceCode cell-code" id="cb16" data-code-line-numbers="|4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1"></a><span class="fu">library</span>(propensity)</span>
792+
<span id="cb16-2"><a href="#cb16-2"></a>df <span class="ot">&lt;-</span> propensity_model <span class="sc">|&gt;</span></span>
793+
<span id="cb16-3"><a href="#cb16-3"></a> <span class="fu">augment</span>(<span class="at">type.predict =</span> <span class="st">"response"</span>, <span class="at">data =</span> nhefs_complete) <span class="sc">|&gt;</span></span>
794+
<span id="cb16-4"><a href="#cb16-4"></a> <span class="fu">mutate</span>(<span class="at">w_ate =</span> <span class="fu">wt_ate</span>(.fitted, qsmk)) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
778795
</div>
779796
</section>
780797
<section id="your-turn" class="slide level2">
781798
<h2><em>Your Turn</em></h2>
782799
<div class="cell" data-layout-align="center">
783800
<div class="cell-output-display">
784-
<div class="countdown" id="timer_b9f62b3b" data-update-every="1" tabindex="0" style="right:0;bottom:0;">
801+
<div class="countdown" id="timer_5ab3ca30" data-update-every="1" tabindex="0" style="right:0;bottom:0;">
785802
<div class="countdown-controls"><button class="countdown-bump-down"></button><button class="countdown-bump-up">+</button></div>
786803
<code class="countdown-time"><span class="countdown-digits minutes">10</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code>
787804
</div>

slides/raw/07-using-pscores.qmd

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ Direct Adjustment
241241
Average Treatment Effect (ATE)
242242

243243
$$\Large w_{ATE} = \frac{Z_i}{p_i} + \frac{1-Z_i}{1 - p_i}$$
244+
```{r}
245+
#| eval: false
246+
(Z / p) + ((1 - Z) / (1 - p))
247+
```
248+
249+
244250

245251
## Target estimands: ATT & ATC {background-color="#23373B"}
246252

@@ -249,11 +255,20 @@ $$\Large w_{ATE} = \frac{Z_i}{p_i} + \frac{1-Z_i}{1 - p_i}$$
249255
Average Treatment Effect Among the Treated (ATT)
250256
$$\Large w_{ATT} = \frac{p_i Z_i}{p_i} + \frac{p_i (1-Z_i)}{1-p_i}$$
251257

252-
. . .
258+
```{r}
259+
#| eval: false
260+
((p * Z) / p) + ((p * (1 - Z)) / (1 - p))
261+
```
262+
263+
## Target estimands: ATT & ATC {background-color="#23373B"}
253264

254265
Average Treatment Effect Among the Controls (ATC)
255266
$$\Large w_{ATC} = \frac{(1-p_i)Z_i}{p_i} + \frac{(1-p_i)(1-Z_i)}{(1-p_i)}$$
256267

268+
```{r}
269+
#| eval: false
270+
(((1 - p) * Z) / p) + (((1 - p) * (1 - Z)) / (1 - p))
271+
```
257272

258273
## Target estimands: ATM & ATO {background-color="#23373B"}
259274

@@ -262,11 +277,23 @@ $$\Large w_{ATC} = \frac{(1-p_i)Z_i}{p_i} + \frac{(1-p_i)(1-Z_i)}{(1-p_i)}$$
262277
Average Treatment Effect Among the Evenly Matchable (ATM)
263278
$$\Large w_{ATM} = \frac{\min \{p_i, 1-p_i\}}{Z_ip_i + (1-Z_i)(1-p_i)}$$
264279

265-
. . .
280+
281+
```{r}
282+
#| eval: false
283+
pmin(p, 1 - p) / (Z * p + (1 - Z) * (1 - p))
284+
```
285+
286+
## Target estimands: ATM & ATO {background-color="#23373B"}
266287

267288
Average Treatment Effect Among the Overlap Population
268289
$$\Large w_{ATO} = (1-p_i)Z_i + p_i(1-Z_i)$$
269290

291+
292+
```{r}
293+
#| eval: false
294+
(1 - p) * Z + p * (1 - Z)
295+
```
296+
270297
## Histogram of propensity scores
271298

272299
```{r}
-11.3 KB
Loading
92.1 KB
Loading
92.8 KB
Loading
86.7 KB
Loading
92.7 KB
Loading
93.9 KB
Loading

0 commit comments

Comments
 (0)