data { int T; ...}parameters {
real eps_0;
vector[T - 1] eps_raw;
real<lower=0> phi; real<lower=0> sigma;}
model {
vector[T] eps;
eps[1] = eps_0;
for (t in 2:T)
eps[t] = phi * eps[t - 1] + sigma * eps_raw[t - 1];
target += normal_lpdf(eps_0 | 0, sigma * sqrt(1 - square(phi)));
target += normal_lpdf(eps_raw | 0, 1);
...
}
Thank you Ben. This is very helpful. Just curious, was the way I had written the model wrong or computationally inefficient?
In this parameterization, the primitive parameters eps_raw are iid standard normal a priori, which makes it much easier for Stan to move around than if eps were a primitive parameter.