Skip to content
Prev 12703 / 29559 Next

Simulating spatially autocorrelated data

Hi Roger and Terry,

Thank you very much for your help and directing me towards Roger's spdep
package, which of course had everything I needed. I've now worked through
this code and done some additional simulations.

I have one remaining question. You say "the larger the distance threshold,
the less well the spatial process is captured." I was wondering if you
could further provide some information on this, either by explaining or
referencing a document or webpage with explanation.

Decreasing the distance threshold, as you suggest, radically alters the
results and I'm looking for some guidance on how to select the appropriate
distance threshold when I don't know the true rho (that is, with
non-simulated data).

Thanks,
Mitch 


-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Thursday, September 01, 2011 2:20 PM
To: Downey, Patrick
Cc: r-sig-geo at stat.math.ethz.ch
Subject: Re: [R-sig-Geo] Simulating spatially autocorrelated data
On Thu, 1 Sep 2011, Downey, Patrick wrote:

            
how to fix it?
distance
I think that you are using the distances as weights, not inverse distances,
which seems more sensible.
As Terry Griffin says, you can use spdep for this:

library(spdep)
rho <- 0.95
N <- 200
x.coord <- runif(N,0,100)
y.coord <- runif(N,0,100)
points <- cbind(x.coord,y.coord)
e <- rnorm(N,0,1)
dnb <- dnearneigh(points, 0, 150)
dsts <- nbdists(dnb, points)
idw <- lapply(dsts, function(x) 1/x)
lw <- nb2listw(dnb, glist=idw, style="W") inv <- invIrW(lw, rho) y <- inv
%*% e moran.test(y, lw)

to reproduce your analysis with IDW, here without:

lw <- nb2listw(dnb, glist=dsts, style="W") inv <- invIrW(lw, rho) y <- inv
%*% e moran.test(y, lw) # no autocorrelation

and here with a less inclusive distance threshold:

dnb <- dnearneigh(points, 0, 15)
dsts <- nbdists(dnb, points)
idw <- lapply(dsts, function(x) 1/x)
lw <- nb2listw(dnb, glist=idw, style="W") inv <- invIrW(lw, rho) y <- inv
%*% e moran.test(y, lw)


the larger the distance threshold, the less well the spatial process is
captured, alternatively use idw <- lapply(dsts, function(x) 1/(x^2)), for
example, to attenuate the weights more sharply.

Hope this clarifies,

Roger
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics, 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