[R-sig-Geo] Generating geo-statistical data

Malcolm Fairbrother m.fairbrother at bristol.ac.uk
Mon Jun 13 10:48:43 CEST 2011


Dear Luca,

Are you looking for something like this?

N <- 300 # set the number of units
W <- matrix(rbinom(N^2, 1, 0.25), N, N)*upper.tri(matrix(1, N, N)) # build a connectivity matrix, randomly
W <- W + t(W) # make the connectivity matrix symmetrical
W <- W/apply(W, 1, sum) # row-standardise the connectivity matrix (make rows sum to 1)
rho <- 0.2 # set the level of autocorrelation
y <- solve(diag(N) - rho*W) %*% rnorm(N, 1, 1) # generate y data with mean 1, sd 1 (prior to "spatialisation")
library(spdep) # for lagarlm below
lagsarlm(y ~ 1, listw=mat2listw(W)) # check that parameters can be recovered (subject to random simulation error)

Cheers,
Malcolm



> Date: Thu, 09 Jun 2011 12:28:52 +0200
> From: Luca Morandini <luca.morandini1 at gmail.com>
> To: R-sig-geo <r-sig-geo at r-project.org>
> Subject: [R-sig-Geo] Generating geo-statistical data
> Message-ID: <4DF0A064.8070505 at gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Folks,
> 
> I would like to generate, for educational purpose, data with a set level of 
> auto-correlation; that is, I would like to generate Zs that exhibit an higher 
> correlation with points that are closer to their locations.
> 
> One method I've found out in "Statistical methods for spatial data analysis" is 
> the use of convolutions (in the sense of "smoothers"), that is, to generate random 
> Zs and then compute Z2s as Z + (some weight based on neighbouring points).
> 
> Of curse this would work, but, ideally, I would like to set a level of 
> autocorrelation and then have a function generating data with (about) that 
> level... any suggestion ?
> 
> Regards,
> 
> Luca Morandini
> http://www.lucamorandini.it



More information about the R-sig-Geo mailing list