pymc-python

Builds, samples, and diagnoses PyMC Bayesian models with named dimensions and predictive checks.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill pymc-python-schattenspiegel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pymc-python
Source: https://github.com/schattenspiegel/skill-foundry-skills/tree/main/skills/pymc-python
Command: npx skills add https://github.com/schattenspiegel/skill-foundry-skills --skill pymc-python-schattenspiegel

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing PyMC models that sample without errors is not the same as writing models that are statistically correct. This Skill guides the construction of identifiable generative models with named coordinates and dims, enforces prior predictive and simulated-recovery testing before fitting, and treats convergence diagnostics and posterior predictive checks as mandatory correctness gates rather than optional extras. ## Core Features & Use Cases - Model construction with shape contracts: Build pymc.Model graphs with coords/dims, Data containers, random variables, deterministics, and potentials whose shapes and coordinate lengths are asserted before sampling. - Inference and diagnostics workflow: Run multi-chain sampling with recorded seeds, then gate on divergences, R-hat, ESS, MCSE, energy/BFMI, and tree depth instead of trusting a single trace plot. - Prediction and comparison recipes: Update Data and coordinates together for out-of-sample prediction, keep predictions separate from in-sample posterior predictive draws, and attach pointwise log likelihood for ArviZ model comparison. - Use Case: You are fitting a hierarchical logistic regression and hitting divergences. The Skill walks you through checking the funnel geometry, switching to a non-centered parameterization, validating prior predictive plausibility, and confirming convergence across four chains before trusting the posterior. ## Quick Start Use the pymc-python skill to build and diagnose a hierarchical Bayesian regression model with prior predictive checks and out-of-sample prediction on new data.

Frequently Asked Questions about pymc-python

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

FAQPage Schema
How do I fix divergences in PyMC sampling?▼

Divergences in PyMC usually signal difficult posterior geometry, especially funnels in hierarchical models. First standardize predictors and try a non-centered parameterization; only raise target_accept as a follow-up after checking parameterization, and always inspect where divergences occur rather than hiding the warnings.

How do I make out-of-sample predictions with a fitted PyMC model?▼

Out-of-sample prediction in PyMC uses pm.set_data to replace Data values and observation coordinates together, then pm.sample_posterior_predictive with predictions=True. Keep predictions in a distinct InferenceData group and preserve training feature order and category encodings.

When should I use PyMC vs Bambi or NumPyro?▼

Use PyMC when you directly construct and sample a pymc.Model with explicit priors and structure. Choose Bambi for formula-driven regression, NumPyro for native JAX probabilistic programs, and ArviZ when the work starts from already-completed inference results.

Why does my PyMC model fail with shape or dims errors?▼

Shape errors occur when distribution batch dimensions, named dims, and observed data shapes disagree; dimension labels do not broadcast or transpose values for you. Assert coordinate lengths, index array bounds, and concrete array shapes before sampling instead of adding broadcast axes blindly.

How do I check if PyMC sampling converged correctly?▼

Convergence requires multiple independent chains plus rank-normalized R-hat, bulk and tail ESS, MCSE, divergences, energy/BFMI, tree depth, and parameter-specific traces. A single chain, one trace plot, or R-hat alone is not sufficient evidence of convergence.

What is the difference between Potential and a likelihood in PyMC?▼

A Potential adds an arbitrary named term to the joint log-probability but is not a random variable and is ignored by prior and posterior forward sampling. Do not use it to hide a likelihood term needed for predictive simulation; document its density and test its behavior if one is necessary.