Specific Dataset causes the glm.nb fucntion to crash for no apparent reason when attempting to perform regression

13 Views Asked by At

So I am attempting to run a Negatice Binomial Regression to estimate a trend of a number of events over time. To do this I am using the function glm.nb() from the MASS package. This has worked for a number of datasets without any issues whatsoever, until now. For some reason when using the code and the specififc dataset below, glm.nb fails, which is weird since it works for any other dataset i have tried:

data<-c(2, 4, 2, 4, 2, 6, 1, 3, 7, 3, 2, 3, 1, 5, 3, 5, 1, 4, 4, 0, 4, 1, 5, 0, 3, 2, 5, 8, 4, 0, 1, 0, 3, 2, 3, 2, 3, 4, 1, 2, 2, 1, 3, 1, 3, 2, 3, 1, 2, 3, 1, 3, 4, 2, 4, 2, 2, 3, 2, 4, 0) # my actual data

time<-c(1:length(data)) #simply a vector from 1 to n(data) for every timestep

glm.nb(data~time)

This generates the error "In theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace = control$trace > : iteration limit reached" twice.

This is strange since it worked on over 100 different (but similar) datasets. Attempting to fix it by increasing the iteration limit doesnt solve this issue, it causes additonal problems instead. If iteration limit > 68 an additional error "In sqrt(1/i) : NaNs produced" is added to the existing ones.

I have absolutely no clue as to what the problem could be. Does anybody know if glm.nb() is at fault here or if my data is the cause? Apologies if its something glaringly obvous that I have missed.

Any help is appreciated :)

EDIT: Closing and restarting R-Studio somehow fixed the problem

0

There are 0 best solutions below