# Spatiotemporal Traffic Prediction Using Hierarchical Bayesian Modeling
## 3 Methodology and Data
### Hierarchical Bayesian Modeling
#### 3.1.1 Gaussian Processes (GP) Model  
The GP includes the temporal effect as well as the spatial effect denoted in Equation (6), which captures the space-time relationship. [52]. \[[Y(s,t):s\in D_{s},\ t\in D_{t}] \tag{6}\]  
where \(Y\) is the value of the traffic flow at location \(s\) at time \(t\); \(D_{s}\) is a set of spatial coordinates \((s_{i},s_{j})\); and \(i,j=\ 0,\ldots,\ (m+1)\times(m+1),\ (m+1)\times(m+1)\) is the total number of locations. For the temporal component, \(D_{t}\) is a set of time series where we have two time components denoted by \(l\) and \(t\) that represent the short time component and the long time component, respectively. In our dataset, we only use the day and month at the observed spatial points. The dataset has 28 locations, and we use the generic spatial process to define the spatial process \(Y_{t_{0}}(s_{0}),\ldots,\ Y_{t_{0}}(s_{0}+\ 28\Delta)\). We compare the spatial process to the temporal process \(Y_{t_{0}}(s_{0}),\ldots,\ Y_{t_{0}+28}(s_{0})\) to decompose \(Y\) in Equation (6), where the spatial process at fixed time \(t_{0}\) and the temporal process at fixed spatial point \(s_{0}\) are denoted by Equations (7) and (8), respectively [52]:  
\[Y_{t_{0}}=\ (Y_{t_{0}}(s_{0}),\ldots,\ Y_{t_{0}}(s_{0}+\ 28\Delta))^{\top} \tag{7}\]  
\[Y_{s_{0}}=\ (Y_{t_{0}}(s_{0}),\ldots,\ Y_{t_{0}+28}(s_{0}))^{\top} \tag{8}\]  
By combining \(Y_{t_{0}}\) and \(Y_{s_{0}}\) as follows:  
\[Y_{t_{0}(s_{i})}|Y_{t_{0}(s_{j})}:j\
eq i\sim\mathit{Gau}((\phi_{t_{0}}/(1+ \phi_{t_{0}}^{2}))Y_{t_{0}(s_{j}-1)}+Y_{t_{0}(s_{j}+1)},\sigma_{t_{0}}^{2}/(1+ \phi_{t_{0}}^{2})) \tag{9}\]  
where the dimensional distributions are determined by the mean function \(\mu(s,t)\), and the covariance matrices \(\mathit{cov}(Y(s,t),Y((s,t))\prime)\) for all spatial points \(s\in D\). Since we are using the GP to build the HBM, we define the hierarchy of the GP in Equation (10):  
\[Y_{I(s_{ij};t)}=f(x_{I})_{(s_{ij};t)}+\epsilon_{I(s_{ij};t)} \tag{10}\]  
The long time unit is denoted by \(L\), where \(l=1,\ldots,L\) and the short time unit is denoted by \(Tl\), where \(t=1,\ldots,Tl\). Our dataset is represented by \(Y_{l(s_{ij};t)}\), where \(e_{l(s_{ij};t)}\) is a random error that we assume to be independently normally-distributed that follows \(e_{i}\sim N(0,\sigma_{e}^{2})\), and we can break down Equation (2) as follows:  
\[\eta_{(s_{ij};t_{0})} =(\eta_{(s_{11};t_{1})},\ldots,\eta_{(s_{m+1};t_{1})}) \tag{11}\] \[\mu_{(s_{ij};t_{0})} =(\mu_{(s_{11};t_{1})},\ldots,\mu_{(s_{m+1};t_{1})}) \tag{12}\]  
Let \(\eta_{(s_{ij};t_{0})}\) be the spatiotemporal random effects, and \(\mu_{(s_{ij};t_{0})}\) is the mean function at location \(s_{ij}\) at time \(t_{0}\). The mean \(\mu_{(s_{ij};t_{0})}\) can be represented by \(\chi\beta\), where \(\beta\) represents the vector of regression coefficients and \(\chi\) represents the matrix of the covariates between time and space. Thus, Equation (2) can be written as follows:  
\[f(x_{l})_{(s_{ij};t)}=\chi_{l(s;t)}\beta+\eta_{(s_{ij};t)} \tag{13}\]  
Different spatial covariance matrices show significant positive results on the prediction outcomes, where estimating the correlation for the space-time effect on a specific observed value is a major step in fitting the model. In the following, we briefly describe these four covariance matrices. **Spatial Covariance Matrices:** In GP, the spatial correlation parameter is calculated by applying one of the four covariance matrices: exponential, Gaussian, spherical and Matern. We refer to the spatial covariance function by \(\kappa(s_{i}-s_{j};\phi,\
u)\), which includes three parameters: \(\phi\), \(\
u\) and the distance between two spatial points \(s_{i}\) and \(s_{j}\), which is calculated as \(\parallel s_{i}-s_{j}\parallel\).