I'm running a negative binomial lasso in R using glmnet with package version 4.0-2
No matter how much I trim down the data, I get an error due that reads
Error: inner loop 1; cannot correct step size
In addition: Warning messages:
1: Infinite objective function!
2: step size truncated due to divergence
At first I thought this was because the function thought my matrix was not full rank, but it is (though this is why I kept trying to trim the data down and now only use an example with one predictor - regardless I get the same error).
I want to use a geometric distribution on my discrete continuous response variable, so I specify my family argument accordingly. The response variable doesn't have the shape of a geometric distribution (looks more like NB), but it is formed from a real world process that should yield a geometric distribution (if you have a problem with this, I tried other theta values in the family assignment and still got this error).
I basically get this error for both glmnet::cv.glmnet and glmnet::glmnet (where, for the latter, I try many dummy values for lambda).
Here is my code
y = c(4 , 2 , 1 , 1 , 7 , 8 , 5 , 3 , 3 , 1 , 2 , 6 , 2 , 4 , 5 , 1 , 7 , 5 , 8 , 10 , 9 , 3 , 2 , 7 , 1 , 4 , 2 , 3 , 3 , 11 , 4 , 2 , 6 , 6 , 1 , 8 , 3 , 6 , 2 , 3 , 3 , 2 , 3 , 5 , 4 , 5 , 7 , 6 , 4 , 8)
x = c(101 , 102 , 98 , 26 , 43 , 50 , 102 , 49 , 36 , 37 , 40 , 82 , 84 , 0 , 70 , 99 , 94 , 74 , -3 , 71 , 60 , 62 , 59 , 56 , 77 , 143 , 115 , 48 , 56 , 90 , 139 , 80 , 72 , 36 , 105 , 71 , 34 , 72 , 62 , 78 , 112 , 76 , 88 , 45 , 82 , 82 , 102 , 105 , 39 , 62)
temp <- data.frame(y = y, x = x)
temp2 <-
Matrix::sparse.model.matrix(
y ~ x, temp)
lasso_best <-
glmnet::cv.glmnet(
x = temp2,
y = temp$y,
family = MASS::negative.binomial(theta = 1, link = "log"),
alpha = 1,
nfolds = 3,
standardize = TRUE,
lambda = exp(seq(log(0.001), log(5), length.out=50))
)
Any help would be greatly appreciated, thanks in advance and thanks if you read this far :)