Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions dte_adj/stratified.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ def _compute_cumulative_distribution(
for s in s_list:
s_mask = strata == s
w_s[s] = (s_mask & treatment_mask).sum() / s_mask.sum()
for i, outcome in enumerate(locations):
for j in range(n_records):
s = strata[j]
prediction[j, i] = (outcomes[j] <= outcome) / w_s[s] * treatment_mask[j]
for j in range(n_records):
s = strata[j]
prediction[j] = (outcomes[j] <= locations) / w_s[s] * treatment_mask[j]

unconditional_pred = {s: prediction[s == strata].mean(axis=0) for s in s_list}
conditional_prediction = np.array([unconditional_pred[s] for s in strata])
Expand Down
18 changes: 12 additions & 6 deletions dte_adj/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import numpy as np
from scipy.stats import norm
from typing import Tuple
from typing import Tuple, TYPE_CHECKING

if TYPE_CHECKING:
from dte_adj.local import (
SimpleStratifiedDistributionEstimator,
AdjustedLocalDistributionEstimator,
)


def compute_confidence_intervals(
Expand Down Expand Up @@ -110,7 +116,7 @@ def compute_confidence_intervals(


def _compute_local_treatment_effects_core(
estimator,
estimator: "SimpleStratifiedDistributionEstimator | AdjustedLocalDistributionEstimator",
target_treatment_arm: int,
control_treatment_arm: int,
locations: np.ndarray,
Expand Down Expand Up @@ -149,10 +155,10 @@ def _compute_local_treatment_effects_core(

# Compute treatment propensity (probability of treatment)
d_t_prediction, d_t_psi, d_t_eta = estimator._compute_cumulative_distribution(
target_treatment_arm, np.zeros(1), X, Z, 1 - D
target_treatment_arm, np.zeros(1), X, Z, 1 - (target_treatment_arm == D)
)
d_c_prediction, d_c_psi, d_c_eta = estimator._compute_cumulative_distribution(
control_treatment_arm, np.zeros(1), X, Z, 1 - D
control_treatment_arm, np.zeros(1), X, Z, 1 - (target_treatment_arm == D)
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The treatment indicator logic is incorrect. For computing control treatment propensity, it should use 1 - (control_treatment_arm == D) instead of 1 - (target_treatment_arm == D) to properly identify control group membership.

Suggested change
control_treatment_arm, np.zeros(1), X, Z, 1 - (target_treatment_arm == D)
control_treatment_arm, np.zeros(1), X, Z, 1 - (control_treatment_arm == D)

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, current logic should be correct

)

# Compute outcome distributions (different for LDTE vs LPTE)
Expand Down Expand Up @@ -257,7 +263,7 @@ def xi(s):


def compute_ldte(
estimator,
estimator: "SimpleStratifiedDistributionEstimator | AdjustedLocalDistributionEstimator",
target_treatment_arm: int,
control_treatment_arm: int,
locations: np.ndarray,
Expand Down Expand Up @@ -290,7 +296,7 @@ def compute_ldte(


def compute_lpte(
estimator,
estimator: "SimpleStratifiedDistributionEstimator | AdjustedLocalDistributionEstimator",
target_treatment_arm: int,
control_treatment_arm: int,
locations: np.ndarray,
Expand Down
4 changes: 1 addition & 3 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@
],
"source": [
"pte, lower_bound, upper_bound = estimator.predict_pte(\n",
" target_treatment_arm=1,\n",
" control_treatment_arm=0,\n",
" locations=locations\n",
" target_treatment_arm=1, control_treatment_arm=0, locations=locations\n",
")\n",
"plot(\n",
" locations[:-1],\n",
Expand Down
Loading