stratify_folds: Generate Stratified Fold IDs

View source: R/helpers.R

stratify_foldsR Documentation

Generate Stratified Fold IDs

Description

Returns a vector of fold IDs that preserves class proportions.

Usage

stratify_folds(y, nfolds = 10, seed = NULL)

Arguments

y

Numeric vector for the (binomial) response variable.

nfolds

Number of folds (default: 10).

seed

An integer that is used as argument by set.seed() for offsetting the random number generator. Default is to not set a particular randomization seed.

Value

Numeric vector with the same length as y.

Examples

y <- rbinom(100, 1, 0.3)
foldids <- stratify_folds(y, nfolds = 5)
table(y, foldids)

riskscores documentation built on June 8, 2025, 10:27 a.m.