← ClaudeAtlas

time-series-modelslisted

Bayesian time series models including AR, MA, ARMA, state-space models, and dynamic linear models in Stan and JAGS.
choxos/BiostatAgent · ★ 4 · AI & Automation · score 75
Install: claude install-skill choxos/BiostatAgent
# Time Series Models ## AR(1) Model ### Stan ```stan data { int<lower=0> T; vector[T] y; } parameters { real mu; real<lower=-1, upper=1> phi; // Stationarity real<lower=0> sigma; } model { mu ~ normal(0, 10); phi ~ uniform(-1, 1); sigma ~ exponential(1); // Stationary initial distribution y[1] ~ normal(mu, sigma / sqrt(1 - phi^2)); // AR(1) likelihood for (t in 2:T) y[t] ~ normal(mu + phi * (y[t-1] - mu), sigma); } ``` ### Vectorized Stan (Efficient) ```stan model { y[1] ~ normal(mu, sigma / sqrt(1 - square(phi))); y[2:T] ~ normal(mu + phi * (y[1:(T-1)] - mu), sigma); } ``` ### JAGS ``` model { y[1] ~ dnorm(mu, tau / (1 - phi * phi)) for (t in 2:T) { y[t] ~ dnorm(mu + phi * (y[t-1] - mu), tau) } mu ~ dnorm(0, 0.001) phi ~ dunif(-1, 1) tau ~ dgamma(0.001, 0.001) sigma <- 1/sqrt(tau) } ``` ## AR(p) Model ### Stan ```stan data { int<lower=0> T; int<lower=1> P; // AR order vector[T] y; } parameters { real mu; vector[P] phi; real<lower=0> sigma; } model { mu ~ normal(0, 10); phi ~ normal(0, 0.5); sigma ~ exponential(1); for (t in (P+1):T) { real pred = mu; for (p in 1:P) pred += phi[p] * (y[t-p] - mu); y[t] ~ normal(pred, sigma); } } ``` ## Local Level (Random Walk + Noise) ### Stan ```stan data { int<lower=0> T; vector[T] y; } parameters { vector[T] mu; // Latent state real<lower=0> sigma_y; // Observation noise real<lower=0> sigma_mu; // State noise } model