I'm trying to figure out how one might go about simulating a landscape (matrix) in R. For example if one wanted to generate a simulated landscape of precipitation values for some area (say a 100 X 100 matrix) they could generate 10,000 numbers using a random normal distribution with a mean and std. dev. and randomly allocate these generated numbers to the grid cells. However, this is too simplistic and the resulting matrix will be very noisy since one cell could have a very high value and an adjacent cell could have a very low value. Is it possible to generate a simulated matrix that would somehow incorporate a measure of spatial autocorrelation, so that grid cells closer to each other are similar? Is this sort of thing possible in R to get a realistic surface or are other software packages (e.g., surface visualizations/rendering) more appropriate for this sort of thing? [[alternative HTML version deleted]]
You could try something like this. Simulating with a large number of grid cells is however very RAM expensive. library(MASS) library(spatial) x <- expand.grid(1:30, 1:30) distances <- as.matrix(dist(x, diag=T, upper=T)) Sigma <- expcov(r=distances, d=10, se=1) z <- mvrnorm(n = 1, mu=rep(0,900), Sigma) z <- matrix(z,nrow=30) image(z) ----- Original Message ----- From: "Brian Davenhall" <bdavenhall at sbcglobal.net> To: <r-help at stat.math.ethz.ch> Sent: Thursday, June 03, 2004 10:46 PM Subject: [R] Simulating a landscape (matrix) in R> I'm trying to figure out how one might go about simulating a landscape > (matrix) in R. For example if one wanted to generate a simulated landscape > of precipitation values for some area (say a 100 X 100 matrix) they could > generate 10,000 numbers using a random normal distribution with a mean and > std. dev. and randomly allocate these generated numbers to the grid cells. > However, this is too simplistic and the resulting matrix will be very noisy > since one cell could have a very high value and an adjacent cell could have > a very low value. Is it possible to generate a simulated matrix that would > somehow incorporate a measure of spatial autocorrelation, so that grid cells > closer to each other are similar? > > > > Is this sort of thing possible in R to get a realistic surface or are other > software packages (e.g., surface visualizations/rendering) more appropriate > for this sort of thing? > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
For creating larger "landscapes" (Gaussian random fields), you may consider using package gstat, which uses the sequential Gaussian simulation algorithm with local approximations. In the example below, only the nearest 20 neighbours are used to approximate each of the conditional distributions. The example below which simulates & plots a 300x300 grid, took 1 minute on a 2 GHz CPU. Best regards, -- Edzer library(gstat) g = gstat(NULL, "id0", z~1, ~x+y, dummy=TRUE,nmax=20, model=vgm(1,"Exp",500),beta=10) locs=expand.grid(x=1:300,y=1:300) out <- predict.gstat(g, locs, nsim=1) levelplot(sim1~x+y,out,col.regions=bpy.colors())