## This example takes couple of minutes and will therefore not be run
## unless you type: example(Isosim, run.dontrun=TRUE)
## Not run:
# ## We load an elevation raster
# data(elevationrastersmall)
# data(worldcountries)
# data(oceanmask)
# data(isoscapepalette)
#
# elevationraster <- RElevate(elevationrastersmall,
# manual.crop=c(-30, 60, 30, 70))
#
# ## We simulate data under default settings
# simu <- Isosim(simu.data=elevationraster,
# save.dataframe=TRUE, seed=2)
#
# simu
#
# ## We build the plots of the outcome using IsoriX
# plot.mean.simu <- plot(
# x=simu,
# which="mean",
# borders=list(borders=worldcountries),
# mask=list(mask=oceanmask),
# palette=isoscapepalette)
#
# plot.disp.simu <- plot(
# x=simu,
# which="disp",
# borders=list(borders=worldcountries),
# mask=list(mask=oceanmask),
# palette=isoscapepalette)
#
#
# ## We fit the simulated data by sampling 200 locations
#
# set.seed(123)
# newdat <- simu$data[sample(1:nrow(simu$data), 200), ]
#
# isoscapemodel <- Isofit(iso.data=newdat,
# mean.model.fix=list(elev=TRUE, lat.abs=TRUE))
#
# isoscape <- Isoscape(elevationraster, isoscapemodel)
#
# plot.mean.fitted <- plot(
# x=isoscape,
# which="mean",
# sources=list(draw=FALSE),
# borders=list(borders=worldcountries),
# mask=list(mask=oceanmask),
# palette=isoscapepalette)
#
# plot.disp.fitted <- plot(
# x=isoscape,
# which="disp",
# sources=list(draw=FALSE),
# borders=list(borders=worldcountries),
# mask=list(mask=oceanmask),
# palette=isoscapepalette)
#
# ## We compare simulated and fitted data visually
# if(require(lattice)){
# print(plot.mean.simu, split=c(1, 1, 2, 2), more=TRUE)
# print(plot.disp.simu, split=c(2, 1, 2, 2), more=TRUE)
# print(plot.mean.fitted, split=c(1, 2, 2, 2), more=TRUE)
# print(plot.disp.fitted, split=c(2, 2, 2, 2), more=FALSE)
# }
#
# ## We compare simulated and fitted data numerically
# ## Note that differences are expected, as the geographic
# ## area is small compared to the scale at which
# ## spatial auto-correlation occurs
# round(cbind(
# simulated=c(
# intercept=64,
# lat.abs=-2.3,
# elev=-0.01,
# nu=0.35,
# rho=5e-5,
# rho_div_nu = 5e-5/0.35,
# lambda.matern=899,
# intercept.disp=5.8,
# nu.disp=3.2e-01,
# rho.disp=1.5e-05,
# lambda.matern.disp=5),
# fitted=c(
# intercept=isoscapemodel$mean.fit$fixef[1],
# lat.abs=isoscapemodel$mean.fit$fixef[2],
# elev=isoscapemodel$mean.fit$fixef[3],
# nu=isoscapemodel$mean.fit$ranFix$nu,
# rho=isoscapemodel$mean.fit$ranFix$rho,
# rho_div_nu=with(isoscapemodel$mean.fit$ranFix,rho/nu),
# lambda.matern=isoscapemodel$mean.fit$lambda,
# intercept.disp=isoscapemodel$disp.fit$fixef[1],
# nu.disp=isoscapemodel$disp.fit$ranFix$nu,
# rho.disp=isoscapemodel$disp.fit$ranFix$rho,
# lambda.matern.disp=isoscapemodel$disp.fit$lambda)), 4)
#
# ## End(Not run)
Run the code above in your browser using DataLab