xvalid
Cross-validation by kriging
A function to perform model validation by comparing observed and values predicted by kriging. Options include: (i) leaving-one-out cross-validation where each data location is removed from the data set and the variable at this location is predicted using the remaining locations, for a given model. This can be computed for all or a subset of the data locations; (ii) external validation can be performed by using validation locations other than data locations.
- Keywords
- spatial
Usage
xvalid(geodata, coords = geodata$coords, data = geodata$data,
model, reestimate = FALSE, variog.obj = NULL,
output.reestimate = FALSE, locations.xvalid = "all",
data.xvalid = NULL, messages, …)
Arguments
- geodata
a list containing element
coords
as described next. Typically an object of the class"geodata"
- a geoR data-set. If not provided the argumentscoords
must be provided instead.- coords
an \(n \times 2\) matrix containing coordinates of the \(n\) data locations in each row. Defaults to
geodata$coords
, if provided.- data
a vector or matrix with data values. If a matrix is provided, each column is regarded as one variable or realization. Defaults to
geodata$data
, if provided.- model
an object containing information on a fitted model. Typically an output of
likfit
,variofit
. If an object of the classeyefit
is passed it takes the first model specified in the object.- reestimate
logical. Indicates whether or not the model parameters should be re-estimated for each point removed from the data-set.
- variog.obj
on object with the empirical variogram, typically an output of the function
variog
. Only used ifreestimate = TRUE
and the object passed to the argumentmodel
is the result of a variogram based estimation, i.e. if the model was fitted byvariofit
.- output.reestimate
logical. Only valid if
reestimate = TRUE
. Specifies whether the re-estimated parameters are returned.- locations.xvalid
there are three possible specifications for this argument:
"all"
indicates the leaving-on-out method is used at all data locations. The second possibility is to use only a sub-set of the data for cross-validation in which case the argument takes a vector with numbers (indexes) indicating at which of the data locations the cross-validation should be performed. The third option is to perform external validation, on locations other than data locations used for the model. For the latter a matrix with the coordinates of the validation points should be provided and the argumentdata.xvalid
mandatory.- data.xvalid
data values at the validation locations. Only used if the validation locations are other than the data locations.
- messages
logical. Indicates whether status messages should be printed on the screen (or output device) while the function is running.
- …
further arguments to the minimization functions used by
likfit
,variofit
.
Details
The cross-validation uses internally the function krige.conv
to predict at each location.
For models fitted by variofit
the
parameters \(\kappa\), \(\psi_A\), \(\psi_R\)
and \(\lambda\) are always regarded as fixed when
reestimating the model.
See documentation of the function likfit
for further
details on the model specification and parameters.
Value
An object of the class
"xvalid"
which is a list with the following components:
the original data.
the values predicted by cross-validation.
the cross-validation prediction variance.
the differences data - predicted value
.
the errors divided by the square root of the prediction variances.
the cumulative probability at original value under a normal distribution with parameters given by the cross-validation results.
A method for summary returns summary statistics for the errors and standard errors. If reestimate = TRUE and output = TRUE additional columns are added to the resulting data-frame with the values of the re-estimated parameters.
References
Further information on the package geoR can be found at: http://www.leg.ufpr.br/geoR.
See Also
plot.xvalid
for plotting of the results, likfit
,
variofit
for parameter estimation and
krige.conv
for the kriging method used for predictions.
Examples
# NOT RUN {
#
# Maximum likelihood estimation
#
s100.ml <- likfit(s100, ini = c(.5, .5), fix.nug = TRUE)
#
# Weighted least squares estimation
#
s100.var <- variog(s100, max.dist = 1)
s100.wls <- variofit(s100.var, ini = c(.5, .5), fix.nug = TRUE)
#
# Now, performing cross-validation without reestimating the model
#
s100.xv.ml <- xvalid(s100, model = s100.ml)
s100.xv.wls <- xvalid(s100, model = s100.wls)
##
## Plotting results
##
par.ori <- par(no.readonly = TRUE)
##
par(mfcol=c(5,2), mar=c(2.3,2.3,.5,.5), mgp=c(1.3, .6, 0))
plot(s100.xv.ml)
par(mfcol=c(5,2))
plot(s100.xv.wls)
##
par(par.ori)
#
# }