cv.trajectory: Cross-validated peeling trajectory

Description Usage Arguments Details Value References See Also Examples

View source: R/peeling_trajectory.R

Description

Performs k-fold cross-validation on peeling for choosing the stopping criterion.

Usage

1
cv.trajectory(y, x, grid = NULL, folds = NULL, nfolds = 10, ...)

Arguments

y

Numeric vector of response values.

x

Numeric or categorical data.frame of input values.

grid

Vector of stopping supports for peeling trajectory prediction. If NULL (the default), an initial peeling is carried out on the whole data and its support element is used.

folds

An integer vector giving the fold index of each observation. If NULL (the default) nfolds folds are randomly generated. Directly using folds is useful for nonstandard folds such as blocks. Note that folds is recycled if necessary.

nfolds

Integer giving the number of folds to create if folds is NULL.

...

Additional arguments to be passed to peeling.

Details

The cv.trajectory function splits the provided data into nfolds several folds. The peeling is carried out on nfolds - 1 folds and the objective function is computed on the remaining fold. This process is repeated excluding each fold successively and the resulting trajectories are averaged at each value in grid.

Folds can be given either directly through the argument folds or randomly generated using the argument nfolds.

Value

A cv.prim object that can be used in methods for prim objects (e.g. plot_trajectory). Contains the elements:

support

The support grid provided in the argument grid or generated if the latter is NULL.

yfun

The cross-validated objective function values at each support value.

se.yfun

Cross-validation standard errors associated with yfun values.

x,y

The input and response data used.

numeric.vars

A logical vector indicating, for each input variable, if it was considered as a numeric variable.

alpha, peeling.side, obj.fun

The value of the arguments used for peeling. Useful for prim methods.

References

Friedman, J.H., Fisher, N.I., 1999. Bump hunting in high-dimensional data. Statistics and Computing 9, 123-143. https://doi.org/10.1023/A:1008894516817

See Also

peeling for the peeling algorithm used in the function. plot_trajectory to analyse the cross-validated trajectory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
   # A simple bump
   set.seed(12345)
   x <- matrix(runif(2000), ncol = 2, dimnames = list(NULL, c("x1", "x2")))
   y <- 2 * x[,1] + 5 * x[,2] + 10 * (x[,1] >= .8 & x[,2] >= .5) + rnorm(1000)
   
   # 10-fold cross-validation
   cv_res <- cv.trajectory(y, x)
   
   # Display the cross-validated trajectory
   plot_trajectory(cv_res, type = "b", pch = 16, col = "cornflowerblue", 
     support = 0.1, npeel = which.max(cv_res$yfun), 
     abline.pars = list(lwd = 2, col = "indianred"), 
     xlab = "", xlim = c(0, 0.2), ylim = c(10, 18))

PierreMasselot/primr documentation built on Feb. 5, 2021, 7:33 p.m.