Prepare data for a simultaneous autoregressive (SAR) model
Prepare data for a simultaneous autoregressive (SAR) model
Given a spatial weights matrix W, this function prepares data for the simultaneous autoregressive (SAR) model (a.k.a spatial error model (SEM)) in Stan. This is used internally by stan_sar, and may also be used for building custom SAR models in Stan.
prep_sar_data(W, quiet =FALSE)
Arguments
W: Spatial weights matrix, typically row-standardized.
quiet: Controls printing behavior. By default, quiet = FALSE and the range of permissible values for the spatial dependence parameter is printed to the console.
Returns
Return's a list of data required as input for geostan's SAR models, as implemented in Stan. The list contains:
ImW_w: Numeric vector containing the non-zero elements of matrix (I−W).
ImW_v: An integer vector containing the column indices of the non-zero elements of (I−W).
ImW_u: An integer vector indicating where in ImW_w a given row's non-zero values start.
nImW_w: Number of entries in ImW_w.
Widx: Integer vector containing the indices corresponding to values of -W in ImW_w (i.e. non-diagonal entries of (I−W)).
nW: Integer length of Widx.
eigenvalues_w: Eigenvalues of W matrix.
n: Number of rows in W.
W: Sparse matrix representation of W
rho_min: Minimum permissible value of ρ (1/min(eigenvalues_w)).
rho_max: Maximum permissible value of ρ (1/max(eigenvalues_w).
The function will also print the range of permissible ρ values to the console (unless quiet = TRUE).
Details
This is used internally to prepare data for stan_sar models. It can also be helpful for fitting custom SAR models in Stan (outside of geostan), as described in the geostan vignette on custom spatial models.