Back to Skills

stan-fundamentals

verified

Foundational knowledge for writing Stan 2.37 models including program structure, type system, distributions, and best practices. Use when creating or reviewing Stan models.

View on GitHub

Marketplace

bayesian-modeling-agent

choxos/BayesianAgent

Plugin

bayesian-modeling

statistics

Repository

choxos/BayesianAgent

plugins/bayesian-modeling/skills/stan-fundamentals/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/choxos/BayesianAgent/blob/main/plugins/bayesian-modeling/skills/stan-fundamentals/SKILL.md -a claude-code --skill stan-fundamentals

Installation paths:

Claude
.claude/skills/stan-fundamentals/
Powered by add-skill CLI

Instructions

# Stan Fundamentals

## When to Use This Skill

- Writing new Stan models from scratch
- Understanding Stan program structure
- Learning Stan syntax and conventions
- Translating models from other languages to Stan
- Optimizing existing Stan code

## Program Structure

Stan models have up to 7 blocks in this exact order:

```stan
functions { }           // User-defined functions
data { }                // Input data declarations
transformed data { }    // Data preprocessing
parameters { }          // Model parameters
transformed parameters { } // Derived parameters
model { }               // Log probability
generated quantities { }  // Posterior predictions
```

All blocks are optional. Empty string is valid (but useless) Stan program.

## Type System Quick Reference

### Scalars
```stan
int n;                    // Integer
real x;                   // Real number
complex z;                // Complex number
```

### Vectors and Matrices
```stan
vector[N] v;              // Column vector
row_vector[N] r;          // Row vector
matrix[M, N] A;           // Matrix
```

### Arrays (Modern Syntax)
```stan
array[N] real x;          // 1D array of reals
array[M, N] int y;        // 2D array of integers
array[J] vector[K] theta; // Array of vectors
```

### Constrained Types
```stan
real<lower=0> sigma;              // Non-negative
real<lower=0, upper=1> p;         // Probability
simplex[K] theta;                 // Sums to 1
ordered[K] c;                     // Ascending
corr_matrix[K] Omega;             // Correlation
cov_matrix[K] Sigma;              // Covariance
cholesky_factor_corr[K] L_Omega;  // Cholesky correlation
```

## Key Distributions

### Continuous (SD parameterization!)
```stan
y ~ normal(mu, sigma);      // sigma is SD
y ~ student_t(nu, mu, sigma);
y ~ cauchy(mu, sigma);
y ~ exponential(lambda);
y ~ gamma(alpha, beta);
y ~ beta(a, b);
y ~ lognormal(mu, sigma);
```

### Discrete
```stan
y ~ bernoulli(theta);
y ~ binomial(n, theta);
y ~ poisson(lambda);
y ~

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5069 chars