Learn R Programming

analogue (version 0.17-7)

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 wa crossval(obj, method = c("LOO","kfold","bootstrap"), nboot = 100, nfold = 10, folds = 5, verbose = getOption("verbose"), ...)

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

Value

Returns an object of class "crossval", a list with the following components:

fitted.values

numeric vector; the cross-validated estimates of the response.

residuals

numeric vector; residuals computed from the cross-validated estimates of the response.

performance

data frame; cross-validation performance statistics for the model.

CVparams

list; parameters holding details of the cross-validation process.

call

the matched call.

Arguments

obj

A fitted transfer function model. Currently, only objects of class wa and pcr are supported.

method

character; type of cross-validation.

ncomp

numeric; number of components to fit, as in models with 1:ncomp components.

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.

Author

Gavin L. Simpson

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, method = "kfold", kfold = 10, folds = 1)
cv.kfold

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

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

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

## Principal Components Regression
mpcr <- pcr(SumSST ~., data = ImbrieKipp, ncomp = 10)
crossval(mpcr, method = "kfold", kfold = 10, folds = 2, ncomp = 10)

crossval(mpcr, method = "bootstrap", nboot = 100, ncomp = 10)

Run the code above in your browser using DataLab