https://github.com/cran/gstat
Tip revision: f84769b7472a4a4d1541b46221890e60f430edd5 authored by Edzer J. Pebesma on 11 March 2008, 11:57:00 UTC
version 0.9-44
version 0.9-44
Tip revision: f84769b
uisim.R
# $Id: uisim.R,v 1.3 2006-02-10 19:05:02 edzer Exp $
library(gstat)
# prediction grid:
data(meuse.grid)
gridded(meuse.grid) = ~x+y
# define variable as dummy data
v = vgm(.25, "Sph", 900)
g = gstat(NULL, "var1", x~1, beta = .5, nmax = 20, model = v, dummy = TRUE)
# simulation of a single variable
out = predict(g, meuse.grid, nsim = 20, indicators = TRUE)
spplot(out)
# simulation of two correlated variables:
v = vgm(.1, "Sph", 900)
g = gstat(g, "var2", x~1, beta = .25, nmax = 20, model = v, dummy = TRUE)
v = vgm(-.1, "Sph", 900)
g = gstat(g, c("var1", "var2"), model = v)
out = predict(g, meuse.grid, nsim = 10, indicators = TRUE, set = list(order = 2))
spplot(out)
# merge all 10 individual simulations into three-group factors:
for (i in 1:10) {
v1 = paste("var1.sim", i, sep = "")
v2 = paste("var2.sim", i, sep = "")
m = cbind(out[[v1]], out[[v2]], 1 - (out[[v1]]+out[[v2]]))
mout = factor(apply(m, 1, function(x) which(x == 1)))
if (i == 1)
out2 = SpatialPixelsDataFrame(out, data.frame(mout))
else
out2[[i]] = mout
}
names(out2) = paste("sim", 1:10, sep="")
spplot(out2)