Learn R Programming

perry (version 0.1.1)

repCV: (Repeated) cross-validation for fitted models

Description

Estimate the prediction error of a fitted model via (repeated) $K$-fold cross-validation. This works for any model for which a perry method is available.

Usage

repCV(object, K = 5, R = 1,
    foldType = c("random", "consecutive", "interleaved"),
    grouping = NULL, folds = NULL, ...)

Arguments

object
the fitted model for which to estimate the prediction error.
K
an integer giving the number of folds into which the observations should be split (the default is five). Setting K equal to the number of observations or groups yields leave-one-out cross-validation.
R
an integer giving the number of replications for repeated $K$-fold cross-validation. This is ignored for for leave-one-out cross-validation and other non-random splits of the data.
foldType
a character string specifying the type of folds to be generated. Possible values are "random" (the default), "consecutive" or "interleaved".
grouping
a factor specifying groups of observations. If supplied, the data are split according to the groups rather than individual observations such that all observations within a group belong to the same fold.
folds
an object of class "cvFolds" (as returned by cvFolds) or a control object of class "foldControl" (see foldControl) defini
...
additional arguments to be passed down to perry.

Value

  • An object of class "perry" as returned by perry.

See Also

perry, repRS, bootPE

Examples

Run this code
# load data and fit an LS regression model
data("mtcars")
fit <- lm(mpg ~ wt + cyl, data=mtcars)

# perform cross-validation
repCV(fit, K = 5, R = 10, seed = 1234)  # K-fold CV
repCV(fit, K = nrow(mtcars))            # leave-one-out CV

Run the code above in your browser using DataLab