Questions tagged [glmnet]

glmnet is an R package for Lasso and elastic-net regularized generalized linear models.

Overview

glmnet is an R package which provides Lasso and elastic-net regularized generalized linear models. It features extremely efficient procedures for fitting the entire Lasso or elastic-net regularization path for linear regression, logistic and multinomial regression models, Poisson regression and the Cox model.

Resources

Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique.
Consider whether your question might be better suited to Cross Validated, the Stack Exchange site for statistics, machine learning and data analysis.

598 questions
41
votes
1 answer

R glmnet : "(list) object cannot be coerced to type 'double' "

I'm trying to use the glmnet package on a dataset. I'm using cv.glmnet() to get a lambda value for glmnet(). Here's the dataset and error message: > head(t2) X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 1 1 1 0.7661266 45 2…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
40
votes
9 answers

Extracting coefficient variable names from glmnet into a data.frame

I would like to extract the glmnet generated model coefficients and create a SQL query from them. The function coef(cv.glmnet.fit) yields a 'dgCMatrix' object. When I convert it to a matrix using as.matrix, the variable names are lost and…
David Eborall
  • 401
  • 1
  • 4
  • 3
28
votes
3 answers

R glmnet as.matrix() error message

I'm trying to use the glmnet package on a dataset. I'm using cv.glmnet() to get a lambda value for glmnet(). I'm excluding columns 1,2,7,12 as they are: id column, response column, contain NA's, and contain NA's. Here's the dataset and error…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
24
votes
1 answer

How can I force cv.glmnet not to drop one specific variable?

I am running a regression with 67 observasions and 32 variables. I am doing variable selection using cv.glmnet function from the glmnet package. There is one variable I want to force into the model. (It is dropped during normal procedure.) How can I…
lareven
  • 379
  • 2
  • 15
23
votes
3 answers

Getting glmnet coefficients at 'best' lambda

I am using following code with glmnet: > library(glmnet) > fit = glmnet(as.matrix(mtcars[-1]), mtcars[,1]) > plot(fit, xvar='lambda') However, I want to print out the coefficients at best Lambda, like it is done in ridge regression. I see…
rnso
  • 23,686
  • 25
  • 112
  • 234
21
votes
1 answer

Formula interface for glmnet

In the last few months I've worked on a number of projects where I've used the glmnet package to fit elastic net models. It's great, but the interface is rather bare-bones compared to most R modelling functions. In particular, rather than specifying…
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
21
votes
2 answers

How to make all interactions before using glmnet

I have an x-matrix of 8 columns. I want to run glmnet to do a lasso regression. I know I need to call: glmnet(x, y, family = "binomial", ...). However, how do I get x to consider all one way interactions as well? Do I have to manually remake the…
user1357015
  • 11,168
  • 22
  • 66
  • 111
21
votes
2 answers

Why is it inadvisable to get statistical summary information for regression coefficients from glmnet model?

I have a regression model with binary outcome. I fitted the model with glmnet and got the selected variables and their coefficients. Since glmnet doesn't calculate variable importance, I would like to feed the exact output (selected variables and…
TongZZZ
  • 756
  • 2
  • 8
  • 20
20
votes
2 answers

Big matrix to run glmnet()

I am having a problem to run glmnet lasso with a wide data set. My data has N=50, but p > 49000, all factors. So to run glmnet i have to create a model.matrix, BUT i just run out of memory when i call model.matrix(formula, data), where formula =…
Flavio Barros
  • 996
  • 1
  • 11
  • 29
18
votes
4 answers

R error in glmnet: NA/NaN/Inf in foreign function call

I am trying to create a model using glmnet, (currently using cv to find the lambda value) and I am getting an error NA/NaN/Inf in foreign function call (arg 5). I believe this has something to do with the NA values in my data set, because when I…
mgoldwasser
  • 14,558
  • 15
  • 79
  • 103
16
votes
3 answers

How to solve 'protection stack overflow' issue in R Studio

I'm trying to build a model with the glmnet package, but I'm getting the following error when I run the following line: #library('glmnet') x = model.matrix(response ~ ., data = acgh_frame[,c(3:ncol(acgh_frame))]) Error: protect(): protection stack…
Ansjovis86
  • 1,506
  • 5
  • 17
  • 48
16
votes
2 answers

Difference between glmnet() and cv.glmnet() in R?

I'm working on a project that would show the potential influence a group of events have on an outcome. I'm using the glmnet() package, specifically using the Poisson feature. Here's my code: # de <- data imported from sql connection x <-…
Sean Branchaw
  • 597
  • 1
  • 5
  • 21
16
votes
2 answers

How does glmnet's standardize argument handle dummy variables?

In my dataset I have a number of continuous and dummy variables. For analysis with glmnet, I want the continuous variables to be standardized but not the dummy variables. I currently do this manually by first defining a dummy vector of columns that…
Dr. Beeblebrox
  • 838
  • 2
  • 13
  • 30
14
votes
2 answers

'x' and 'w' must have same length - error in weighted.mean.default

I am having a problem with the package glmnet in R. I am trying to use it off-the-shelf, and am getting the following problem: test <- glmnet(seq.trans,rsem.trans) Error in weighted.mean.default(y, weights) : 'x' and 'w' must have the same…
Ian Fiddes
  • 2,821
  • 5
  • 29
  • 49
13
votes
2 answers

R vector size limit: "long vectors (argument 5) are not supported in .C"

I have a very large matrix I'm trying to run through glmnet on a server with plenty of memory. It works fine even on very large data sets up to a certain point, after which I get the following error: Error in elnet(x, ...) : long vectors (argument…
Danny
  • 3,077
  • 2
  • 23
  • 26
1
2 3
39 40