## 4 Methodology
### Model Specifications
#### 4.1.4 Spatial Random Parameters Logit Model  
Both the RP-logit model and the RI-logit model can identify the unobserved heterogeneity across crashes effectively. Nevertheless, some critical issues still need to be resolved. A typical representative is to identify the spatial correlation of crashes. Hence, the SRP-logit model was proposed to comprehensively accommodate the spatial correlation and unobserved heterogeneity and the derivation process is as follows. To address the potential variations across road segments, an unstructured error term was constructed. The RP-logit model can be modified to:  
\[ \begin{split}& logit\Big{(}P_{i,k}^{w}\Big{)}=\log\frac{P_{i,k}^{w}}{P _{i,1}^{w}}=\beta_{i,k,0}+\sum\limits_{l=1}^{L}\beta_{i,k,l}x_{i,l}^{w}+u_{k}^ {w},\ (k=2,\ 3)\\ & u_{k}^{w}{\sim}\ N(0,\ \sigma_{u_{k}}^{2}),\end{split}  \tag{10}\]  
where the error term \(u_{k}^{w}\) was accommodated to permit the potential within-segment correlation and cross-segment heterogeneity and followed normal distribution. \(\sigma_{u_{k}}^{2}\) represents the variance of unstructured error term. In most cases, the existence of spatial correlation is reasonable because the adjacent segments will have similar geometric features and environments [47; 54]. This may lead to certain factors shared among adjacent crashes [11]. As demonstrated by [PERSON] and [PERSON] [58], random variations across sites may be structured spatially due to the complexity of traffic interactions around crash sites. To this end, a structured spatial error term \(s_{k}^{w}\) was included in the regression function, resulting in the final SRP-logit model:  
\[logit\Big{(}P_{i,k}^{w}\Big{)}=\log\frac{P_{i,k}^{w}}{P_{i,1}^{w}}=\beta_{i,k,0}+\sum\limits_{l=1}^{L}\beta_{i,k,l}x_{i,l}^{w}+u_{k}^{w}+s_{k}^{w},\ (k=2,\ 3). \tag{11}\]  
An effective and commonly used joint density function for the spatial effect term \(s_{k}^{w}\) was in terms of pairwise differences in errors and a spatial variation term \(\sigma_{s_{k}}^{2}\)[59]:  
\[P(s_{k})\propto\exp\left[-0.5\eta^{-1}\sum\limits_{w\
eq\ \
eq\ {w^{\prime}}}\left(s_{k}^{w}-s_{k}^{w^{\prime}}\right)^{2}\right],\ \eta=\sigma_{s_{k}}^{2}. \tag{12}\]  
A valid conditional prior following a normal distribution was implied for \(s_{k}^{w}\) conditioning on the impact of \(s_{k}^{w^{\prime}}\) on the remaining observation road segments. Hence, we have:  
\[s_{k}^{w}\Big{|}s_{k}^{w^{\prime}}\sim N\left(\overline{s_{k}^{w}},\ \frac{\sigma_{s_{k}}^{2}}{\sum_{w\
eq\ {w^{\prime}}}\delta_{w,\ w^{\prime}}}\right),\ \ \overline{s_{k}^{w}}=\frac{\sum_{w\
eq\ {w^{\prime}}}\left(\delta_{w,\ {w^{\prime}}}s_{k}^{w^{\prime}} \right)}{\sum_{w\
eq\ {w^{\prime}}}\delta_{w,\ {w^{\prime}}}}, \tag{13}\]  
where \(\sum_{w\
eq\ {w^{\prime}}}\delta_{w,\ {w^{\prime}}}\) denotes the total number of neighbors of road segment \(w\); \(\delta_{w,\ {w^{\prime}}}\) represents the un-normalized weight between segments \(w\) and \(w^{\prime}\), which is an adjacency-based measure. The most common neighboring structure is the first-order neighbors, which can be defined as all road segments that are directly connected with the one in question [11]. Specifically, if a directly connected relationship is presented between segments \(w\) and \(w^{\prime}\), we have \(\delta_{w,\ w^{\prime}}=1\); otherwise, \(\delta_{w,\ w^{\prime}}=0\). The conditional variance is inversely proportional to the number of adjacent segments, and the conditional mean is the mean of the neighboring spatial effects. A similar procedure was discussed by [PERSON] et al. [60]. The spatial correlation was evaluated by calculating the ratio of spatial variation in the whole heterogeneity variation, denoted as \(\tau_{{}_{k}}\). The specific calculation process is as follows. \[\tau_{{}_{k}}=\frac{\sigma_{{}_{k_{\text{r}}}}^{2}}{\sigma_{{}_{k_{\text{r}}}}^{2 }+\sigma_{{}_{\text{u}_{\text{z}}}}^{2}}, \tag{14}\]  
where \(\sigma_{{}_{\text{z}}}^{2}\) is the spatial variance; \(\sigma_{{}_{\text{u}_{\text{z}}}}^{2}\) is the posterior variance of unstructured error term.