$npx -y skills add Learning-Bayesian-Statistics/baygent-skills --skill bayesian-workflowOpinionated Bayesian modeling workflow with PyMC and ArviZ. Contains critical guardrails (nutpie sampler, prior/posterior predictive checks, LOO-PIT calibration, prior sensitivity checks, 94% HDI, non-centered parameterizations, reproducible seeds) that agents won't apply unpromp
| 1 | # Bayesian Workflow |
| 2 | |
| 3 | ## Workflow overview |
| 4 | |
| 5 | Every Bayesian analysis follows this sequence. Do not skip steps -- especially model criticism. |
| 6 | |
| 7 | 1. **Formulate** — Define the generative story. What underlying process, that we're precisely trying to model, created the data? |
| 8 | 2. **Specify priors** — See [references/priors.md](references/priors.md) |
| 9 | 3. **Implement in PyMC** — Write the model. Prefer PyMC 5+ syntax. Use the latest version possible. |
| 10 | 4. **Run prior predictive checks** — `pm.sample_prior_predictive()`. Verify priors produce plausible data ranges before fitting |
| 11 | 5. **Inference** — `pm.sample(nuts_sampler="nutpie")`. Always use nutpie for speed (the nutpie python package provides cutting-edge sampling). Don't hardcode the number of chains — let the sampler pick the best default for the platform. |
| 12 | 6. **Diagnose convergence** — Use `arviz_stats.diagnose(idata)` as the first check (requires arviz-stats >= 1.0.0). It covers R-hat, ESS, divergences, tree depth, and E-BFMI in one call. See [references/diagnostics.md](references/diagnostics.md) |
| 13 | 7. **Criticize the model** — See [references/model-criticism.md](references/model-criticism.md) |
| 14 | 8. **Check prior sensitivity** — Run `psense_summary(idata)` to verify conclusions are robust to prior choices. Visualize with `plot_psense_dist(idata)` from `arviz_plots`. Requires `log_likelihood` and `log_prior` in the InferenceData — compute them after sampling if needed. See [references/sensitivity.md](references/sensitivity.md) |
| 15 | 9. **Compare models** (if applicable) — See [references/model-comparison.md](references/model-comparison.md) |
| 16 | 10. **Report results** — Generate `<slug>/report.md` using the canonical template in [references/reporting.md](references/reporting.md). Run `scripts/check_diagnostics.py` to turn raw diagnostics into qualitative ratings + an ordered next-steps list, and use that output to fill the Assessment lines and Suggested Next Steps section. When the user mentions a non-technical audience or is new to Bayesian stats, additionally adapt the prose to plain language and include a glossary — but keep the canonical report structure as the audit trail. |
| 17 | |
| 18 | ## Installation |
| 19 | |
| 20 | Prefer conda-forge / mamba-forge to install PyMC and its dependencies — pip can cause issues with |
| 21 | compiled backends (nutpie, JAX). Example: |
| 22 | |
| 23 | ```bash |
| 24 | mamba install -c conda-forge pymc nutpie arviz arviz-stats preliz |
| 25 | ``` |
| 26 | |
| 27 | See **Stack compatibility** below for the PyMC 5.x vs 6.x / ArviZ 0.23 vs 1.x notes. |
| 28 | |
| 29 | ## Stack compatibility (PyMC 5.x and 6.x) |
| 30 | |
| 31 | This skill teaches the **latest** PyMC 6 / ArviZ 1.x idioms and stays runnable on |
| 32 | PyMC 5.x during the transition (regulated/corporate environments can't always |
| 33 | upgrade freely). The scripts are verified on **both** stacks. |
| 34 | |
| 35 | Most code is identical across versions. Where an API genuinely diverges, prefer the |
| 36 | form that runs on **both**: |
| 37 | |
| 38 | | Task | Modern (PyMC 6 / ArviZ 1.x) | Legacy (PyMC 5 / ArviZ 0.23) | |
| 39 | |---|---|---| |
| 40 | | Posterior-predictive plot | `arviz_plots.plot_ppc_dist(idata)` — runs on both | `az.plot_ppc(idata)` (removed in ArviZ 1.x) | |
| 41 | | Trace / rank plot | `az.plot_trace(idata, var_names=[...])`; rank view `az.plot_rank(idata, var_names=[...])` — both run on both, but **pass `var_names`**: ArviZ 1.x errors when the auto-selected set exceeds its subplot cap (e.g. a vector `Deterministic` like `mu` with an `obs` dim) | `az.plot_trace(idata, kind="rank_vlines")` (the `kind=` arg is 0.23-only) | |
| 42 | | Prior-predictive draws | `pm.sample_prior_predictive(draws=500)` — runs on both | `samples=500` (removed in PyMC 6) | |
| 43 | | Summary interval | `az.summary(idata, ci_prob=0.94, ci_kind="hdi")` (ArviZ 1.x **only**) | `az.summary(idata, hdi_prob=0.94)` (ArviZ 0.23 **only**) | |
| 44 | | Sampler output type | `DataTree` | `InferenceData` | |
| 45 | |
| 46 | `arviz_plots` (the ArviZ 1.x plotting package, imported as `azp`) installs on **both** |
| 47 | stacks, so leading with `azp.*` plots is the most portable choice. Ba |