Add weighting bootstrap inference (weightingboottest)#1275
Open
Add weighting bootstrap inference (weightingboottest)#1275
Conversation
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes 🚀 New features to boost your workflow:
|
s3alfisc
reviewed
Apr 14, 2026
| self, | ||
| reps: int, | ||
| method: Literal["bayesian", "multinomial"] = "bayesian", | ||
| alpha: float = 1.0, |
Member
There was a problem hiding this comment.
Maybe we could name the alpha arg differently? Right now I believe we might risk that users confuse alpha from the dirchlet list with the significance alpha level?
Collaborator
Author
There was a problem hiding this comment.
Thanks for the comment. It is now changed to concentration.
https://en.wikipedia.org/wiki/Concentration_parameter
80261a4 to
c79d5e0
Compare
Collaborator
Author
|
pre-commit.ci please re-run |
Implements observation-reweighting bootstrap as a complement to wildboottest() and analytic vcov(). Two methods: - bayesian: Dirichlet(alpha) weights (Rubin 1981), continuous - multinomial: Multinomial(N, 1/N) weights = classical pairs/XY bootstrap Key implementation details: - Re-demeans per iteration with bootstrap weights using native numba demeaning, ~12x faster than wildboottest on large FE panels - Stores _X_untransformed_df (pre-demeaning DataFrame) alongside the existing _Y_untransformed to enable correct per-iteration re-absorption - Filters zero-weight rows before demeaning to avoid division-by-zero in the numba kernel (can arise with multinomial draws) - Handles unbalanced panels via np.unique inverse mapping - _X_untransformed_df freed in lean mode via _clear_attributes() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
…ormat Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… with significance level The `alpha` parameter in the Dirichlet weighting bootstrap is a concentration parameter, not a significance level. Rename to `concentration` to match PyTorch/TensorFlow Probability conventions and clarify its meaning. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Refactor the bootstrap loop in Feols.weightingboottest() to delegate per-iteration fitting to _bootstrap_one_rep(), which subclasses can override. Feiv overrides it to solve 2SLS (demean Y, X, Z with bootstrap weights) instead of OLS, giving correct bootstrap SEs for IV models. Also stores _Z_untransformed_df (pre-demeaning instrument DataFrame) alongside the existing _X_untransformed_df for use in the Feiv bootstrap. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Refactor the bootstrap loop in Feols.weightingboottest() to delegate per-iteration fitting to _bootstrap_one_rep(), which subclasses can override. Feiv overrides it to solve 2SLS (demean Y, X, Z with bootstrap weights) instead of OLS, giving correct bootstrap SEs for IV models. Also stores _Z_untransformed_df (pre-demeaning instrument DataFrame) alongside the existing _X_untransformed_df for use in the Feiv bootstrap. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes RUF002 pre-commit failure triggered by master commit c533be2 which added get_ivf_data() with γ_ambition in the docstring. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8c1314c to
4018e55
Compare
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.
Summary
Closes #1274
The classical pairs bootstrap (sampling with replacement) is equivalent to weighting observations by counts drawn from a Multinomial(N, 1/N, ..., 1/N) distribution. The Bayesian bootstrap (Rubin 1981) is its continuous analogue: weights are drawn from a Dirichlet(α) distribution, which assigns positive mass to every observation and avoids the discreteness of the multinomial. Both are implemented as
weightingboottest(), a new observation-reweighting inference method alongside the existingwildboottest()and analyticvcov()options.This also adds the first pairs/XY bootstrap implementation in pyfixest —
method="multinomial"is provably equivalent to resampling rows with replacement.API
Implementation notes
wildboottest()on large FE panels (500 FEs, N=5,000)np.uniqueinverse mapping_X_untransformed_df(pre-demeaning DataFrame) to enable correct per-iteration FE re-absorption, mirroring the existing_Y_untransformed_X_untransformed_dfis freed in lean mode via_clear_attributes()Test plan
multinomialSE matches manual pairs bootstrap SE within MC noisemethodandalpharaiseValueErrorcluster=argument worksCo-developed by @mdizadi and Claude Code (Anthropic).