 # Running a hierachical spatio-temporal geostaistical model in STAN

Dear STAN groups

I am a STAN beginner, so I would like to know whether STAN can handle a hierachical spatio temporal model.

y\left ( s,t \right )=z\left ( x,t \right )\beta+\xi\left ( x,t \right )+\epsilon
\xi\left ( x,t \right )=a\xi\left ( x,t-1 \right )+\omega\left ( x,t \right )
\omega follows a multivariate gaussian distribution with zero mean and a matern defined covriance matrix.

It is clear that this model can be done in INLA (grouped AR1 model), but I intend to run this model through a sampling approach rather than an approximation.

Could STAN handle this model?
More clearly, I do not know how to deal with the second stage of this model, how I multiply the separatable covariance matrices.

Best regards

(Just FYI, LaTeX now works on the discourse (!!!), so you can wrap equations in \$s to get it to render maths

In the case where the noise is Gaussian, the INLA method is exact up to the integration over the hyperparameters, so the solution you get there will probably be as good (if not better) than the one you get out of Stan.

Stan is a programming language, so you can just program up the model in the same way you wrote it:

 model {
for (t in 2:T)
xi[n] ~ multi_normal_c( a * xi[t-1], K);
}


where K is the covariance matrix of the GP. You’ll probably have ot do some tricks (like the noncentering described in the GP chapter of the manual) to make it run well.

1 Like

OK， I see. thank you Daniel

I am running the same model, but the chains are not mixed. Is there any suggestion on the code?

Hello, could you share your code here? Maybe I can help you find whether the problem comes from data or coding.