Bayesian time series models including AR, MA, ARMA, state-space models, and dynamic linear models in Stan and JAGS.
View on GitHubchoxos/BayesianAgent
bayesian-modeling
plugins/bayesian-modeling/skills/time-series-models/SKILL.md
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/choxos/BayesianAgent/blob/main/plugins/bayesian-modeling/skills/time-series-models/SKILL.md -a claude-code --skill time-series-modelsInstallation paths:
.claude/skills/time-series-models/# 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 {
sigma_y ~ exponential(1);
sigma_mu ~ exponential(1);
// State evolution (random walk)
mu[1] ~ normal(y[1], sigma_y);
mu[2:T] ~ normal(mu[1:(T-1)], sigma_mu);
// Observations
y ~ normal(mu, sigma_y);
}
```
## Local Linear Trend
### Stan
```stan
parameters {
vector[T] mu; // Level
vector[T] delta; // Trend
real<lower=0> sigma_y;
real<lower=0> sigma_mu;
real<lower=0> sigma_delta;
}
model {
// Level evolution
mu[2:T] ~ normal(mu[1:(T-1)] + delta[1: