R/convenience-functions.R
prep_sar_data.Rd
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)
Spatial weights matrix, typically row-standardized.
Controls printing behavior. By default, quiet = FALSE
and the range of permissible values for the spatial dependence parameter is printed to the console.
Return's a list of data required as input for geostan's SAR models, as implemented in Stan. The list contains:
Numeric vector containing the non-zero elements of matrix \((I - W)\).
An integer vector containing the column indices of the non-zero elements of \((I - W)\).
An integer vector indicating where in ImW_w
a given row's non-zero values start.
Number of entries in ImW_w
.
Integer vector containing the indices corresponding to values of -W
in ImW_w
(i.e. non-diagonal entries of \((I-W)\)).
Integer length of Widx
.
Eigenvalues of \(W\) matrix.
Number of rows in \(W\).
Sparse matrix representation of \(W\)
Minimum permissible value of \(\rho\) (1/min(eigenvalues_w)
).
Maximum permissible value of \(\rho\) (1/max(eigenvalues_w)
.
The function will also print the range of permissible \(\rho\) values to the console (unless quiet = TRUE
).
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.