[R-sig-Geo] I need a raster with negative spatial autocorrelation
Babak Naimi
naimi.b at gmail.com
Fri Aug 5 06:38:45 CEST 2016
Dear list,
I need a dataset (preferably a raster) that has a negative spatial
autocorrelation. I just used an arbitrary procedure to simulate a simple
one, but I think it is not realistic at all. The procedure I used:
I generated two separate rasters using unconditional simulation given two
different variogram models with different mean, and variance. I then
combined the values from different parts of these two rasters into a single
new raster in a way that each cell is surrounded by dissimilar values. I am
wondering if anyone is aware of a more formal procedure or simply can
introduce a dataset.
Following is the code I used. Thanks for your help.
Best regards,
Babak
(web: r-gis.net)
# a function to generate an unconditional simulation as a raster using grf
function in package geoR:
library(geoR)
genrf <-
function(side,model='exponential',sill=10,phi,nugget=0,mean=50,nsim=1,method='cholesky')
{
sim0<-grf(side*side,grid='reg',xlims=c(0.5,side-0.5),ylims=c(0.5,side-0.5),cov.pars=c(sill,phi),cov.model=model,mean=mean,nugget=nugget,nsim=nsim,method=method)
if (nsim == 1) {
r<-as.data.frame(cbind(sim0$coords,sim0$data))
coordinates(r)<-~x+y
gridded(r) <- TRUE
r <- as(r, "SpatialGridDataFrame")
names(r at data)<-c('sim1')
r <- raster(r)
} else {
r <- as.data.frame(cbind(sim0$coords,sim0$data[,1]))
coordinates(r)<-~x+y
gridded(r) <- TRUE
r <- as(r, "SpatialGridDataFrame")
names(r at data)<-c('sim1')
r <- stack(raster(r))
for (i in 2:nsim) {
rr <- as.data.frame(cbind(sim0$coords,sim0$data[,i]))
coordinates(rr)<-~x+y
gridded(rr) <- TRUE
rr <- as(rr, "SpatialGridDataFrame")
names(rr at data)<-c(paste('sim',i,sep=''))
rr <- raster(rr)
r <- addLayer(r,rr)
}
}
r
}
#------------
###########
# --- the procedure to generate the surface with negative spatial
autocorrelation:
f1 <- genrf(20,phi=20, model='exponential',nugget=0,nsim=1,sill=20,mean =
100)
f2 <- genrf(20,phi=20, model='spherical',nugget=0,nsim=1,sill=30,mean = 200)
f <- raster(f1) # an empty raster to have the output
# loops to take values from different parts of the two simulated rasters
put together just to make sure each cell is serronded by dissimilar values
for (i in seq(19,1,-2)) f[i,] <- f1[,i]
for (i in seq(2,20,2)) f[i-1,] <- f2[i,]
for (i in seq(19,1,-2)) f[,i] <- f2[i+1,]
for (i in seq(2,20,2)) f[,i-1] <- f1[,i]
plot(f)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160805/b779bc98/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pasted1
Type: image/png
Size: 6914 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160805/b779bc98/attachment.png>
More information about the R-sig-Geo
mailing list