Learn R Programming

ncvreg (version 3.15.0)

assign_fold: 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)

Value

A vector of integers indicating fold assignments

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

See Also

[cv.ncvreg()]

Examples

Run this code
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)

Run the code above in your browser using DataLab