I\'m running several hundred datasets through glm.nb
using a wrapper function. Nothing fancy, I just pass on each list item via llply
, then fit using <
I have an nls() which I run that has the same challenge. I'm applying the regression to every group in a data.frame, but this logic should work for you as well (I think):
dlply(myData, c("group1", "group2"), function(df){
tryCatch(nls(depen ~ exp(a1 + b1 * year) , data=df, start = list(a1 = -1, b1 = 0), na.action=na.omit), error=function(e) NULL)
so if I were to guess how to apply that to your situation, it would be something like:
res <- trycatch(glm.nb(x~y, data=x), error=function(e) NULL )
The way I use this, I'm throwing NA values any time the regression does not converge. You may want to do something different.
you can also use the failwith function in plyr. if f is the function you are passing to plyr, you can instead pass the function
safef = failwith(NA, f)
of course, you can replace NA with whatever return value you need when the function fails. this code is lifted directly from the examples for failwith.