# load data
data(meuse,meuse.blocks)
# approximation of block variance
# pixel area = 75m x 75m
# exponential covariance function with measurement error = 0, nugget = 0.05,
# part. sill = 0.15 and range parameter = 192.5
preCK <- preCKrige(newdata = meuse.blocks,
model = covmodel("exponential", 0, 0.05, 0.15, scale = 192.5),
pwidth = 75, pheight = 75)
# block prediction by constrained kriging
ck <- CKrige(formula = log(zinc) ~ sqrt(dist),
data = meuse, locations = ~ x + y, object = preCK, ex.out = TRUE)
# backtransformation to the original scale for the CK prediction
beta <- ck$parameter$beta.coef
c1 <- 0.2
c2 <- beta[2]^2 * meuse.blocks@data$M
c3 <- unlist( preCK@covmat )
ck$object@data$Zn <- exp(ck$object@data$prediction + 0.5*(c1 + c2 - c3))
# factor: the factor multiplied with the corresponding block mean
# prediction gives the upper bound of the 97.5% confidence interval
# of the prediction
ck$object@data$factor <- exp(ck$object@data$prediction
+ 1.96*ck$object@data$prediction.se)/ck$object@data$Zn
# plots with spplot, generic function in the sp package
# plot of the constrained block kriging prediction
# function ck.colors(n) create a vector of n colors
ticks <- seq(0, 1850, by = 185)
spplot(ck$object, zcol ="Zn" , col.regions = ck.colors(10), at = ticks,
colorkey= list(labels = list(at = ticks, labels = ticks)))
# plot of the factor to get the upper bound of the 97.5% confidence interval
spplot(ck$object, zcol = "factor", col.regions = ck.colors(10), at = seq(1,3, by = 0.2))
Run the code above in your browser using DataLab