Closed dstoeckel closed 5 years ago
Thanks for this!
The issue in your example seems to be that the Hessian actually is singular because optim
is finding the "wrong" solution (a boundary solution that fits the large number of zeros with the count model). As a result, you can get it to perform properly by giving it better start values. For example, you can use the estimates of a hurdle model, which are much closer to the solution, for the start values. Thus, the following works without error for me:
fit.hurdle <- pscl::hurdle(y~1|1, dist="negbin")
fit <- pscl::zeroinfl(y~1|1, dist="negbin", start=fit.hurdle$coefficients)
Obviously, the zeroinfl
function should handle this situation better. I don't think using L-BFGS-B
or computing the Hessian differently are the best solutions here because the Hessian actually should be singular (although I think we might want to compute the Hessian differently anyway). But we should at least catch this error. Maybe we should issue a warning with that and suggest different start values? Or maybe the default should be to get better start values rather than using a vector of zeros (e.g., to get start values for the count side from a truncated count model and observations with non-zero responses, as happens with hurdle
.
Thank you for your answer! I agree that switching to L-BFGS-B
or anything else as a default would only be a band aid for this particular case and not a solution in general. The proper solution is probably to get better starting values and (as this will make the problem only less likely) to catch a singular Hessian + issue a warning.
For my particular case I will have to see whether I can convince the mpath
package to take different starting values (It is computing a whole LASSO path, so the probabilities may change a bit ...). But this is my problem :slightly_frowning_face:
thanks Alex, for weighing in on this
— Simon
On 19 Feb 2019, at 9:49 pm, Daniel Stöckel notifications@github.com<mailto:notifications@github.com> wrote:
Thank you for your answer! I agree that switching to L-BFGS-B or anything else as a default would only be a band aid for this particular case and not a solution in general. The proper solution is probably to get better starting values and (as this will make the problem only less likely) to catch a singular Hessian + issue a warning.
For my particular case I will have to see whether I can convince the mpath package to take different starting values (It is computing a whole LASSO path, so the probabilities may change a bit ...). But this is my problem 🙁
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://protect-au.mimecast.com/s/DpBPCJyp0qhWnxrmcVRUXh?domain=github.com, or mute the threadhttps://protect-au.mimecast.com/s/cQWNCK1qJZty1LEvFvsXnF?domain=github.com.
I added error handling with the Hessian and improved the starting values a bit. This at least fixes the example above (both in that it finds the correct solution with the new default starting values and it handles the singular Hessian properly if given the old starting values). It's also worked fine on all the examples I've tried. It's not on CRAN yet and should probably be tested a bit more first. But, until then, it can be installed from the github version using devtools
.
Hi, first of all thank you for the pscl package. I am using it directly and via mpath.
However, I have a numerical problem that pops up from time to time in the current CRAN version (1.5.2).
zeroinfl
callsoptim
to minimize the log-likelihood of the zero-inflated model. It then uses the inverse of the inferred Hessian (Fisher Information matrix) to compute the standard error oftheta
. If the Hessian is singular, this crashes. However, the inferred Hessian can simply become singular due to numerical issues in the optimization procedure (method="BFGS"
), which crashes thesolve
call:The problem disappears if
L-BFGS-B
: Fast, but leads to warnings due to reltol being definedCG
: Significantly slowerEM=TRUE
is used (Much slower)The following code reproduces the problem:
Proposed solutions:
L-BFGS-B
can be used.