[Repo Assist] fix(estimators): delta-method CI/SE for LinearRegressionEstimator with effect modifiers - #1739
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…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>
78 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.
Problem
LinearRegressionEstimator._estimate_confidence_intervalsand_estimate_std_errorraisedNotImplementedErrorwhenever effect modifiers were present (the code had a# TODO: Looking for contributionscomment). 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:
This is exact for linear models (not an approximation) and requires no simulation.
Fix
Added
_delta_method_std_error()helper toLinearRegressionEstimatorthat:X_t1/X_t0with treatment fixed totreatment_value/control_value.gradient = mean(X_t1 - X_t0, axis=0).sqrt(gradient @ cov_params @ gradient)._estimate_confidence_intervalsand_estimate_std_errornow call this for the effect-modifier case instead of raisingNotImplementedError. The non–effect-modifier path is unchanged.The approach naturally handles:
OneHotEncoderreuse).treatment_value/control_valuescaling.References
Test Status
21 new tests added, covering:
NotImplementedErrorfor CI/SE with effect modifiers.(1, 2)for the effect-modifier case.lower < upper).All 21 tests in
test_linear_regression_estimator.pypass. Linting matches the pre-existing baseline (no new flake8 errors introduced).