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)

Arguments

W

Spatial weights matrix, typically row-standardized.

Value

list of data to add to a Stan data list:

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 \(\rho\) (1/min(eigenvalues_w)).

rho_max

Maximum permissible value of \(\rho\) (1/max(eigenvalues_w).

The function will also print the range of permissible \(\rho\) values to the console.

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).

Examples

data(georgia)
W <- shape2mat(georgia, "W")
sar_dl <- prep_sar_data(W)