I am trying to fit a simple AR 1 model, as shown below. I read over the missing values section in the Stan manual, but it is not clear to me how to fit this model if I have missing observations in my data. Would it be as straight forward as setting \tau = 0 if there is a missing observation at time i-1? Or draw another value of \tau_0 at the time point before each missing observation? In some sense, treating it again as requiring an initial value.

The easiest way to do do it is to declare in the parameters block a vector, say y_miss whose size is equal to the number of missing observations. Then, weave together a â€ścomplete dataâ€ť vector in temporal order that consists of the observed observations and y_miss. The â€ścomplete dataâ€ť vector then has an AR1 â€ścomplete data likelihoodâ€ť.

Thanks for you reply. As long as my yâ€™s are in the right temporal order, it looks like I can add indexing to identify the responses that are missing, and then combine them into one big vector in the transformed parameters block.

One more quick follow up, I am looping over the all observations rather than doing nested loops for each time series. I have a time vector that that repeats the time indicesâ€“e.g., 1 2 3 1 2 3â€¦1 2 3 (if I had 3 time points for each series). Without the AR term it looks basically like the following (assume x[i] indicates the time point).

model{
for(i in 1:N){
y[i] ~ normal(f[x[i]], sigma)
}

Is there simple way to let the model know that at each time point i = 1, we need to reset the AR process for the next series? I was thinking something like if x[i]==1 let \eta \sim N(0, a); otherwise, \eta = \rho\eta_{i-1}. Does this make sense?

You can put in if {} else {} statements but for observations where i = 1, the unconditional variance is not sigma but rather sigma / sqrt(1 - square(rho)).