← ClaudeAtlas

stan-fundamentalslisted

Foundational knowledge for writing modern Stan models including program structure, type system, distributions, and best practices. Use when creating or reviewing Stan models.
choxos/BiostatAgent · ★ 4 · AI & Automation · score 75
Install: claude install-skill choxos/BiostatAgent
# 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