assign_fold {ncvreg} | R Documentation |
Assign folds for cross-validation
Description
If y has only two unique values, fold assignments are chosen so that the balance between outcomes is the same in each fold. This is useful for logistic regression and time-to-event data (to balance the fraction of observations that are censored).
Usage
assign_fold(y, folds, seed)
Arguments
y |
Either (i) the vector of outcomes or (ii) a vector such as |
folds |
Number of folds |
seed |
(optional) set a seed for reproducibility |
Value
A vector of integers indicating fold assignments
See Also
[cv.ncvreg()]
Examples
assign_fold(rnorm(11), 2)
assign_fold(1:41, 7)
assign_fold(1:41, 7) |> table()
data(Heart)
assign_fold(Heart$y, 7) |> head()
assign_fold(Heart$y, 7) |> table(Heart$y)
[Package ncvreg version 3.15.0 Index]