[R-sig-Geo] Use pre-calculated population weighted road-distance matrix in spdep package
Suchar, Vasile (vasiles@uidaho.edu)
vasiles at uidaho.edu
Wed Aug 19 19:43:27 CEST 2015
Hi,
While I am "old" in statistics and R, I just started with spatial data and I have a few problems.
At this time, I am trying to evaluate the spatial autocorrelation of "counts" over a series of "counties". For simplicity I created a simple example mimicking the real data which is more extensive. The counts may be also transformed, if necessary. See example bellow.
I created a population-weighted road-distance matrix between counties. I made a weight matrix 1/dij (a row-standardized matrix can also be created) and run a Moran's I test for spatial autocorrelation using function Moran.I in package "ape".
But I would really like to use these population-weighted road distances to explore the wide range of spatial weights and spatial autoccorelation tests offered by "spdep" package. The spatial weights (listw) in "spdep" results from neighbor list objects (nb), created from grid cells, graph structures, etc.
Do you have any idea how to use my distance matrix in spdep, or have any suggestions about other packages that will allow the use of customized "distance" matrices?
By the way, this is my first R post too, so hopefully is appropriate...
Thank you.
Example:
# number of cases in each county
counts=data.frame(c("a","b", "c", "d"), c(1:4))
colnames(counts)=c("county", "counts")
counts
## county counts
## 1 a 1
## 2 b 2
## 3 c 3
## 4 d 4
# distance matrix between counties
dist=matrix(c(1:16), nrow=4, ncol=4)
diag(dist)=0
colnames(dist)=counts$county
rownames(dist)=counts$county
dist
## a b c d
## a 0 5 9 13
## b 2 0 10 14
## c 3 7 0 15
## d 4 8 12 0
# I can create a weight matrix or a row standardized
dist.w=1/dist
diag(dist.w)=0
# Moran's I calculation
library(ape)
Moran.I(counts$counts, dist.w)
## $observed
## [1] -0.312481
##
## $expected
## [1] -0.3333333
##
## $sd
## [1] 0.1451662
##
## $p.value
## [1] 0.8857809
Sincerely,
Alex
Vasile-Alexandru Suchar
University of Idaho
Email: vasiles at uidaho.edu<mailto:vasiles at uidaho.edu>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list