Learn R Programming

riskscores (version 1.2.3)

stratify_folds: Generate Stratified Fold IDs

Description

Returns a vector of fold IDs that preserves class proportions.

Usage

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

Value

Numeric vector with the same length as y.

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.

Examples

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

Run the code above in your browser using DataLab