Relatively new to GLMNET and having an odd problem. I know the binomial family of regression requires a binary response variable (IE a 1 or 0). I have data in which each entry has a large number of trials and a proportion of successes. IE, the first line has a bunch of potential explanatory variables and then the response is like 27 successes in 427 attempts.

My understanding on how to do this is to duplicate each line with the response being a '1' for one line and a '0' for the other. And then weight each of those by the number of successes and failures. So 27 and 400 respectively. I have about 6000 of those.

But what happens is that cv.glmnet pretty much always returns nothing but an intercept and eliminates all the explanatory variables (regardless of lasso, elnet or ridge). This is wrong as there are several variables with strong relationships to the response. Switching over to gaussian regression causes them to show up immediately, but I specifically want logistic regression.

It seems like the weighting is working, and since for every '1' there's an identical set of explanatory variables for every '0', without the weights obviously everything cancels out.

Now if I use penalty factors and demand it accepts certain variables, it will work after a fashion, but then all it does is use those variables and eliminates the rest.

It unfortunately is a roadblock right now. I could do a gaussian regression to find the variables, and then switch to binomial with the penalty factors set appropriately, but I understand that there are fundamental differences between the two that makes that invalid.


The core of glmnet (the fortran code) does not accept sample weights for binomial regression models.

Contrast the call structure of the elastic net (the linear model)

call elnet(ka,parm,no,ni,x,y,w,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,

to the call structure for the lognet (the binomial model)

call lognet (parm,no,ni,nc,x,y,o,jd,vp,cl,ne,nx,nlam,flmin,ulam,thr,isd,

The binomial model has no w argument.

I'm not sure what the R wrapper does when you supply sample weights to a longet, I suspect it ignores them. It would explain what you are seeing, because the fitting algorithm would, in your situation, see one positive and one negative case for every combination of predictors. This would drive all the coefficients to zero. Passing sample weights to the lognet should be an error, but unfortunately it just seems to cause surprising behavior.

What you want to do is pass in a two column matrix for your response vector. The first column will be a count of negative cases, the second a count of positive cases. This is documented

For family="binomial" should be either a factor with two levels, or a two-column matrix of counts or proportions (the second column is treated as the target class; for a factor, the last level in alphabetical order is the target class).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.