Skip to content

Fix sampler portability and interval labels (for #703)#975

Closed
daimon-pymclabs wants to merge 1 commit into
cetagostini/causalimpact_v_causalpyfrom
daimon/703-sampler-and-hdi-fixes
Closed

Fix sampler portability and interval labels (for #703)#975
daimon-pymclabs wants to merge 1 commit into
cetagostini/causalimpact_v_causalpyfrom
daimon/703-sampler-and-hdi-fixes

Conversation

@daimon-pymclabs

Copy link
Copy Markdown

Targets cetagostini/causalimpact_v_causalpy (the #703 branch) to address the two outstanding "should fix before merge" items from the latest review round.

Changes

1. Portable sampler (cell 14). The notebook used nutpie + the jax backend + mode="FAST_COMPILE", none of which ship with a default CausalPy install — so the notebook errored for most readers running it locally. There was also a typo: the key was nut_sampler, but PyMC's argument is nuts_sampler (cf. iv_vs_priors.ipynb), so it was silently ignored rather than selecting nutpie. Replaced with the default NUTS sampler and modest sample_kwargs (draws=500, tune=500, target_accept=0.95), consistent with AGENTS.md asking docs to minimise MCMC load.

2. Interval labelling (cells 28/29). The CausalPy ITS and SC bands compute a genuine az.hdi(...), but the CausalImpact band comes from tfp-causalimpact's point_effects_lower/upper, which is an equal-tailed pointwise interval — yet the shared legend and caption called all three "95% HDI". The figure now labels CausalImpact's band "95% interval" (CausalPy bands stay "95% HDI"), and the caption is clarified.

⚠️ Outputs need regenerating before merge

The docs build runs with nb_execution_mode = "off", so cell outputs are committed by hand. I changed the sampler and the figure, but I could not execute the notebook in my environment (no pymc / tfp-causalimpact). I therefore cleared the stale outputs for the cells whose results change — the ITS fit (14–15), the SC fit and summaries (23, 24, 26, 27), the three-panel figure (29), and the MAE table (31).

@cetagostini — please re-run those cells in your env to repopulate outputs. Note the new default sampler will shift the ITS/SC numbers slightly, so the approximate figures quoted in the markdown (≈ −5.2 for ITS, ≈ −1.98 for SC, and the ~14×/~46× MAE ratios in cell 32) may need a light touch-up to match the regenerated run.

Everything else from the review round was already addressed on the branch. Happy to fold these commits directly into #703 instead of as a separate PR if that's easier.

…CausalImpact

Addresses two review items on #703:

- Cell 14: replace the nutpie/jax/FAST_COMPILE sampler (not in the default
  install, and the kwarg was spelled `nut_sampler` rather than PyMC's
  `nuts_sampler`, so it was silently ignored) with the default NUTS sampler
  and modest sample_kwargs (draws=500, tune=500, target_accept=0.95). Keeps
  docs runnable for readers on a default CausalPy install.
- Cells 28/29: the CausalImpact band uses tfp-causalimpact's equal-tailed
  pointwise interval, not an HDI. Label it "95% interval" while the genuine
  az.hdi bands for the CausalPy methods stay "95% HDI", and clarify the caption.

Outputs for the affected cells are cleared — they need regenerating in an
env with pymc + tfp-causalimpact since the docs build runs with
nb_execution_mode="off".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@cursor

cursor Bot commented Jun 25, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Documentation-only notebook edits with no library or API changes; merge should wait until affected cells are re-executed so docs do not ship empty outputs.

Overview
Updates its_causalpy_vs_causalimpact.ipynb so readers can run it on a default CausalPy install and the comparison figure labels uncertainty bands correctly.

The ITS and synthetic-control fits now use default PyMC NUTS with shared, modest sample_kwargs (draws=500, tune=500, target_accept=0.95, etc.) instead of nutpie, the jax backend, and FAST_COMPILE, which are not part of a typical install. That removes the mistaken nut_sampler key (PyMC expects nuts_sampler, which was being ignored).

On the three-panel effect plot, CausalImpact’s band is labeled “95% interval” (equal-tailed pointwise bounds from point_effects_lower/upper), while CausalPy ITS and SC stay “95% HDI” via az.hdi. The markdown caption now distinguishes HDIs from CausalImpact’s interval instead of calling everything HDI.

Outputs for the refit cells, comparison figure, and MAE table were cleared because the author could not execute the notebook; those cells need to be re-run before merge so committed outputs match the new sampler and labels (ITS/SC numbers and quoted ≈ values may shift slightly).

Reviewed by Cursor Bugbot for commit 583f593. Bugbot is set up for automated code reviews on this repo. Configure here.

@read-the-docs-community

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants