I am trying to run a negative binomial regression using the glmnet 4.0 package. I have implemented the regression using code from the section entitled 'Fitting Other GLMs' of this webpage. However, I keep getting the following error:
Error in seq.default(log(lambda_max), log(lambda_max * lambda.min.ratio), : 'from' must be a finite number
I haven’t been able to find examples of other people experiencing this error in the past. I think maybe because it is specific to this new version of the package?
Below is an example which should reproduce the error. This is not the data I have been using for my analysis and is simply for example purposes.
library(eventdataR)
library(glmnet)
library(MASS)
df <- subset(traffic_fines, activity == "Create Fine" | activity == "Add penalty" )
df <- df[,c(4,6,7,9,13,14,18)]
df$resource <- as.numeric(df$resource)
dfm <- as.matrix(df[,-3])
newfit <- glmnet(dfm, df$amount, family = negative.binomial(theta = 5))
Does anyone know why this error might be occurring and what I can do to stop it?