View source: R/convenience-functions.R
shape2mat | R Documentation |
Creates sparse matrix representations of spatial connectivity structures
shape2mat(
shape,
style = c("B", "W"),
queen,
method = c("queen", "rook", "knn"),
k = 1,
longlat = NULL,
snap = sqrt(.Machine$double.eps),
t = 1,
st.style = c("contemp", "lag"),
quiet = FALSE
)
shape |
An object of class |
style |
What kind of coding scheme should be used to create the spatial connectivity matrix? Defaults to "B" for binary; use "W" for row-standardized weights. |
queen |
Deprecated: use the ‘method’ argument instead. This option is passed to |
method |
Method for determining neighbors: queen, rook, or k-nearest neighbors. See Details for more information. |
k |
Number of neighbors to select for k-nearest neighbor method. Passed to |
longlat |
If longlat = TRUE, Great Circle (rather than Euclidean) distances are used; great circle circle distances account for curvature of the Earth. |
snap |
Passed to |
t |
Number of time periods. Only the binary coding scheme is available for space-time connectivity matrices. |
st.style |
For space-time data, what type of space-time connectivity structure should be used? Options are "lag" for the lagged specification and "contemp" (the default) for contemporaneous specification (see Details). |
quiet |
If |
The method argument currently has three options. The queen contiguity condition defines neighbors as polygons that share at least one point with one another. The rook condition requires that they share a line or border with one another. K-nearest neighbors is based on distance between centroids. All methods are implemented using the spdep package and then converted to sparse matrix format.
Alternatively, one can use spdep directly to create a listw
object and then convert that to a sparse matrix using as(listw, 'CsparseMatrix')
for use with geostan.
Haining and Li (Ch. 4) provide a helpful discussion of spatial connectivity matrices (Ch. 4).
The space-time connectivity matrix can be used for eigenvector space-time filtering (stan_esf
. The 'lagged' space-time structure connects each observation to its own past (one period lagged) value and the past value of its neighbors. The 'contemporaneous' specification links each observation to its neighbors and to its own in situ past (one period lagged) value (Griffith 2012, p. 23).
A spatial connectivity matrix in sparse matrix format. Binary matrices are of class ngCMatrix
, row-standardized are of class dgCMatrix
, created by sparseMatrix
.
Bivand, Roger S. and Pebesma, Edzer and Gomez-Rubio, Virgilio (2013). Applied spatial data analysis with R, Second edition. Springer, NY. https://asdar-book.org/
Griffith, Daniel A. (2012). Space, time, and space-time eigenvector filter specifications that account for autocorrelation. Estadística Espanola, 54(177), 7-34.
Haining, Robert P. and Li, Guangquan (2020). Modelling Spatial and Spatial-Temporal Data: A Bayesian Approach. CRC Press.
edges
row_standardize
n_nbs
data(georgia)
## binary adjacency matrix
C <- shape2mat(georgia, "B", method = 'rook')
## number of neighbors per observation
summary( n_nbs(C) )
head(Matrix::summary(C))
## row-standardized matrix
W <- shape2mat(georgia, "W", method = 'rook')
## summary of weights
E <- edges(W, unique_pairs_only = FALSE)
summary(E$weight)
## space-time matricies
## for eigenvector space-time filtering
## if you have multiple years with same geometry/geography,
## provide the geometry (for a single year!) and number of years \code{t}
Cst <- shape2mat(georgia, t = 5)
dim(Cst)
EVst <- make_EV(Cst)
dim(EVst)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.