Bayesian structural time series modeling

For latent time series, you want to declare the innovations as the parameters and construct the variables of interest in transformed parameters according to the assumed generative process. So, it would be something like this

parameters {
  vector[T] u_err;
  vector[T] v_err;
  real<lower=0> s_slope;
  real<lower=0> s_level;
  ...
}
transformed parameters {
  vector[T] u;
  vector[T] v;
  u[1] = u_err[1];
  v[1] = v_err[1];
  for (t in 2:T) {
    u[t] = u[t - 1] + s_level * u_err[t];
    v[t] = v[t - 1] + s_slope * v_err[t];
  }
}
model {
  u_err ~ normal(0,1);
  v_err ~ normal(0,1);
  ...
}
1 Like