[R-sig-Geo] Spatial correlogram - Problems with creating neigbourhood list and weights
Roger Bivand
Roger.Bivand at nhh.no
Tue Jan 5 15:07:14 CET 2010
On Tue, 5 Jan 2010, Strubbe Diederik wrote:
> Dear all,
>
> I have a dataset with several lat-long coordinates (48) and corresponding residuals values (not a grid). Using the spdep package, I try to create a correlogram of these residuals according to several lags (i.e. distance classes) but I can?t seem to get the neighborhood and weights right?
>
> Below, I show the main parts of the code and the results:
>
> rnp <- read.table ("D:/Diederik/RESID_WITH_DISTANCE.csv",sep=",",header=T)
> resids <- rnp$RESID
>
> ##create neighbourhood list and make symmetric##
> xy <- cbind(rnp$X, rnp$Y)
> rnp_nb <-knn2nb(knearneigh(xy, longlat=TRUE))
> rnp_nb <-make.sym.nb(rnp_nb)
> rnp_nb
You have chosen a k=1 first nearest neighbour scheme, was this intended?
>
> Neighbour list object:
> Number of regions: 48
> Number of nonzero links: 66
> Percentage nonzero weights: 2.864583
> Average number of links: 1.375
>
> ##create weights##
> rnp_w <- nb2listw(rnp_nb,glist=NULL,style="W",zero.policy=FALSE)
> rnp_w
>
> Characteristics of weights list object:
> Neighbour list object:
> Number of regions: 48
> Number of nonzero links: 66
> Percentage nonzero weights: 2.864583
> Average number of links: 1.375
>
> Weights style: W
> Weights constants summary:
> n nn S0 S1 S2
> W 48 2304 48 73.72222 209.3333
>
> ## Moran's I test for spatial autocorrelation##
> moran.test(resids, rnp_w, randomisation=TRUE, ?)
>
> Moran's I test under randomisation
>
> data: resids
> weights: rnp_w
> Moran I statistic standard deviate = -0.3353, p-value = 0.6313
> alternative hypothesis: greater
> sample estimates:
> Moran I statistic Expectation Variance
> -0.08060979 -0.02127660 0.03130522
>
Note that Moran's I for this symmetrized first nearest neighbour scheme is
not significant.
>
>
>
> ##make a correlogram##
> sp.correlogram(rnp_nb, resids, order=16, method="I", zero.policy=TRUE)
>
> Error in nb2listw(nblags[[i]], style = style, zero.policy = zero.policy) :
> No valid observations
This is most likely a result of your choice of symmtrized first nearest
neighbours, leading to many graph components and/or the unrealistically
high order=:
library(spdep)
data(columbus)
nbk1 <- knn2nb(knearneigh(cbind(columbus$X, columbus$Y)))
snbk1 <- make.sym.nb(nbk1)
n.comp.nb(snbk1)$nc
plot(snbk1, cbind(columbus$X, columbus$Y))
moran.test(columbus$CRIME, nb2listw(snbk1))
sp.correlogram(snbk1, columbus$CRIME, order=6, method="I",
zero.policy=TRUE)
sp.correlogram(snbk1, columbus$CRIME, order=7, method="I",
zero.policy=TRUE)
Try reducing order= to something realistic, but also consider a denser,
more connected, representation of neighbours.
Hope this helps,
Roger
> In addition: Warning message:
> In moran.test(var, listw, randomisation = randomisation, zero.policy = zero.policy) :
> Out-of-range p-value: reconsider test arguments
>
>
> Moran.test seems to work fine, but the sp.correlogram doesn?t? Do I ? in any way- have to attach the weigths (rnp_w) to the neighourhood list (rnp_nb)?
>
> Many thanks!!
>
> Diederik
>
> PS: R-version 2.9.2, Package spdep version 0.4-56, Windows Vista Home Premium Service Pack 2 on Acer Extensa 5630
>
> Dr. Diederik Strubbe
> Evolutionary Ecology Group
> Department of Biology
> University of Antwerp
> Groenenborgerlaan 171
> 2020 Antwerpen, Belgium
> tel: +32 3 265 3464
>
>
> [[alternative HTML version deleted]]
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list