wayneeusa
wayneeusa

Reputation: 194

Specifying type of measure with lasso regression

I'm trying to do variable selection with glmnet and lasso poisson regression.

It runs if I use:

model.lasso <- glmnet(X,ED.visits, family="poisson", alpha=1, nlambda=1000)

But I've been asked to use "deviance" as a measure. I get an error when I run:

model.lasso <- glmnet(X,ED.visits, type.measure=c("deviance"), family="poisson", alpha=1, nlambda=1000)

type.measure is the right specification according to: the documentation.

Upvotes: 0

Views: 834

Answers (2)

StupidWolf
StupidWolf

Reputation: 46908

For a poisson family regression, by default it is fitting using deviance (minimizing it). The purpose of cv.glmnet is to find the optimal lambda using cross-validation, but since you already specified it, the results from using cv.glmnet and glmnet are the same:

library(glmnet)
x = matrix(rnorm(10000),1000,10)
y = rpois(1000,10)
cv.lasso <- cv.glmnet(x,y, 
type.measure="deviance", family="poisson", 
alpha=1, nlambda=1000)

model.lasso <- glmnet(x,y, family="poisson", 
alpha=1, nlambda=1000)

> identical(cv.lasso$glmnet.fit$beta,model.lasso$beta)
[1] TRUE

Do you need to find the optimal lambda? If not just use glmnet without the type="measure" argument.

Upvotes: 1

user12009469
user12009469

Reputation:

The argument: type.measure, is not part of the glmnet function but the cv.glmnet function. You are calling to an argument that is not part of the above described function.

Upvotes: 2

Related Questions