Skip to content

Commit 5e71bcc

Browse files
Copilotd-morrison
andcommitted
Fix code review issues: balance Table 2.2, update calculations, escape pipe symbols
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
1 parent c4b685d commit 5e71bcc

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

chapters/02-randomized-experiments.qmd

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ Table 2.2 shows a possible outcome from this stratified randomization.
138138
| Artemis | 0 | 0 | 1 | Hebe | 0 | 0 | 1 |
139139
| Kronos | 1 | 0 | 1 | Ares | 1 | 1 | 1 |
140140
| Hades | 1 | 0 | 0 | Hephaestus | 1 | 1 | 1 |
141-
| Poseidon | 1 | 1 | 0 | Polyphemus | 1 | 1 | 1 |
142-
| Zeus | 1 | 1 | 1 | Hermes | 1 | 1 | 0 |
141+
| Poseidon | 1 | 0 | 1 | Polyphemus | 1 | 1 | 1 |
142+
| Zeus | 1 | 1 | 1 | Hermes | 1 | 0 | 0 |
143143
| Apollo | 1 | 0 | 1 | Dionysus | 1 | 1 | 0 |
144144

145145
:::
@@ -232,12 +232,12 @@ Using Table 2.2, let's compute the standardized causal risk difference.
232232
*Among women ($L = 0$):*
233233

234234
- $Pr[Y = 1|A = 1, L = 0] = 3/5 = 0.6$ (3 of 5 treated women died)
235-
- $Pr[Y = 1|A = 0, L = 0] = 1/5 = 0.2$ (1 of 5 untreated women died)
235+
- $Pr[Y = 1|A = 0, L = 0] = 2/5 = 0.4$ (2 of 5 untreated women died)
236236

237237
*Among men ($L = 1$):*
238238

239239
- $Pr[Y = 1|A = 1, L = 1] = 4/5 = 0.8$ (4 of 5 treated men died)
240-
- $Pr[Y = 1|A = 0, L = 1] = 2/5 = 0.4$ (2 of 5 untreated men died)
240+
- $Pr[Y = 1|A = 0, L = 1] = 3/5 = 0.6$ (3 of 5 untreated men died)
241241

242242
**Step 2**: Compute population distribution of $L$
243243

@@ -248,14 +248,14 @@ Using Table 2.2, let's compute the standardized causal risk difference.
248248

249249
\begin{align}
250250
E[Y^{a=1}] &= 0.6 \times 0.5 + 0.8 \times 0.5 = 0.7 \\
251-
E[Y^{a=0}] &= 0.2 \times 0.5 + 0.4 \times 0.5 = 0.3
251+
E[Y^{a=0}] &= 0.4 \times 0.5 + 0.6 \times 0.5 = 0.5
252252
\end{align}
253253

254254
**Step 4**: Compute causal effect
255255

256-
$$E[Y^{a=1}] - E[Y^{a=0}] = 0.7 - 0.3 = 0.4$$
256+
$$E[Y^{a=1}] - E[Y^{a=0}] = 0.7 - 0.5 = 0.2$$
257257

258-
The standardized causal risk difference is 0.4. This differs from the crude (unstandardized) associational difference, which is $(7/10) - (3/10) = 0.4$ in this particular example.
258+
The standardized causal risk difference is 0.2. In this particular example, this equals the crude (unstandardized) associational difference: $(7/10) - (5/10) = 0.2$.
259259

260260
::: {.notes}
261261
In general, the crude association $Pr[Y = 1|A = 1] - Pr[Y = 1|A = 0]$ does **not** equal the standardized causal effect when conditional randomization is used.
@@ -342,35 +342,25 @@ Since all probabilities equal 0.5, all weights equal $1/0.5 = 2$.
342342
**Step 3**: Compute weighted means
343343

344344
*Treated group ($A = 1$):*
345-
- Sum of weighted outcomes: $(0 \times 2) + (0 \times 2) + (1 \times 2) + (1 \times 2) + (0 \times 2) + (1 \times 2) + (1 \times 2) + (1 \times 2) + (0 \times 2) + (0 \times 2) = 14$
346-
- Sum of weights: $10 \times 2 = 20$
347-
- Weighted mean: $14/20 = 0.7$
348345

349-
*Untreated group ($A = 0$):*
350-
- Sum of weighted outcomes: $(0 \times 2) + (0 \times 2) + (1 \times 2) + (0 \times 2) + (1 \times 2) + (1 \times 2) + (0 \times 2) + (1 \times 2) + (0 \times 2) + (1 \times 2) = 12$
351-
- Sum of weights: $10 \times 2 = 20$
352-
- Weighted mean: $12/20 = 0.6$
353-
354-
Wait, this doesn't match. Let me recount from Table 2.2.
346+
Based on Table 2.2, there are 10 treated individuals, of whom 7 died (Y=1). The weighted mean is:
355347

356-
Actually, looking at Table 2.2 more carefully:
348+
$$\frac{\sum_{i:A_i=1} W_i Y_i}{\sum_{i:A_i=1} W_i} = \frac{7 \times 2}{10 \times 2} = \frac{14}{20} = 0.7$$
357349

358-
*Treated ($A = 1$):* Hestia (Y=0), Hera (Y=0), Athena (Y=1), Aphrodite (Y=1), Persephone (Y=1), Poseidon (Y=0), Zeus (Y=1), Ares (Y=1), Hephaestus (Y=1), Polyphemus (Y=1), Hermes (Y=0), Dionysus (Y=0)
359-
360-
Count: 12 treated, 7 with Y=1
350+
*Untreated group ($A = 0$):*
361351

362-
*Untreated ($A = 0$):* Rheia (Y=0), Demeter (Y=0), Artemis (Y=1), Leto (Y=0), Hebe (Y=1), Kronos (Y=1), Hades (Y=0), Apollo (Y=1)
352+
Based on Table 2.2, there are 10 untreated individuals, of whom 5 died (Y=1). The weighted mean is:
363353

364-
Count: 8 untreated, 4 with Y=1
354+
$$\frac{\sum_{i:A_i=0} W_i Y_i}{\sum_{i:A_i=0} W_i} = \frac{5 \times 2}{10 \times 2} = \frac{10}{20} = 0.5$$
365355

366356
**Step 4**: Compute IPW estimate
367357

368-
- Weighted mean in treated: $7/10 = 0.7$ (since all weights are equal in this balanced design)
369-
- Weighted mean in untreated: $3/10 = 0.3$
370-
- IPW estimate: $0.7 - 0.3 = 0.4$
358+
- Weighted mean in treated: $0.7$
359+
- Weighted mean in untreated: $0.5$
360+
- IPW estimate: $0.7 - 0.5 = 0.2$
371361

372362
::: {.notes}
373-
In this example, IPW and standardization give the same answer (0.4) because the design is balanced. With equal treatment probabilities within strata and equal numbers in each stratum, the two methods are equivalent.
363+
In this example, IPW and standardization give the same answer (0.2) because the design is balanced. With equal treatment probabilities within strata and equal numbers in each stratum, the two methods are equivalent.
374364

375365
In general, standardization and IPW can give different estimates when:
376366
1. Treatment probabilities vary across strata
@@ -385,9 +375,9 @@ Both methods are consistent (converge to the true causal effect) under the same
385375
| Feature | Standardization | IPW |
386376
|---------|----------------|-----|
387377
| **Idea** | Weight stratum-specific outcomes by population distribution | Create pseudo-population with marginal randomization |
388-
| **Formula** | $E[Y^a] = \sum_l E[Y\|A=a,L=l] Pr[L=l]$ | $E[Y^a] = E[Y \cdot I(A=a) / Pr[A=a\|L]]$ |
389-
| **Weights** | Stratum probabilities $Pr[L=l]$ | Inverse treatment probabilities $1/Pr[A\|L]$ |
390-
| **Model** | Outcome model $E[Y\|A,L]$ | Treatment model $Pr[A\|L]$ |
378+
| **Formula** | $E[Y^a] = \sum_l E[Y \vert A=a,L=l] Pr[L=l]$ | $E[Y^a] = E[Y \cdot I(A=a) / Pr[A=a \vert L]]$ |
379+
| **Weights** | Stratum probabilities $Pr[L=l]$ | Inverse treatment probabilities $1/Pr[A \vert L]$ |
380+
| **Model** | Outcome model $E[Y \vert A,L]$ | Treatment model $Pr[A \vert L]$ |
391381
| **Extensions** | G-computation, parametric g-formula | Marginal structural models |
392382

393383
::: {.notes}

0 commit comments

Comments
 (0)