predict calculates the predicted values at specified locations. The method can additionally provide the mean square prediction error (mspe) and perform conditional simulation.
## S3 method for class 'geolm_cmodStd'predict( object, newdata, nsim =0, return_type ="SpatialPointsDataFrame", dmethod ="chol", compute_mspe =TRUE, sp =NULL,...)
Arguments
object: An object produced by the geolm
function.
newdata: An optional data frame in which to look for the coordinates at which to predict. If omitted, the observed data locations are used.
nsim: A non-negative integer indicating the number of realizations to sample at the specified coordinates using conditional simulation.
return_type: A character string indicating the type of object that should be returned. The default is "SpatialPointsDataFrame" for easy plotting of results (see Examples). Other options include "data.frame", "geardf", and "sf".
dmethod: The method used to decompose the covariance matrix for conditional simulation. Valid options are "chol", "eigen", and "svd". The default is "chol".
compute_mspe: A logical value indicating whether the mean square prediction error should be calculated. Default is TRUE.
sp: This argument will be deprecated in the future. Please use the return_type argument. A logical value indicating whether to object returned should be of class SpatialPointsDataFrame for easier plotting with the sp package. Default is NULL.
...: Currently unimplemented.
Returns
A data.frame, SpatialPointsDataFrame, geardf, or sf
object with the kriging predictions pred, kriging variance/mean-square prediction error (mspe), the root mean-square prediction error mspe (rmspe), and the conditional simulations sim.1, sim.2, etc. sim.1, sim.2, etc.
Details
The newdata data frame must include the relevant covariates for the prediction locations, where the covariates are specified on the right side of the ~ in object$formula. newdata must also include the coordinates of the prediction locations, with these columns having the names provided in object$coordnames.
Examples
# generate responsey = rnorm(10)# generate coordinatesx1 = runif(10); x2 = runif(10)# data frame for observed datadata = data.frame(y, x1, x2)# newdata must have columns with prediction coordinatesnewdata = data.frame(x1 = runif(5), x2 = runif(5))# specify a standard covariance modelmod = cmod_std(model ="exponential", psill =1, r =1)# geolm for universal kriginggearmod_uk = geolm(y ~ x1 + x2, data = data, mod = mod, coordnames = c("x1","x2"))# prediction for universal kriging, with conditional simulationpred_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 installedif(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 installedif(requireNamespace("sf", quietly =TRUE)){ pred_sfdf = predict(gearmod_uk, newdata, return_type ="sf") plot(pred_sfdf["pred"]) plot(pred_sfdf)}# geolm for ordinary kriginggearmod_ok = geolm(y ~1, data = data, mod = mod, coordnames = c("x1","x2"))# prediction for ordinary krigingpred_ok = predict(gearmod_ok, newdata)# geolm for simple kriginggearmod_sk = geolm(y ~1, data = data, mod = mod, coordnames = c("x1","x2"), mu =1)# prediction for simple krigingpred_sk = predict(gearmod_sk, newdata)