This vignette gives a few examples on how to create different spatial
weights matrices using the SDPDmod
package.
A spatial weights matrix is an \(N \times N\) non-negative matrix, where \(N\) is the size of the data set. The elements of the spatial matrix \(W\), \(w_{ij}\) are non-zero if \(i\) and \(j\) are considered to be neighbors and zero otherwise. Since unit \(i\) can not be a neighbor to itself, the diagonal elements of the spatial weights matrix are zero, i.e. \(w_{ij}=0\).
Data on German districts and distances between district’s centroids
in meters are included in the SDPDmod
package and are used
for the examples.
\[ w_{ij} = \begin{cases} 1,&i &\text{and} &j &\text{have a shared boundary}\\ 0,& \text{otherwise} \end{cases} \]
\[ w_{ij} = \begin{cases} 1,& \text{if unit} &j &\text{is one of the} &k &\text{nearest neighbor of} &i\\ 0,& \text{otherwise} \end{cases} \]
\[ w_{ij} = d_{ij}^{-\alpha} \] \(d_{ij}\) - distance between units \(i\) and \(j\), \(\alpha\) - positive exponent
## inverse distance no cut-off
W_inv1 <- InvDistMat(distMat = gN3dist)
## inverse distance with cut-off 100000 meters
W_inv2 <- InvDistMat(distMat = gN3dist, distCutOff = 100000)
gN3dist2 <- gN3dist/1000 ## convert to kilometers
## inverse distance with cut-off 100 km
W_inv3 <- InvDistMat(distMat = gN3dist2, distCutOff = 100)
## inverse distance with cut-off 200km and exponent 2
W_inv4 <- InvDistMat(gN3dist2, 200, powr = 2)
\[ w_{ij} = exp(-\alpha d_{ij}) \] \(d_{ij}\) - distance between units \(i\) and \(j\), \(\alpha\) - positive exponent
## Exponential distance no cut-off
W_exp1 <- ExpDistMat(distMat = gN3dist)
## Exponential distance with cut-off 100000 meters
W_exp2 <- ExpDistMat(distMat = gN3dist, distCutOff = 100000)
gN3dist2 <- gN3dist/1000 ## convert to kilometers
## Exponential distance with cut-off 100 km
W_exp3 <- ExpDistMat(gN3dist2, 100)
## Exponential distance with cut-off 100 km
W_exp4 <- DistWMat(gN3dist2, 100, type = "expo")
all(W_exp3==W_exp4)
#> [1] TRUE
## Exponential distance with cut-off 200 km and exponent 0.001
W_exp5 <- ExpDistMat(gN3dist2, 200, expn = 0.001)
\[ w_{ij} = \begin{cases} (1-(\frac{d_{ij}}{D})^p)^p,&0 \leq d_{ij} \leq D \\ 0,& d_{ij} \geq D \end{cases} \] \(d_{ij}\) - distance between units \(i\) and \(j\), \(p\) - positive exponent, \(D\) - distance cut-off
## Double-Power distance no cut-off, exponent 2
W_dd1 <- DDistMat(distMat = gN3dist)
## Double-Power distance with cut-off 100000 meters, exponent 2
W_dd2 <- DDistMat(distMat = gN3dist, distCutOff=100000)
gN3dist2 <- gN3dist/1000 ## convert to kilometers
## Double-Power distance with cut-off 100 km
W_dd3 <- DDistMat(gN3dist2, 100)
## Double-Power distance with cut-off 100 km
W_dd4 <- DistWMat(gN3dist2, 100, type = "doubled")
all(W_dd3==W_dd4)
#> [1] TRUE
## Double-Power distance with cut-off 200km and exponent 3
W_dd5 <- DDistMat(gN3dist2, 200, powr = 3)
\[ w_{ij}^{normalized} =w_{ij}/\sum_{j=1}^N w_{ij} \]