nested.glm: Cross-validated generalized linear models

nested.glmR Documentation

Cross-validated generalized linear models

Description

Run linear or logistic regression on a set of cross-validation folds. This can be used to establish a baseline model, often built only on the initial set of covariates.

Usage

nested.glm(formula, data, family, folds, store.glm = FALSE)

Arguments

formula

An object of class formula (or one that can be coerced to that class) that describes the baseline model to be fitted.

data

Data frame or matrix containing outcome variable and predictors.

family

Type of model fitted: either gaussian() for linear regression or binomial() for logistic regression. This can be specified also as a function name (gaussian) or as a string ("gaussian").

folds

List of cross-validation folds, where each element contains the indices of the observations to be withdrawn in that fold.

store.glm

Whether the object produced by glm should be stored (default: FALSE).

Value

An object of class nestglm of length equal to length(folds), where each entry contains the following fields:

summary

Summary of the coefficients of the model fitted on the training observations.

family

Type of model fitted.

fit

Predicted values for the withdrawn observations.

obs

Observed values for the withdrawn observations.

test.llk

Test log-likelihood.

test.idx

Indices of the the withdrawn observations for this fold.

regr

Object created by glm (only if store.glm=TRUE).

See Also

nested.performance().

Examples


data(diabetes)
folds <- create.folds(10, nrow(diabetes), seed=1)
res <- nested.glm(Y ~ age + sex + bmi + map, diabetes, gaussian(), folds)



nestfs documentation built on Dec. 28, 2022, 1:27 a.m.