# generating a simulated data-set
ex.data <- grf(50, cov.pars=c(10, .25))
#
# defining the prediction grid:
ex.grid <- as.matrix(expand.grid(seq(0,1,l=11), seq(0,1,l=11)))
#
# computing Bayesian posterior and predictive distributions
# (this can take some time to run)
ex.bayes <- krige.bayes(ex.data, loc=ex.grid, prior =
prior.control(range.discrete=seq(0, 2, l=51)))
#
# Ploting theoretical amd empirical variograms
plot(ex.data)
# adding lines with fitted variograms
lines(ex.bayes)
lines(ex.bayes, summ="median", lty=2)
lines(ex.bayes, summ="mean", lwd=2, lty=2)
#
# Ploting prediction some results
op <- par(no.readonly = TRUE)
par(mfrow=c(2,2))
par(mar=c(3,3,1,1))
par(mgp = c(2,1,0))
image.krige.bayes(ex.bayes, loc=ex.grid, main="predicted values")
image.krige.bayes(ex.bayes, val="moments.variance",
loc=ex.grid, main="prediction variance")
image.krige.bayes(ex.bayes, val= "simulation", number.col=1,
loc=ex.grid,
main="a simulation from the \npredictive distribution")
image.krige.bayes(ex.bayes, val= "simulation", number.col=2,
loc=ex.grid,
main="another simulation from \nthe predictive distribution")
par(op)
<testonly>ex.data <- grf(50, cov.pars=c(10, .25))
ex.grid <- as.matrix(expand.grid(seq(0,1,l=11), seq(0,1,l=11)))
ex.bayes <- krige.bayes(ex.data, loc=ex.grid, prior =
prior.control(range.discrete=seq(0, 2, l=3),
nugget.rel.prior = "uniform",
nugget.rel.discrete=seq(0,.5, l=2)),
output=output.control(n.post=100))
plot(ex.data)
lines(ex.bayes)
lines(ex.bayes, summ="median", lty=2)
lines(ex.bayes, summ="mean", lwd=2, lty=2)
op <- par(no.readonly = TRUE)
par(mfrow=c(2,2))
par(mar=c(3,3,1,1))
par(mgp = c(2,1,0))
image.krige.bayes(ex.bayes, loc=ex.grid, main="predicted values")
image.krige.bayes(ex.bayes, val="moments.variance",
loc=ex.grid, main="prediction variance")
image.krige.bayes(ex.bayes, val= "simulation", number.col=1,
loc=ex.grid,
main="a simulation from the \npredictivedistribution")
image.krige.bayes(ex.bayes, val= "simulation", number.col=2,
loc=ex.grid,
main="another simulation from \nthepredictive distribution")
par(op)</testonly>Run the code above in your browser using DataLab