Learn R Programming

ModelGood (version 1.0.9)

ElasticNet: Wrapper function for glmnet

Description

Wrapper function for glmnet

Usage

ElasticNet(formula, data, nfolds = 10, ...)

Arguments

formula
Formula where the right hand side specifies the response and the left hand side the predictor matrix
data
A data frame in which formula is evaluated
nfolds
nfolds: number of cross-validation folds in cv.glmnet (default in function is 10)
...
passed on to glmnet

Value

Object with class ElasticNet

Details

This function first calls cv.glmnet and then evaluates glmnet at the hyper parameter which optimizes the cross-validation criterion.

See Also

predictStatusProb

Examples

Run this code
# Generate some data with binary response Y
 # depending on X1 and X2 and X1*X2
set.seed(40)
N <- 40
X1 <- rnorm(N)
X2 <- rbinom(N,1,.4)
X3 <- rnorm(N)
expit <- function(x) exp(x)/(1+exp(x))
lp <- expit(1 + X1 + X2 + X3)
Y <- factor(rbinom(N,1,lp))
dat <- data.frame(Y=Y,X1=X1,X2=X2,X3=X3)

efit <- ElasticNet(Y~X1+X2+X3,data=dat,family="binomial",alpha=0.1)
Brier(efit,verbose=FALSE)

Run the code above in your browser using DataLab