mcmc-sampling-stan

Guide Bayesian MCMC sampling with Stan and RStan.

134|21|Updated Nov 12, 2025
One-click install
npx skills add https://github.com/letta-ai/skills --skill mcmc-sampling-stan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mcmc-sampling-stan
Source: https://github.com/letta-ai/skills/tree/main/ai/benchmarks/letta/terminal-bench-2/trajectory-only/mcmc-sampling-stan
Command: npx skills add https://github.com/letta-ai/skills --skill mcmc-sampling-stan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill guides Bayesian modeling and MCMC sampling using Stan (RStan or PyStan), including model specification, diagnostics, and sampling configuration.

Core Features & Use Cases

  • Environment setup: Verify Stan toolchains and compilers.
  • Model specification: Write data, parameters, and model blocks with priors.
  • Diagnostics: Essential checks (R-hat, ESS, divergences, treedepth, energy).

Quick Start

Example: fit a Stan model with 4 chains, check R-hat < 1.01 and ESS > 400, and address any divergences.

Frequently Asked Questions about mcmc-sampling-stan

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

FAQPage Schema
How do I check MCMC convergence diagnostics like R-hat and ESS?

MCMC convergence diagnostics assess whether your Stan sampling has run long enough. R-hat measures chain mixing (target < 1.01), ESS estimates effective sample size (target > 400), and divergences flag numerical problems. Stan reports these automatically after sampling; address any violations by increasing iterations, adjusting step size, or reparameterizing your model.

What's the best way to set up Stan and RStan for Bayesian modeling?

Environment setup verifies Stan toolchains, compilers, and dependencies before modeling. Install Stan or RStan with version-pinned packages, check compiler readiness, and validate installation by compiling a test model. This prevents build failures and ensures reproducible sampling across projects.

How do I write and specify a Stan model with priors and parameters?

Stan model specification requires writing data, parameters, and model blocks with explicit priors. Define your data types and dimensions in the data block, declare parameters to estimate in the parameters block, and specify the likelihood and priors in the model block. Proper specification prevents sampling errors and improves diagnostics.

Can I use Stan for hierarchical or multilevel Bayesian models?

Yes, Stan supports hierarchical and multilevel modeling through nested parameter declarations and group-level priors. You define population-level hyperparameters and group-specific parameters, then use vectorized operations for efficiency. This enables pooling information across groups while capturing variation.

Why am I getting divergences or high treedepth warnings in Stan sampling?

Divergences and high treedepth indicate numerical instability or inefficient sampling geometry. Common causes include poor prior choices, unscaled parameters, or insufficient adaptation. Address these by reparameterizing, standardizing inputs, increasing adapt_delta, or adjusting max_treedepth in your sampling configuration.