Tidy and strengthen ar1_bayes lecture (#927)
* Tidy and strengthen ar1_bayes lecture
Style and correctness pass on the AR(1) Bayesian posteriors lecture,
aligned with the QuantEcon styleguide:
- Fix bugs: :tags: directive typo (output was never hidden), wrong model
in a summary cell, stationary-variance typo, "kernal", MCMC wording.
- Adopt Unicode Greek variable names, np.random.default_rng, plain N for
the normal distribution, IID, sentence-case headings, {cite:t}, and
ax-style plotting with lw=2.
- Add an Overview section and a roadmap to each section; introduce every
code block with a sentence of prose.
- Link to intro AR(1) lecture; link NUTS explanation to bayes_nonconj
(add a (nuts) anchor there) instead of re-explaining.
- Teach the main point: add a "Comparing the two posteriors" section that
overlays the two posteriors for rho, and pay off the two-library setup
with an explicit PyMC vs NumPyro agreement check.
- Fix terminology once and use it throughout: the "conditioning
assumption" vs the "stationary assumption", defined by whether the
density of y0 depends on the parameters.
- Rewrite the conclusion with a plain-English rule of thumb.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Fix ar1_bayes build: drop figsize from az.plot_trace
arviz 1.x (the arviz_plots backend) no longer accepts the figsize kwarg
on plot_trace and raises ValueError, breaking notebook execution in CI
(which pip-installs the latest arviz). Remove figsize from the two
az.plot_trace calls; arviz uses its default size, which is also more
consistent with the styleguide. Verified against arviz 1.2.0 that
plot_trace(idata), summary(round_to=...), and posterior[...] access all
work; only the figsize kwarg was the problem.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* ar1_bayes: restructure Overview and explain the PyMC/NumPyro models
- Restructure the Overview into Setting / Libraries / Imports subsections
and move the likelihood factorization down to where it is used.
- Explain how the PyMC model is declared (priors, vectorized likelihood
as the product of one-step densities) so the setup is less opaque.
- Highlight, with notes and code comments, exactly how each assumption is
imposed: the conditioning assumption drops f(y0); the stationary
assumption restores it via the single y0_obs term.
- For NumPyro, add a short PyMC->NumPyro syntax mapping (function vs with
block, numpyro.sample, obs= vs observed=) instead of repeating the
explanation, and mirror the assumption code comments.
- Fix a typo and use "stationary distribution" consistently.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* ar1_bayes: fix data seed so conditioning posterior shows Hurwicz bias
The default_rng modernization changed the realized sample, leaving the
conditioning posterior for rho centered ABOVE 0.5 (mode ~0.58) -- which
contradicted both the "centred a little below 0.5" comparison text and
the earlier Hurwicz-bias (downward) attribution. Switch the data seed to
42, which restores the intended picture: conditioning rho ~0.44 (a little
below 0.5, Hurwicz) and stationary rho ~0.88 (pushed toward 1). Verified
posterior locations with a NumPyro proxy on the same data and model.
Also delete the comparison-section recap of how each assumption is
imposed (drop/keep f(y0)); it now repeats the notes added in the PyMC
implementation section.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* ar1_bayes: restructure estimation section, soften the bias discussion
- Reorganize the Estimation section into Likelihood function / Simulation
code subsections, with the simulation built up one step at a time
(incorporates John's edits; fixes heading case, the unused y_0, and a typo).
- Reframe the first-fit commentary: instead of leading with "the posteriors
aren't centered on the true values" + Hurwicz bias, state that conditioning
on y_0 recovers the parameters reasonably well (reminding the reader the
true values are rho=0.5, sigma_x=1), and move the Hurwicz downward-bias
explanation into a note that accounts for the residual imperfection.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 files changed
Lines changed: 331 additions & 160 deletions