assign_fold: Assign folds for cross-validation

View source: R/assign_fold.R

assign_foldR 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 1:n

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)

ncvreg documentation built on April 12, 2025, 1:16 a.m.