View source: R/convenience-functions.R
prep_car_data | R Documentation |
Prepare data for the CAR model
prep_car_data(
A,
style = c("WCAR", "ACAR", "DCAR"),
k = 1,
gamma = 0,
lambda = TRUE,
stan_fn = ifelse(style == "WCAR", "wcar_normal_lpdf", "car_normal_lpdf"),
quiet = FALSE
)
A |
Binary adjacency matrix; for |
style |
Specification for the connectivity matrix (C) and conditional variances (M); one of "WCAR", "ACAR", or "DCAR". |
k |
For |
gamma |
For |
lambda |
If TRUE, return eigenvalues required for calculating the log determinant of the precision matrix and for determining the range of permissible values of rho. These will also be printed with a message if lambda = TRUE. |
stan_fn |
Two computational methods are available for CAR models using |
quiet |
Controls printing behavior. By default, |
The CAR model is:
Normal(Mu, Sigma), Sigma = (I - rho * C)^-1 * M * tau^2,
where I
is the identity matrix, rho
is a spatial autocorrelation parameter, C
is a connectivity matrix, and M * tau^2
is a diagonal matrix with conditional variances on the diagonal. tau^2
is a (scalar) scale parameter.
In the WCAR specification, C
is the row-standardized version of A
. This means that the non-zero elements of A
will be converted to 1/N_i
where N_i
is the number of neighbors for the i
th site (obtained using Matrix::rowSums(A)
. The conditional variances (on the diagonal of M * tau^2
), are also proportional to 1/N_i
.
The ACAR specification is from Cressie, Perrin and Thomas-Agnon (2005); also see Cressie and Wikle (2011, p. 188) and Donegan (2021).
The DCAR specification is inverse distance-based, and requires the user provide a (sparse) distance matrix instead of a binary adjacency matrix. (For A
, provide a symmetric matrix of distances, not inverse distances!) Internally, non-zero elements of A
will be converted to: d_{ij} = (a_{ij} + gamma)^(-k)
(Cliff and Ord 1981, p. 144; Donegan 2021). Default values are k=1
and gamma=0
. Following Cressie (2015), these values will be scaled (divided) by their maximum value. For further details, see the DCAR_A specification in Donegan (2021).
For inverse-distance weighting schemes, see Cliff and Ord (1981); for distance-based CAR specifications, see Cressie (2015 [1993]), Haining and Li (2020), and Donegan (2021).
Details on CAR model specifications can be found in Table 1 of Donegan (2021).
A list containing all of the data elements required by the CAR model in stan_car
.
Cliff A, Ord J (1981). Spatial Processes: Models and Applications. Pion.
Cressie N (2015 [1993]). Statistics for Spatial Data. Revised edition. John Wiley & Sons.
Cressie N, Perrin O, Thomas-Agnan C (2005). “Likelihood-based estimation for Gaussian MRFs.” Statistical Methodology, 2(1), 1–16.
Cressie N, Wikle CK (2011). Statistics for Spatio-Temporal Data. John Wiley & Sons.
Donegan, Connor (2021). Spatial conditional autoregressive models in Stan. OSF Preprints. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.31219/osf.io/3ey65")}.
Haining RP, Li G (2020). Modelling Spatial and Spatio-Temporal Data: A Bayesian Approach. CRC Press.
data(georgia)
## use a binary adjacency matrix
A <- shape2mat(georgia, style = "B")
## WCAR specification
cp <- prep_car_data(A, "WCAR")
1 / range(cp$lambda)
## ACAR specification
cp <- prep_car_data(A, "ACAR")
## DCAR specification (inverse-distance based)
A <- shape2mat(georgia, "B")
D <- sf::st_distance(sf::st_centroid(georgia))
A <- D * A
cp <- prep_car_data(A, "DCAR", k = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.