Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Impact of numDeriv and maxLik on estimating the hessian

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Jane
Posts: 5
Joined: 02 Nov 2020, 04:24

Impact of numDeriv and maxLik on estimating the hessian

Post by Jane »

Hi,

I have been estimating a mixed logit discrete choice model in Apollo and I was receiving errors indicating positivity in the hessian and some NaN's for standard errors while using the maxLik package to estimate the hessian. If I use the numDeriv package the model has stabilised (okay hessian and all se's estimated). Should I be concerned? I have estimated the model using other software and output/model is stable (converging okay, negative hessian and se's okay). Parameter estimates are consistent for all versions. I have been estimating at 6000 sobol draws (3030 obs, 11 random parameters and 11 fixed parameters).

Interested to hear your thoughts on the impact of using these different packages to estimate the hessian in Apollo.

Cheers
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Impact of numDeriv and maxLik on estimating the hessian

Post by dpalma »

Hi Jane,

What version of Apollo are you using? You can see it when you load the library.

Thanks
David
Jane
Posts: 5
Joined: 02 Nov 2020, 04:24

Re: Impact of numDeriv and maxLik on estimating the hessian

Post by Jane »

Currently I am running Apollo 0.2.1 and the comments above are from working with this version, but I was using 0.0.9 and actually (if I remember correctly i had specified the maxLik package) in this version I didn't have the warnings about positive hessian and nan's for se.

Cheers,
Alaya
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Impact of numDeriv and maxLik on estimating the hessian

Post by dpalma »

Hi Alaya,

Newer versions of Apollo include more information on the Hessian than older versions. For example, the biggest eigenvalue was not reported prior to v0.1.0. So it may be that the issue was present in v0.0.9, but it simply wasn't reported. You can check this by manually calculating the eigenvalues for the model$hessian object.

Since v0.2.0, Apollo supports three ways to calculate the Hessian:
  • By numerically differentiating the analytical gradient of the model (only available for the most common models)
  • Full numerical differentiation using the numDeriv package
  • Full numerical differentiation using the maxLik package
In theory, they should all render the same results, but in practice there may be differences due to numerical issues. By default, Apollo will try the methods in the described order, e.g. jumping to the second if the first one fails. When available, we always recommend using the analytical gradient, as it is faster to compute and relies less on numerical approximations. The numDeriv package uses more precise approximations than maxLik does, but in our experience is slightly less robust.

In summary, if Apollo does manage to calculate the Hessian (and the corresponding s.e.) I wouldn't worry too much about the method used to obtain it, as they are all consistent among them. If you get the warning about positive eigenvalues (which happens more often in complicated models with multiple local maximum), you might be in a saddle point, so I would recommend trying different starting values in the hope of finding a better solution. You can do this automatically with the apollo_searchStart function.

Cheers
David
Post Reply