[R-sig-Geo] Simulating spatially autocorrelated data

Terry Griffin tgriffin at uaex.edu
Thu Sep 1 20:07:40 CEST 2011


Patrick,

Good questions, the package spdep has the functions you are looking for, specifically invIrM or invIrW. I suspect you'll figure it out from there but if not, please respond back.

Terry

Terry Griffin, Ph.D. 
Associate Professor - Economics 
University of Arkansas - Division of Agriculture 
501.249.6360 (SMS)
tgriffin at uaex.edu 




----- Original Message -----
From: "Patrick Downey" <PDowney at urban.org>
To: r-sig-geo at stat.math.ethz.ch
Sent: Thursday, September 1, 2011 12:58:31 PM
Subject: [R-sig-Geo] Simulating spatially autocorrelated data

Hello all,

I'm trying to simulate a spatially autocorrelated random variable, and I
cannot figure out what the problem is. All I want is a simple spatial lag
model where

Y = rho*W*Y + e

Where e is a vector of iid normal random variables, rho is the
autocorrelation, W is a row-normalized distance matrix (a spatial weights
matrix), and Y is the random variable.

I thought the following program should do it, but it's not working. At the
end of the program, I calculate Moran's I, and it is not even close to
rejecting the null hypothesis of no spatial autocorrelation, even when rho
is very high (for example, below, rho is 0.95). Can someone please identify
what the problem is and offer some guidance on how to fix it?

PS - I apologize in advance, but I am not familiar with R's spatial
packages. I've done very little spatial analysis in R, so if there's a
package that can already do this, please recommend.

BEGIN PROGRAM:

install.packages("fields");library(fields)
install.packages("ape");library(ape)

N <- 200
rho <- 0.95

x.coord <- runif(N,0,100)
y.coord <- runif(N,0,100)

points <- cbind(x.coord,y.coord)

e <- rnorm(N,0,1)

dist.nonnorm <- rdist(points,points)   # Matrix of Euclidean distances
dist <- dist.nonnorm/rowSums(dist.nonnorm)   # Row normalizing the distance
matrix
diag(dist) <- 0   # Ensuring that the main diagonal is exactly 0

I <- diag(N)   # Identity matrix (not Moran's I)

inv <- solve(I-rho.lag*dist)   # Inverting (I - rho*W)
y <- as.vector(inv %*% e)   # Generating data that is supposed to be
spatially autocorrelated

Moran.I(y,dist)   # Does not reject null hypothesis of no spatial
autocorrelation

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list