model <- c(var=5, range=1,shape=0.5)
RandomFields::plot(modelRandomFields(model))
myraster = raster(nrows=20,ncols=30,xmn=0,ymn=0,xmx=6,ymx=4,
crs="+init=epsg:2081")
set.seed(0)
simu <- RFsimulate(model, x=myraster, n=3)
plot(simu[['sim2']])
data("swissRain")
swissRain$sqrtrain = sqrt(swissRain$rain)
# estimate parameters
swissRes = lgm(data=swissRain, newdata=50, formula="sqrtrain",
covariates=swissAltitude,
shape=1, fixShape=TRUE,
aniso=FALSE, nugget=1, fixNugget=TRUE,
nuggetInPrediction=FALSE
)
# simulate from the random effect conditional on
# the observed data
swissSim = RFsimulate(model=swissRes$param,
data=swissRes$data[,'resid'],
x=swissRes$predict,
n=3
)
# plot the simulated random effect
plot(swissSim[['sim2']])
plot(swissBorder, add=TRUE)
Run the code above in your browser using DataLab