# NOT RUN {
# generate response
y = rnorm(10)
# generate coordinates
x1 = runif(10); x2 = runif(10)
# data frame for observed data
data = data.frame(y, x1, x2)
# newdata must have columns with prediction coordinates
newdata = data.frame(x1 = runif(5), x2 = runif(5))
# specify a standard covariance model
mod = cmod_std(model = "exponential", psill = 1, r = 1)
# geolm for universal kriging
gearmod_uk = geolm(y ~ x1 + x2, data = data, mod = mod,
coordnames = c("x1", "x2"))
# prediction for universal kriging, with conditional simulation
pred_uk = predict(gearmod_uk, newdata, nsim = 2)
# demonstrate plotting abilities if return_type == "geardf"
pred_geardf = predict(gearmod_uk, newdata,
return_type = "geardf")
plot(pred_geardf, "pred")
plot(pred_geardf, interp = TRUE)
# demonstrate plotting abilities if sp package installed
if (requireNamespace("sp", quietly = TRUE)) {
pred_spdf = predict(gearmod_uk, newdata,
return_type = "SpatialPointsDataFrame")
sp::spplot(pred_spdf, "pred")
sp::spplot(pred_spdf)
}
# demonstrate plotting abilities if sf package installed
if (requireNamespace("sf", quietly = TRUE)) {
pred_sfdf = predict(gearmod_uk, newdata,
return_type = "sf")
plot(pred_sfdf["pred"])
plot(pred_sfdf)
}
# geolm for ordinary kriging
gearmod_ok = geolm(y ~ 1, data = data, mod = mod,
coordnames = c("x1", "x2"))
# prediction for ordinary kriging
pred_ok = predict(gearmod_ok, newdata)
# geolm for simple kriging
gearmod_sk = geolm(y ~ 1, data = data, mod = mod,
coordnames = c("x1", "x2"), mu = 1)
# prediction for simple kriging
pred_sk = predict(gearmod_sk, newdata)
# }
Run the code above in your browser using DataLab