Think of \(\boldsymbol{\varepsilon}_{s,t}\) as a matrix of sites by years
The spatially correlated random effects are independent across time-steps
How do we get \(\Sigma\)?
\[
\begin{array}{l} \Sigma \text{ is a covariance matrix with:}\\
\Sigma_{i, j}=\sigma^{2}_{gp} \exp \left( - \text {distances}_{i,j} / \theta_{gp}\right), \text { if } i \neq j \\
\Sigma_{i, j}=\sigma^{2}_{gp}, \text { if } i=j\end{array}
\]
How do we get \(\Sigma\)?
\[
\begin{array}{l} \Sigma \text{ is a covariance matrix with:}\\
\Sigma_{i, j}=\sigma^{2}_{gp} \exp \left( - \text {distances}_{i,j} / \theta_{gp}\right), \text { if } i \neq j \\
\Sigma_{i, j}=\sigma^{2}_{gp}, \text { if } i=j\end{array}
\]
We could also get \(\Sigma\) via other correlation kernels (Gaussian, Matern, etc.)
Let’s simulate some spatiotemporal fields in Stan
simulate an iid spatio-temporal random field with an exponential kernel
library(tidyverse)library(cmdstanr)library(tidybayes)set.seed(13)n_site <-500# number of sampling locations for each year# simulate random x,y site locations:g <-data.frame(easting =runif(n_site, 0, 10),northing =runif(n_site, 0, 10))locs <-unique(g)dist_sites <-as.matrix(dist(locs)) # distances among sites n_year <-8# number of years
Let’s simulate some spatiotemporal fields in Stan
simulate an iid spatio-temporal random field with an exponential kernel
# model parameters to simulategp_theta <-1# Gaussian process scale parametergp_sigma <-0.15# Gaussian process variance / spatial noise parametersim_data <-list(n_sites =nrow(locs),n_year = n_year,dist_sites = dist_sites,gp_theta = gp_theta,gp_sigma = gp_sigma )# compile the modelsim_mod <-cmdstan_model("week10/src/sim_st_iid.stan")
Let’s simulate a spatiotemporal field
simulate an iid spatio-temporal random field with an exponential kernel
# simulate data sim_s <- sim_mod$sample(data = sim_data,fixed_param =TRUE, iter_warmup =0, iter_sampling =1,chains =1, seed =1)# extract the simulated dataeps_st <-matrix(sim_s$draws("eps_st", format ="draws_matrix"),nrow = n_site, ncol = n_year)