Learn R Programming

gstat (version 0.9-22)

krige.cv: (co)kriging cross validation, n-fold or leave-one-out

Description

Cross validation functions for simple, ordinary or universal point (co)kriging, kriging in a local neighbourhood.

Usage

gstat.cv(object, nfold, remove.all = FALSE, verbose = FALSE, 
	all.residuals = FALSE, ...)
krige.cv(formula, locations, data, model = NULL, ..., beta = NULL, nmax = Inf, 
	nmin = 0, maxdist = Inf, nfold = nrow(data), verbose = FALSE)

Arguments

object
object of class gstat; see function gstat
nfold
apply n-fold cross validation; if nfold is set to nrow(data) (the default), leave-one-out cross validation is done; if set to e.g. 5, five-fold cross validation is done
remove.all
logical; if TRUE, remove observations at cross validation locations not only for the first, but for all subsequent variables as well
verbose
logical; if TRUE, progress is printed
all.residuals
logical; if TRUE, residuals for all variables are returned instead of for the first variable only
...
other arguments that will be passed to predict.gstat in case of gstat.cv, or to gstat in case of krige.cv
formula
formula that defines the dependent variable as a linear model of independent variables; suppose the dependent variable has name z, for ordinary and simple kriging use the formula z~1; for simple kriging also define be
locations
formula with only independent variables that define the spatial data locations (coordinates), e.g. ~x+y; if data is of class spatial.data.frame, this argument may be ignored, as it can be derived from the data
data
data frame; should contain the dependent variable, independent variables, and coordinates.
model
variogram model of dependent variable (or its residuals), defined by a call to vgm or fit.variogram
beta
only for simple kriging (and simulation based on simple kriging); vector with the trend coefficients (including intercept); if no independent variables are defined the model only contains an intercept and this should be the simple kriging mean
nmax
for local kriging: the number of nearest observations that should be used for a kriging prediction or simulation, where nearest is defined in terms of the space of the spatial locations. By default, all observations are used
nmin
for local kriging: if the number of nearest observations within distance maxdist is less than nmin, a missing value will be generated; see maxdist
maxdist
for local kriging: only observations within a distance of maxdist from the prediction location are used for prediction or simulation; if combined with nmax, both criteria apply

Value

  • data frame containing the coordinates of data or those of the first variable in object, and columns of prediction and prediction variance of cross validated data points, observed values, residuals, zscore (residual divided by kriging standard error), and fold.

    If all.residuals is true, a data frame with residuals for all variables is returned, without coordinates.

Details

Leave-one-out cross validation (LOOCV) visits a data point, and predicts the value at that location by leaving out the observed value, and proceeds with the next data point. (The observed value is left out because kriging would otherwise predict the value itself.) N-fold cross validation makes a partitions the data set in N parts. For all observation in a part, predictions are made based on the remaining N-1 parts; this is repeated for each of the N parts. N-fold cross validation may be faster than LOOCV.

References

http://www.gstat.org/

See Also

krige, gstat, predict.gstat

Examples

Run this code
data(meuse)
m <- vgm(.59, "Sph", 874, .04)
# five-fold cross validation:
x <- krige.cv(log(zinc)~1, ~x+y, model = m, data = meuse, nmax = 40, nfold=5)
bubble(x, z = "residual", main = "log(zinc): 5-fold CV residuals")

Run the code above in your browser using DataLab