# NOT RUN {
if(require("sp", quietly=TRUE) & require("gstat", quietly=TRUE)) {
# Examples from gstat complemented with global envelopes
#-------------------------------------------------------
data(meuse)
coordinates(meuse) <- ~x+y
# topsoil zinc concentration, mg kg-1 soil ("ppm")
bubble(meuse, "zinc",
col=c("#00ff0088", "#00ff0088"), main="zinc concentrations (ppm)")
# Variogram can be calculated as follows by the function variogram of the gstat library.
# The function variogram takes a formula as its first argument:
# log(zinc)~1 means that we assume a constant trend for the variable log(zinc).
lzn.vgm <- variogram(object=log(zinc)~1, data=meuse)
plot(lzn.vgm)
# Variogram with global envelopes is as easy:
# }
# NOT RUN {
lzn.vgm.GET <- GET.variogram(object=log(zinc)~1, data=meuse)
# }
# NOT RUN {
# }
# NOT RUN {
plot(lzn.vgm.GET)
# Instead of the constant mean, denoted by ~1, a mean function can
# be specified, e.g. using ~sqrt(dist) as a predictor variable:
lznr.vgm <- variogram(log(zinc)~sqrt(dist), meuse)
# In this case, the variogram of residuals with respect
# to a fitted mean function are shown.
plot(lznr.vgm)
# The variogram with global envelopes (obtained by permuting the residuals):
# }
# NOT RUN {
lznr.vgm.GET <- GET.variogram(object=log(zinc)~sqrt(dist), data=meuse)
# }
# NOT RUN {
# }
# NOT RUN {
plot(lznr.vgm.GET)
# Directional variograms
lzn.dir <- variogram(object=log(zinc)~1, data=meuse, alpha=c(0, 45, 90, 135))
plot(lzn.dir)
# with global envelopes
# }
# NOT RUN {
lzn.dir.GET <- GET.variogram(object=log(zinc)~1, data=meuse, alpha=c(0, 45, 90, 135))
# }
# NOT RUN {
# }
# NOT RUN {
plot(lzn.dir.GET, base_size=10)
# Use instead gstat objects
g <- gstat(id="ln.zinc", formula=log(zinc)~1, data=meuse)
# or: g <- gstat(id="ln.zinc", formula=log(zinc)~sqrt(dist), data=meuse)
# The variogram
plot(variogram(g))
# The variogram with global envelopes:
# }
# NOT RUN {
g.GET <- GET.variogram(object=g)
# }
# NOT RUN {
# }
# NOT RUN {
plot(g.GET)
}
# }
Run the code above in your browser using DataLab