From cf15002733a9408e20d4f03fd6184e1d3c239dbf Mon Sep 17 00:00:00 2001 From: TomeHirata Date: Sun, 30 Aug 2026 11:47:51 +0900 Subject: [PATCH] docs(tutorials): fix broken Oregon tutorial code Three issues that prevented the Oregon tutorial from running end-to-end: - The LPTE bar plots (both costs and visits) used outcome_ed_*_locations[1:] as the x-axis (n-1 points) against a PTE vector of length n returned by predict_lpte, causing a broadcast shape mismatch inside ax.bar. Dropping the [1:] slice matches the shape returned by predict_lpte. - The Visits section rebound ldte_simple/lower/upper/ldte_ml/... and lpte_simple/... to the visits values, clobbering the earlier ED costs values. The final "Overall Population vs Individual Strata" visualization then plotted the visits arrays against the costs locations (a shape mismatch, and semantically wrong even if the shapes had matched). Rename the visits arrays to *_visits_* so the costs arrays stay in scope for the final comparison plot. Verified by running the tutorial end-to-end against a local copy of the OHIE Public Use Files. Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/docs/tutorials/oregon.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/docs/tutorials/oregon.md b/docs/docs/tutorials/oregon.md index a6f8d2b..c9fd6c3 100644 --- a/docs/docs/tutorials/oregon.md +++ b/docs/docs/tutorials/oregon.md @@ -215,7 +215,7 @@ lpte_ml, lpte_lower_ml, lpte_upper_ml = ml_local_estimator.predict_lpte( fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6)) # Simple local estimator -plot(outcome_ed_costs_locations[1:], lpte_simple, lpte_lower_simple, lpte_upper_simple, +plot(outcome_ed_costs_locations, lpte_simple, lpte_lower_simple, lpte_upper_simple, chart_type="bar", title="Effects of Emergency Department Costs (Simple Local Estimator)", xlabel="Emergency Department Costs", @@ -224,7 +224,7 @@ plot(outcome_ed_costs_locations[1:], lpte_simple, lpte_lower_simple, lpte_upper_ ax=ax1) # ML-adjusted local estimator -plot(outcome_ed_costs_locations[1:], lpte_ml, lpte_lower_ml, lpte_upper_ml, +plot(outcome_ed_costs_locations, lpte_ml, lpte_lower_ml, lpte_upper_ml, chart_type="bar", title="Effects of Emergency Department Costs (ML-Adjusted Local Estimator)", xlabel="Emergency Department Costs", @@ -275,13 +275,13 @@ Let's compare the results from both simple and machine learning-adjusted local e ```python # Compute LDTE: Treatment vs Control -ldte_simple, lower_simple, upper_simple = simple_local_estimator.predict_ldte( +ldte_visits_simple, lower_visits_simple, upper_visits_simple = simple_local_estimator.predict_ldte( target_treatment_arm=1, # Z=1 Selected for treatment (Enrolled) control_treatment_arm=0, # Z=0 Not selected for treatment (Not enrolled) locations=outcome_ed_visits_locations ) -ldte_ml, lower_ml, upper_ml = ml_local_estimator.predict_ldte( +ldte_visits_ml, lower_visits_ml, upper_visits_ml = ml_local_estimator.predict_ldte( target_treatment_arm=1, # Selected for treatment (Enrolled) control_treatment_arm=0, # Not selected for treatment (Not enrolled) locations=outcome_ed_visits_locations @@ -291,14 +291,14 @@ ldte_ml, lower_ml, upper_ml = ml_local_estimator.predict_ldte( fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6)) # Visualize Treatment vs Control using dte_adj's plot function -plot(outcome_ed_visits_locations, ldte_simple, lower_simple, upper_simple, +plot(outcome_ed_visits_locations, ldte_visits_simple, lower_visits_simple, upper_visits_simple, title="ED Visits: Treatment vs Control (Simple Local Estimator)", xlabel="Emergency Department Visits", ylabel="Local Distribution Treatment Effect", color="purple", ax=ax1) -plot(outcome_ed_visits_locations, ldte_ml, lower_ml, upper_ml, +plot(outcome_ed_visits_locations, ldte_visits_ml, lower_visits_ml, upper_visits_ml, title="ED Visits: Treatment vs Control (ML-Adjusted Local Estimator)", xlabel="Emergency Department Visits", ylabel="Local Distribution Treatment Effect", @@ -324,13 +324,13 @@ The confidence intervals are not substantially narrower with ML adjustment. Both ```python # Compute Local Probability Treatment Effects -lpte_simple, lpte_lower_simple, lpte_upper_simple = simple_local_estimator.predict_lpte( +lpte_visits_simple, lpte_visits_lower_simple, lpte_visits_upper_simple = simple_local_estimator.predict_lpte( target_treatment_arm=1, # Z=1 Selected for treatment (Enrolled) control_treatment_arm=0, # Z=0 Not selected for treatment (Not enrolled) locations=np.insert(outcome_ed_visits_locations, 0, -1) ) -lpte_ml, lpte_lower_ml, lpte_upper_ml = ml_local_estimator.predict_lpte( +lpte_visits_ml, lpte_visits_lower_ml, lpte_visits_upper_ml = ml_local_estimator.predict_lpte( target_treatment_arm=1, # Z=1 Selected for treatment (Enrolled) control_treatment_arm=0, # Z=0 Not selected for treatment (Not enrolled) locations=np.insert(outcome_ed_visits_locations, 0, -1) @@ -339,7 +339,7 @@ lpte_ml, lpte_lower_ml, lpte_upper_ml = ml_local_estimator.predict_lpte( fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6)) # Simple local estimator -plot(outcome_ed_visits_locations[1:], lpte_simple, lpte_lower_simple, lpte_upper_simple, +plot(outcome_ed_visits_locations, lpte_visits_simple, lpte_visits_lower_simple, lpte_visits_upper_simple, chart_type="bar", title="Effects of Emergency Department Visits (Simple Local Estimator)", xlabel="Emergency Department Visits", @@ -348,7 +348,7 @@ plot(outcome_ed_visits_locations[1:], lpte_simple, lpte_lower_simple, lpte_upper ax=ax1) # ML-adjusted local estimator -plot(outcome_ed_visits_locations[1:], lpte_ml, lpte_lower_ml, lpte_upper_ml, +plot(outcome_ed_visits_locations, lpte_visits_ml, lpte_visits_lower_ml, lpte_visits_upper_ml, chart_type="bar", title="Effects of Emergency Department Visits (ML-Adjusted Local Estimator)", xlabel="Emergency Department Visits",