makeFoldsGLMcv: Generate folds for cross-validation of generalized linear...

View source: R/ridgeGLMandCo.R

makeFoldsGLMcvR Documentation

Generate folds for cross-validation of generalized linear models.

Description

Function that evaluates the targeted ridge estimator of the regression parameter of generalized linear models.

Usage

makeFoldsGLMcv(fold, Y, stratified=TRUE, model="linear")

Arguments

fold

An integer, the number of folds to be generated.

Y

A numeric being the response vector.

stratified

A logical. If stratified=TRUE, the folds are generated such the distribution of the response Y is (roughly) the same across folds.

model

A character, either "linear" and "logistic" (a reference to the models currently implemented), indicative of the type of response for stratification.

Value

A list of length fold. Each list item is a fold.

Author(s)

W.N. van Wieringen.

Examples

# set the sample size
n <- 50

# set the true parameter
betas <- (c(0:100) - 50) / 20

# generate covariate data
X <- matrix(rnorm(length(betas)*n), nrow=n)

# sample the response
probs <- exp(tcrossprod(betas, X)[1,]) / (1 + exp(tcrossprod(betas, X)[1,]))
Y     <- numeric()
for (i in 1:n){
    Y <- c(Y, sample(c(0,1), 1, prob=c(1-probs[i], probs[i])))
}

# generate folds 
folds <- makeFoldsGLMcv(10, Y, model="logistic")

porridge documentation built on Oct. 16, 2023, 1:06 a.m.