perryTuning(object, ...) ## S3 method for class 'function':
perryTuning(object, formula,
data = NULL, x = NULL, y, tuning = list(),
args = list(), splits = foldControl(),
predictFun = predict, predictArgs = list(),
cost = rmspe, costArgs = list(),
selectBest = c("min", "hastie"), seFactor = 1,
names = NULL, envir = parent.frame(), ncores = 1,
cl = NULL, seed = NULL, ...)
## S3 method for class 'call':
perryTuning(object, data = NULL,
x = NULL, y, tuning = list(), splits = foldControl(),
predictFun = predict, predictArgs = list(),
cost = rmspe, costArgs = list(),
selectBest = c("min", "hastie"), seFactor = 1,
names = NULL, envir = parent.frame(), ncores = 1,
cl = NULL, seed = NULL, ...)
call
for the
latter).formula
describing
the model.formula
."cvFolds"
(as
returned by cvFolds
) or a control object of
class "foldControl"
(see
foldControl
) definipredictFun
.cost
."min"
(the default) or "hastie"
. The
former selects the model with the smallest prediction
error. The latter is useful for modselectBest
is
"min"
.environment
in which to
evaluate the function call for fitting the models (see
eval
).NA
, all available processor cores are used.makeCluster
. If
supplied, this is preferred over ncores
..Random.seed
). Note that
also in case of parallel computing, resampling is
performed on the manager process rather than the worker
prtuning
is an empty list, perryFit
is called to return an object of class "perry"
. Otherwise an object of class "perryTuning"
(which
inherits from class "perrySelect"
) with the
following components is returned:
folds
). Each of the $K$ data blocks
is left out once to fit the model, and predictions are
computed for the observations in the left-out block with
predictFun
. 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 $K$-fold
cross-validation (as indicated by splits
), this
process is replicated and the estimated prediction errors
from all replications are returned. (Repeated) random splitting is performed similarly. In
each replication, the data are split into a training set
and a test set at random. Then the training data is used
to fit the model, and predictions are computed for the
test data. Hence only the response values from the test
data and the corresponding predictions are passed to the
prediction loss function cost
.
For the bootstrap estimator, each bootstrap sample is
used as training data to fit the model. The out-of-bag
estimator uses the observations that do not enter the
bootstrap sample as test data and computes the prediction
loss function cost
for those out-of-bag
observations. The 0.632 estimator is computed as a
linear combination of the out-of-bag estimator and the
prediction loss of the fitted values of the model
computed from the full sample.
In any case, if the response is a vector but
predictFun
returns a matrix, the prediction error
is computed for each column. A typical use case for this
behavior would be if predictFun
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 call
method, which does 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
.
perryFit
, perrySelect
,
cvFolds
, randomSplits
,
bootSamples
, cost
data("coleman")
## evaluate MM regression models tuned for 85\% and 95\% efficiency
tuning <- list(tuning.psi = c(3.443689, 4.685061))
## 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
perryTuning(lmrob, formula = Y ~ ., data = coleman,
tuning = tuning, splits = foldControl(K = 5, R = 10),
cost = rtmspe, costArgs = list(trim = 0.1), seed = 1234)
## via function call
# set up function call
call <- call("lmrob", formula = Y ~ .)
# perform cross-validation
perryTuning(call, data = coleman, y = coleman$Y,
tuning = tuning, splits = foldControl(K = 5, R = 10),
cost = rtmspe, costArgs = list(trim = 0.1), seed = 1234)
Run the code above in your browser using DataLab