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
# Step 2: Create the "clever covariate": this is the key to TMLE
381
381
# It weights observations based on their propensity scores to achieve balance
382
-
# For treated units: 1 / propensity_scores
383
-
# For control units: -1 / (1 - propensity_scores)
382
+
# For treated units: 1 / propensity_scores
383
+
# For control units: -1 / (1 - propensity_scores)
384
384
# This is NOT the ATE weights; it's a component of the efficient influence function
385
385
# But it IS related, as it is also a consequence of targeting the ATE
386
386
clever_covariate <- ifelse(
@@ -391,7 +391,7 @@ clever_covariate <- ifelse(
391
391
```
392
392
393
393
6. Fit a fluctuation model with the bounded outcome, using `qlogis(initial_pred_observed)` as an offset and the clever covariate as a predictor (with no intercept). Use binomial family for the model.
394
-
7. Get the fluctuation parameter `epsilon` from the model coefficients; this is the coefficient for the clever covariate.
394
+
7. Get the fluctuation parameter `epsilon` from the model coefficients; this is the coefficient for the clever covariate.
395
395
396
396
```{r}
397
397
# Step 3: The targeting step - a small parametric fluctuation of initial estimates
@@ -412,7 +412,7 @@ epsilon <- __________
412
412
epsilon
413
413
```
414
414
415
-
8. Now that we've calculated the fluctuation parameter, we can update our predictions to obtain targeted predictions that are minimize the bias-variance tradeoff for the average treatment effect.
415
+
8. Now that we've calculated the fluctuation parameter, we can update our predictions to obtain targeted predictions that are minimize the bias-variance tradeoff for the average treatment effect.
416
416
- For treated units, we add `epsilon * (1 / propensity_scores)`.
417
417
- For control units, we add `epsilon * (-1 / (1 - propensity_scores)`.
# we'll need this later for calculating the variance and confidence intervals
434
434
targeted_pred_observed <- ifelse(
435
-
seven_dwarfs$park_extra_magic_morning == 1,
436
-
targeted_pred_treated,
435
+
seven_dwarfs$park_extra_magic_morning == 1,
436
+
targeted_pred_treated,
437
437
targeted_pred_control
438
438
)
439
439
```
440
440
441
-
9. Let's visualize the initial vs targeted individual-level predictions for treated and control units. Set the x-axis to the initial predictions and the y-axis to the targeted predictions. For the first plot, use `initial_pred_treated` and `targeted_pred_treated`, and for the second plot, use `initial_pred_control` and `targeted_pred_control`.
441
+
9. Let's visualize the initial vs targeted individual-level predictions for treated and control units. Set the x-axis to the initial predictions and the y-axis to the targeted predictions. For the first plot, use `initial_pred_treated` and `targeted_pred_treated`, and for the second plot, use `initial_pred_control` and `targeted_pred_control`.
442
442
443
443
```{r}
444
444
# plot the initial vs targeted individual-level predictions for treated units
# Standard error is the standard deviation of IC values divided by sqrt(n)
@@ -518,7 +518,7 @@ tibble(
518
518
R has several packages for TMLE: tmle, ltmle, and tmle3, all with slightly different designs and capabilities. We'll use the `tmle` package here, which is quite simple and works with SuperLearner.
0 commit comments