pymc

Build, fit, and validate Bayesian models in Python using PyMC MCMC and variational inference.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill pymc-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pymc
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/pymc
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill pymc-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pymc, arviz, numpy, pandas, matplotlib, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? Building Bayesian models correctly requires navigating prior selection, MCMC sampling configuration, convergence diagnostics, and model comparison, where mistakes like divergences or poor parameterization silently invalidate results. ## Core Features & Use Cases - Standard Bayesian Workflow: Guides the full pipeline from data standardization and prior predictive checks through NUTS sampling, diagnostics (R-hat, ESS, divergences), and posterior predictive validation. - Model Templates and Patterns: Provides ready-to-customize templates for linear regression and hierarchical models with non-centered parameterization, plus patterns for logistic, Poisson, time series, and mixture models. - Diagnostic and Comparison Scripts: Includes scripts that automate convergence checks, generate diagnostic report plots, and compare models with LOO/WAIC including Pareto-k reliability checks and model averaging. - Use Case: A researcher modeling grouped experimental data can use the hierarchical model template to fit a multilevel regression, verify convergence with the diagnostics script, and compare it against simpler models using LOO. ## Quick Start Use the pymc skill to build a Bayesian hierarchical regression model for my grouped dataset and check its sampling diagnostics.

Frequently Asked Questions about pymc

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a Bayesian hierarchical model in PyMC?

Define hyperpriors for population-level parameters, then use non-centered parameterization for group-level effects by sampling offsets and scaling them deterministically. The hierarchical_model_template.py file provides a complete working example with diagnostics and predictions.

How to fix divergences in PyMC NUTS sampling?

Increase target_accept to 0.95 or 0.99, apply non-centered parameterization for hierarchical models, and strengthen priors to constrain parameters. Persistent divergences may indicate model misspecification requiring structural changes.

What is the difference between LOO and WAIC for model comparison?

Both estimate out-of-sample predictive accuracy, but LOO via Pareto-smoothed importance sampling is generally more robust. When Pareto-k values exceed 0.7, LOO becomes unreliable and WAIC or k-fold cross-validation should be considered instead.

When should I use variational inference instead of MCMC in PyMC?

Use ADVI for quick exploration, large models, or initializing MCMC chains, since it runs much faster than NUTS. However, it approximates the posterior and may underestimate uncertainty, so use full MCMC when accurate uncertainty quantification matters.

What R-hat and ESS values indicate PyMC convergence?

R-hat should be below 1.01 for all parameters, indicating chains have converged, and effective sample size should exceed 400 for reliable estimates. The check_diagnostics function in model_diagnostics.py automatically verifies both thresholds plus divergences and tree depth.