## creating random variables first
## here, a grid is chosen, but any arbitrary points for which
## data are given are fine. Indeed if the data are given on a
## grid, the grid has to be expanded before calling `CondSimu',
## see below.
## However, locations where values are to be simulated,
## should be given in form of a grid definition whenever
## possible
param <- c(0, 1, 0, 1)
model <- "exponential"
RFparameters(PracticalRange=FALSE)
p <- 1:7
data <- GaussRF(x=p, y=p, grid=TRUE, model=model, param=param)
for (i in 1:3) do.call(getOption("device"), list(height=4,width=4))
# another grid, where values are to be simulated
step <- 0.25 # or 0.3
x <- seq(0, 7, step)
# standardisation of the output
lim <- range( c(x, p) )
zlim <- c(-2.6, 2.6)
colour <- rainbow(100)
## visualise generated spatial data
dev.set(2)
image(p, p, data, xlim=lim, ylim=lim, zlim=zlim, col=colour)
#conditional simulation
krige.method <- "O" ## random field assumption corresponding to
## those of ordinary kriging
cz <- CondSimu(krige.method, x, x, grid=TRUE,
model=model, param=param,
given=expand.grid(p,p),# if data are given on a grid
# then expand the grid first
data=data)
range(cz)
dev.set(3)
image(x, x, cz, col=colour, xlim=lim, ylim=lim, zlim=zlim)
#conditional simulation with error term
cze <- CondSimu(krige.method, x, x, grid=TRUE,
model=model, param=c(0, 1/2, 0, 1),
err.model="gauss", err.param=c(0, 1/2, 0, 1),
given=expand.grid(p,p),
data=data)
range(cze)
dev.set(4)
image(x, x, cze, col=colour, xlim=lim, ylim=lim, zlim=zlim)
Run the code above in your browser using DataLab