A “stand alone” cross-validation function for groc
objects.
grocCrossval(object, segments = 10, segment.type = c("random",
"consecutive","interleaved"), length.seg, trace = 15, ...)
The supplied object
is returned, with an additional component
validation
, which is a list with components
equals "CV"
for cross-validation.
an array with the cross-validated predictions.
a matrix of PRESS values for models with 1, ...,
ncomp
components. Each row corresponds to one response variable.
a matrix of PREMAD values for models with 1, ...,
ncomp
components. Each row corresponds to one response variable.
a matrix of sqrt(PRESS/nobj) values for models with 1, ...,
ncomp
components. Each row corresponds to one response variable.
the list of segments used in the cross-validation.
the number of components.
a groc
object; the regression to cross-validate.
the number of segments to use, or a list with segments (see below).
the type of segments to use.
Positive integer. The length of the segments to use.
if TRUE
, tracing is turned on. If numeric, it
denotes a time limit (in seconds). If the estimated total time of
the cross-validation exceeds this limit, tracing is turned on.
additional arguments, sent to the underlying fit function.
Martin Bilodeau (bilodeau@dms.umontreal.ca) and Pierre Lafaye de Micheaux (lafaye@unsw.edu.au)
This function performs cross-validation on a model fit by groc
.
It can handle models such as groc(Y ~ X, ...)
.
Note that to use grocCrossval
, the data must be specified
with a data
argument when fitting object
.
If segments
is a list, the arguments segment.type
and
length.seg
are ignored. The elements of the list should be
integer vectors specifying the indices of the segments.
Otherwise, segments of type segment.type
are generated. How
many segments to generate is selected by specifying the number of
segments in segments
, or giving the segment length in
length.seg
. If both are specified, segments
is
ignored.
When tracing is turned on, the segment number is printed for each segment.
Martin Bilodeau, Pierre Lafaye de Micheaux, Smail Mahdi (2015), The R
Package groc for Generalized Regression on Orthogonal Components,
Journal of Statistical Software, 65(1), 1-29,
https://www.jstatsoft.org/v65/i01/
data(yarn,package="pls")
yarn.groc <- groc(density ~ NIR, 6, data = yarn)
yarn.cv <- grocCrossval(yarn.groc, segments = 10)
yarn.cv$validation$PRESS
yarn.cv$validation$PREMAD
Run the code above in your browser using DataLab