cvFit(object, ...)
## S3 method for class 'default':
cvFit(object, data = NULL, x = NULL,
y, cost = rmspe, K = 5, R = 1,
foldType = c("random", "consecutive", "interleaved"),
folds = NULL, names = NULL, predictArgs = list(),
costArgs = list(), envir = parent.frame(), seed = NULL,
...)
## S3 method for class 'function':
cvFit(object, formula, data = NULL,
x = NULL, y, args = list(), cost = rmspe, K = 5, R = 1,
foldType = c("random", "consecutive", "interleaved"),
folds = NULL, names = NULL, predictArgs = list(),
costArgs = list(), envir = parent.frame(), seed = NULL,
...)
## S3 method for class 'call':
cvFit(object, data = NULL, x = NULL, y,
cost = rmspe, K = 5, R = 1,
foldType = c("random", "consecutive", "interleaved"),
folds = NULL, names = NULL, predictArgs = list(),
costArgs = list(), envir = parent.frame(), seed = NULL,
...)call for the latter). In the case of a
fitted formula describing
the model.formula.K
equal to n yie"random" (the default), "consecutive" or
"interleaved"."cvFolds" giving
the folds of the data for cross-validation (as returned
by cvFolds). If supplied, this is
preferred over K and R.predict method of the
fitted models.cost.environment in which to
evaluate the function call for fitting the models (see
eval)..Random.seed)."cv" with the following
components:predict method of the fitted model.
Thus a prediction is obtained for each observation.
The response variable and the obtained predictions for
all observations are then passed to the prediction loss
function cost to estimate the prediction error.
For repeated cross-validation, this process is replicated
and the estimated prediction errors from all replications
as well as their average are included in the returned
object.
Furthermore, if the response is a vector but the
predict method of the fitted models
returns a matrix, the prediction error is computed for
each column. A typical use case for this behavior would
be if the predict method returns
predictions from an initial model fit and stepwise
improvements thereof.
If formula or data are supplied, all
variables required for fitting the models are added as
one argument to the function call, which is the typical
behavior of model fitting functions with a
formula interface. In this case,
the accepted values for names depend on the
method. For the function method, a character
vector of length two should supplied, with the first
element specifying the argument name for the formula and
the second element specifying the argument name for the
data (the default is to use c("formula", "data")).
Note that names for both arguments should be supplied
even if only one is actually used. For the other
methods, which do not have a formula argument, a
character string specifying the argument name for the
data should be supplied (the default is to use
"data").
If x is supplied, on the other hand, the predictor
matrix and the response are added as separate arguments
to the function call. In this case, names should
be a character vector of length two, with the first
element specifying the argument name for the predictor
matrix and the second element specifying the argument
name for the response (the default is to use c("x",
"y")). It should be noted that the formula or
data arguments take precedence over x.cvTool, cvSelect,
cvTuning, cvFolds,
costlibrary("robustbase")
data("coleman")
## via model fit
# fit an MM regression model
fit <- lmrob(Y ~ ., data=coleman)
# perform cross-validation
cvFit(fit, data = coleman, y = coleman$Y, cost = rtmspe,
K = 5, R = 10, costArgs = list(trim = 0.1), seed = 1234)
## via model fitting function
# perform cross-validation
# note that the response is extracted from 'data' in
# this example and does not have to be supplied
cvFit(lmrob, formula = Y ~ ., data = coleman, cost = rtmspe,
K = 5, R = 10, costArgs = list(trim = 0.1), seed = 1234)
## via function call
# set up function call
call <- call("lmrob", formula = Y ~ .)
# perform cross-validation
cvFit(call, data = coleman, y = coleman$Y, cost = rtmspe,
K = 5, R = 10, costArgs = list(trim = 0.1), seed = 1234)Run the code above in your browser using DataLab