Skip to contents

This function extracts necessary components from a glmnet object (either cv.glmnet or glmnet) to create an ftmglm object. It uses the optimal, or specified, penalty parameter (lambda) and the data used in the glmnet model to adapt them into the FTM framework.

Usage

createFromGlmnet(glmnetObj, s = NULL, x = NULL, y = NULL, outcome_name = NULL)

Arguments

glmnetObj

a cv.glmnet or glmnet object from the glmnet package

s

value of the penalty parameter (lambda) to use; default for cv.glmnet is lambda.min

x

matrix of predictors used in the glmnet model

y

vector of outcomes used in the glmnet model

outcome_name

Optional name of the outcome variable; if not provided, it will be extracted from the model object.

Value

A ftmglm or ftmlm object.

Note

The data used in the glmnet model must be available in the global environment.

Examples

if (FALSE) { # \dontrun{
# Fitting a glmnet model to the mtcars dataset
data(mtcars)
predictors <- as.matrix(mtcars[, c("hp", "wt", "cyl")])
glmnet_model <- glmnet::cv.glmnet(predictors, mtcars$am, family = "binomial", alpha = 0)
ftmglm_model <- createFromGlmnet(glmnet_model, x = predictors, y = mtcars$am)
} # }