Learn R Programming

GeoModels (version 2.2.6)

GeoCV: n-fold kriging Cross-validation

Description

The procedure uses the GeoKrig or GeoKrigloc function to compute n-fold kriging cross-validation using information from a GeoFit object. The function returns prediction scores.

Usage

GeoCV(
  fit, K = 100, estimation = TRUE,
  optimizer = NULL, lower = NULL, upper = NULL,
  n.fold = 0.05, local = FALSE,
  neighb = NULL, maxdist = NULL, maxtime = NULL,
  sparse = FALSE, type_krig = "Simple", which = 1,
  parallel = TRUE, ncores = NULL, progress = TRUE,
  seed = NULL
)

Value

Returns a list containing the following components:

rmse

The vector of root mean squared errors.

mae

The vector of mean absolute errors.

mad

The vector of median absolute errors.

brie

The vector of Brier scores.

crps

The vector of continuous ranked probability scores.

lscore

The vector of log-scores.

pit

The vector of average probability integral transform values.

intscore

The vector of interval scores.

coverage

The vector of empirical coverage values.

seed

The seed used for reproducibility, or NULL.

Arguments

fit

An object of class GeoFit.

K

The number of iterations in cross-validation.

estimation

Logical; if TRUE, an estimation is performed at each iteration and the estimates are used in the prediction. Otherwise, the estimates in the object fit are used.

optimizer

The type of optimization algorithm if estimation is TRUE. See GeoFit for details. If NULL, then the optimization algorithm stored in fit is used.

lower

An optional named list giving the values for the lower bounds of the parameters when bounded optimization is used and estimation is TRUE.

upper

An optional named list giving the values for the upper bounds of the parameters when bounded optimization is used and estimation is TRUE.

n.fold

Numeric; the percentage of data to be deleted and predicted in each cross-validation iteration.

local

Logical; if TRUE, local kriging is performed. The default is FALSE.

neighb

Numeric; an optional positive integer indicating the order of neighborhood if local kriging is performed.

maxdist

Numeric; an optional positive value indicating the spatial neighborhood distance if local kriging is performed.

maxtime

Numeric; an optional positive value indicating the temporal neighborhood distance if local kriging is performed.

sparse

Logical; if TRUE, kriging and simulation are computed with sparse matrix algorithms using the spam package. The default is FALSE. It should be used with compactly supported covariance models.

type_krig

String; the type of kriging. If "Simple", the default, simple kriging is performed. If "Optim", optimal kriging is performed for some non-Gaussian random fields.

which

Numeric; in the case of bivariate cokriging, it indicates which variable to predict. It can be 1 or 2.

parallel

Logical; if TRUE, the cross-validation iterations are parallelized.

ncores

Numeric; number of cores involved in parallelization.

progress

Logical; if TRUE, a progress bar is shown.

seed

Optional integer seed used to make the random selection of folds and any stochastic refitting step reproducible. If NULL, the current random number generator state is left unchanged. When supplied, the previous .Random.seed is restored on exit.

Details

The function randomly removes a fraction n.fold of the observations at each iteration, predicts the removed observations using kriging, and computes a set of predictive scores.

If estimation = TRUE, the model is re-estimated at each cross-validation iteration before prediction. Otherwise, the parameter estimates contained in fit are used.

When seed is supplied, the cross-validation folds are reproducible. The function preserves and restores the user's random number generator state.

See Also

GeoKrig, GeoKrigloc, GeoFit.

Examples

Run this code
# \donttest{
library(GeoModels)

###############################################################
### Example of spatial kriging cross-validation
###############################################################

model <- "Gaussian"
set.seed(79)
x <- runif(400, 0, 1)
y <- runif(400, 0, 1)
coords <- cbind(x, y)

corrmodel <- "GenWend"
mean <- 0
sill <- 5
nugget <- 0
scale <- 0.2
smooth <- 0
power2 <- 4

param <- list(
  mean = mean, sill = sill, nugget = nugget,
  scale = scale, smooth = smooth, power2 = power2
)

data <- GeoSim(coordx = coords, corrmodel = corrmodel,
               param = param)$data

fixed <- list(nugget = nugget, smooth = 0, power2 = power2)
start <- list(mean = 0, scale = scale, sill = 1)
I <- Inf
lower <- list(mean = -I, scale = 0, sill = 0)
upper <- list(mean = I, scale = I, sill = I)

fit <- GeoFit(
  data, coordx = coords, corrmodel = corrmodel,
  model = model, likelihood = "Marginal", type = "Pairwise",
  neighb = 3, optimizer = "nlminb", lower = lower,
  upper = upper, start = start, fixed = fixed
)

#a <- GeoCV(fit, K = 100, estimation = TRUE,
#           parallel = TRUE, seed = 123)
#mean(a$rmse)
# }

Run the code above in your browser using DataLab