# NOT RUN {
## 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(elevraster)
data(countries)
data(oceanmask)
data(isopalette1)
elevationraster <- relevate(elevraster,
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=countries),
mask=list(mask=oceanmask),
palette=isopalette1)
plot.disp.simu <- plot(
x=simu,
which="disp",
borders=list(borders=countries),
mask=list(mask=oceanmask),
palette=isopalette1)
## 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=countries),
mask=list(mask=oceanmask),
palette=isopalette1)
plot.disp.fitted <- plot(
x=isoscape,
which="disp",
sources=list(draw=FALSE),
borders=list(borders=countries),
mask=list(mask=oceanmask),
palette=isopalette1)
## 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)
# }
Run the code above in your browser using DataLab