Learn R Programming

analogue (version 0.10-0)

crossval: Cross-validation of palaeoecological transfer function models

Description

Performs leave-one-out, k-fold, n k-fold and bootstrap cross-validation of palaeoecological transfer function models.

Usage

crossval(obj, ...)

## S3 method for class 'wa': crossval(obj, method = c("LOO","kfold","bootstrap"), nboot = 100, nfold = 10, folds = 5, verbose = getOption("verbose"), ...)

Arguments

obj
A fitted transfer function model. Currently, only objects of class "wa" are supported.
method
character; type of cross-validation.
nboot
numeric; number of bootstrap samples.
nfold
numeric; number of chunks into which the training data are split. The k in k-fold.
folds
numeric; the number of times k-fold CV is performed.
verbose
logical; should progress of the CV be displayed?
...
Arguments passed to other methods.

Value

  • Returns an object of class "crossval", a list with the following components:
  • fitted.valuesnumeric vector; the cross-validated estimates of the response.
  • residualsnumeric vector; residuals computed from the cross-validated estimates of the response.
  • performancedata frame; cross-validation performance statistics for the model.
  • CVparamslist; parameters holding details of the cross-validation process.
  • callthe matched call.

See Also

wa

Examples

Run this code
## Load the Imbrie & Kipp data and
## summer sea-surface temperatures
data(ImbrieKipp)
data(SumSST)
     
## fit the WA model
mod <- wa(SumSST ~., data = ImbrieKipp)
mod

## Leave one out CV
cv.loo <- crossval(mod)
cv.loo

## k-fold CV (k == 10)
cv.kfold <- crossval(mod, kfold = 10, folds = 1, method = "kfold")
cv.kfold

## n k-fold CV (k == 10, n = 10)
cv.nkfold <- crossval(mod, kfold = 10, folds = 10, method = "kfold")
cv.nkfold

## bootstrap with 250 bootstrap samples
cv.boot <- crossval(mod, method = "bootstrap", nboot = 250)
cv.boot

## extract fitted values and residuals
fitted(cv.boot)
resid(cv.boot)

Run the code above in your browser using DataLab