The optimization routines 'ucminf', 'nloptr' and 'trustOptim' requires the user to supply a gradient. Writing an analytical gradient can be quite cumbersome for very complex likelihood expressions. This function is a simple wrapper around numDeriv::grad() and prepares a high-precision numerical gradient that can be supplied directly to the optimizers that require one. Note that a numerical gradient is slower in calculation and less precise than an analytical gradient.

prepare_num_grad(ll, estim_env, workers)

Arguments

ll

This is the 'raw' log-likelihood function passed to the estimation routine. It is important that the user takes into account whether the optimization routine is a minimizer (e.g. 'ucminf') or a maximizer (e.g. 'maxlik').

estim_env

An estimation environment returned by prepare_estimation_environment

workers

A list of workers created using the parallel package

Value

A high precision numerical gradient function