Vectorization of state space models - double check

I am building out some state-space models for our time series data. I am working off these models State space models . I am trying to vectorize the models on github and then compare them to the results in the book.

I wanted to check my understanding here.

Given this:

mu[1] ~ normal(y[1], sigma[3]);
  for (t in 2:n)
    mu[t] ~ normal(mu[t-1], sigma[3]);

I can do this?:

mu[1] ~ normal(y[1], sigma[3]);
mu[2:n] ~ normal(mu[n-1], sigma[2]);

And

 v[1] ~ normal(0, sigma[1]);
  for(t in 2:n-1)
    v[t] ~ normal(v[t-1], sigma[1]);

would be ?

v[1] ~ normal(0, sigma[1]);
v[2:n-1] ~ normal(v[n-1], sigma[1]);

Thanks for eyeballs and double check on this!

ara

I think you need.

mu[2:n] ~ normal(mu[1:(n-1)], sigma[3]);

and

v[2:(n-1)] ~ normal(v[1:(n-2)], sigma[1]);

Otherwise the mean for each time point is the one but last time point in the time series. I am not sure whether you need the round brackets around the indices (n-1, n-2) but I got burned in R a couple of days ago, so I just added them to be sure.

2 Likes

Thanks @stijn! Mine looked weird but I couldn’t place my finger on it. Appreciate the clarification.

ara