Repository navigation
feat: parameter uncertainty via parametric bootstrap - #10
Merged
Merged
Conversation
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.
Type
Related issue
None
What changed
BGNBDandMBGNBDgainparameter_uncertainty(n=200, seed=None, confidence=0.95): a parametric bootstrap that simulatesnsynthetic customerbases from the fitted parameters, refits the model on each, and returns a
ParameterUncertaintyresult (one row per parameter withestimate,se,ci_low,ci_high;to_pandas/to_json/plot). The MLE point estimatescarried no error bars, so a parameter the data pins down looked exactly like
one it barely constrains — on CDNOW calibration
rsits in [0.219, 0.269]while
aspans [0.518, 1.184] andb[1.532, 3.934]. That weak identificationof the dropout pair is the honest result the method exists to surface.
The engine is model-agnostic (
clv/_bootstrap.py); each model contributes itsown generative simulator, kept separate the way the two likelihoods are. The
MBG/NBD simulator adds the time-zero dropout branch. The small-cohort display
note now points at the method,
ParameterUncertaintyis exported fromclvkit.clv, and the user guide, API pages and the CDNOW notebook document it(the notebook cell runs
n=100, seed=42, about 30 s). Opt-in: nothing runsunless called, no dependency added, no existing behaviour changes.
The test workflow also splits into four parallel jobs (code-quality, test,
dask, notebooks) so a failure names its own axis in the checks list.
How it was tested
28 new tests across
tests/test_bgnbd_bootstrap.pyandtests/test_mbgnbd_bootstrap.py: the result contract, determinism (same(n, seed)gives an identical frame), simulator↔likelihood agreement (a basesimulated at large N from known parameters refits to recover
r/alphaanda/(a+b)within tolerance, time-zero dropouts included), interval coverage ofthe well-identified parameters, and the relative-width assertion that
a/bcome back wider than
r. Full suite: 292 passed, 1 skipped. The CDNOW goldentests still reproduce the published estimates to the last printed digit.
Checks
uv run pytestuv run ruff checkuv run ruff format --checkuv run pytest --nbmake examples/)