Skip to content

[Repo Assist] fix(estimators): delta-method CI/SE for LinearRegressionEstimator with effect modifiers - #1739

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-issue-336-linear-reg-ci-effect-modifiers-20260806-ddd0bedddffde301
Draft

[Repo Assist] fix(estimators): delta-method CI/SE for LinearRegressionEstimator with effect modifiers#1739
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-issue-336-linear-reg-ci-effect-modifiers-20260806-ddd0bedddffde301

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.

Problem

LinearRegressionEstimator._estimate_confidence_intervals and _estimate_std_error raised NotImplementedError whenever effect modifiers were present (the code had a # TODO: Looking for contributions comment). This forced users to fall back to expensive bootstrapping, or receive an error, even though the exact analytic solution is straightforward for a linear model.

Closes #336

Root Cause

The ATE for a linear model with effect modifiers is a linear combination of OLS coefficients:

ATE = (b_t + b_{t·x1}·mean(x1) + b_{t·x2}·mean(x2) + ...) × (t1 – t0)
    = gradient @ beta
```

where `gradient = mean(X_t1 − X_t0, axis=0)` is the vector of mean feature differences under `treatment_value` vs `control_value`. By the delta method:

```
Var(ATE) = gradient @ cov_params @ gradient
SE(ATE)  = sqrt(Var(ATE))

This is exact for linear models (not an approximation) and requires no simulation.

Fix

Added _delta_method_std_error() helper to LinearRegressionEstimator that:

  1. Builds feature matrices X_t1 / X_t0 with treatment fixed to treatment_value / control_value.
  2. Computes gradient = mean(X_t1 - X_t0, axis=0).
  3. Returns sqrt(gradient @ cov_params @ gradient).

_estimate_confidence_intervals and _estimate_std_error now call this for the effect-modifier case instead of raising NotImplementedError. The non–effect-modifier path is unchanged.

The approach naturally handles:

  • Multiple effect modifiers (including categorical ones, via the existing OneHotEncoder reuse).
  • Arbitrary treatment_value / control_value scaling.
  • Multiple confounders.

References

Test Status

21 new tests added, covering:

  • No NotImplementedError for CI/SE with effect modifiers.
  • CI shape is (1, 2) for the effect-modifier case.
  • CI bounds are finite and properly ordered (lower < upper).
  • CI contains the point estimate.
  • SE is positive and finite.
  • Multiple effect modifiers.

All 21 tests in test_linear_regression_estimator.py pass. Linting matches the pre-existing baseline (no new flake8 errors introduced).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

…imator with effect modifiers

Previously _estimate_confidence_intervals and _estimate_std_error raised
NotImplementedError when effect modifiers were present, falling back to
bootstrap. This commit implements the exact analytic delta-method for both.

For a linear model y = X @ beta, the ATE is a linear combination of
coefficients: ATE = gradient @ beta where gradient = mean(X_t1 - X_t0).
By the delta method: Var(ATE) = gradient @ cov_params @ gradient.

This gives an exact, O(1)-sample SE/CI without bootstrapping.

Closes #336

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions github-actions Bot added automation bug Something isn't working enhancement New feature or request repo-assist labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working enhancement New feature or request repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add asymptotic confidence intervals for average treatment effect for linear regression with effect modifiers

0 participants