Going back to your original model specification, assuming that you can convert those element-wise univariate normal priors to multivariate normal priors over vectors (over all spatial units for each time step of phi
, and over all time steps for delta
) the Stan code might look something like:
data {
...
int K; // number of spatial units
int T; // number of time steps
}
parameters {
...
vector[K] phi[T];
vector[T] delta;
}
model {
...
for (t in 1:T)
// phi[t] is a vector with one element per spatial unit
phi[t] ~ multi_normal...
delta ~ multi_normal...
}
There are ways to implement CAR priors more efficiently that do not require using any of the multi_normal*
functions, and these are described in the case studies mentioned above.
To use a temporal AR 1 prior on delta
, you could use the covariance matrix for an AR 1 process (https://stats.stackexchange.com/questions/295102/how-to-write-variance-covariance-matrix-of-ar1-process-in-r), or you could specify the AR 1 prior using the transformed parameters block (Migrated from Google Group: AR(1) Logistic Regression Funnel).
I’d recommend starting with the simplest version of this model that you can, and then slowly add complexity and verify that you can recover parameters for a sequence of models that are increasing in complexity (essentially following Stan best practices), e.g.,
- Ridiculously simple Poisson model
- Model with a non-time varying spatial effect
- Model with a time varying spatial effect
- Model with a time varying spatial effect + a temporal effect