Learn R Programming

apollo (version 0.3.2)

apollo_makeGrad: Creates gradient function.

Description

Creates gradient function from the likelihood function apollo_probabilities provided by the user. Returns NULL if the creation of gradient function fails.

Usage

apollo_makeGrad(
  apollo_beta,
  apollo_fixed,
  apollo_logLike,
  validateGrad = FALSE
)

Value

apollo_gradient function. It receives the following arguments

  • b Numeric vector of _variable_ parameters (i.e. must not include fixed parameters).

  • countIter Not used. Included only to mirror inputs of apollo_logLike.

  • getNIter Not used. Included only to mirror inputs of apollo_logLike.

  • sumLL Not used. Included only to mirror inputs of apollo_logLike.

  • writeIter Not used. Included only to mirror inputs of apollo_logLike.

If the creation of the gradient function fails, then it returns NULL.

Arguments

apollo_beta

Named numeric vector. Names and values for parameters.

apollo_fixed

Character vector. Names (as defined in apollo_beta) of parameters whose value should not change during estimation.

apollo_logLike

Function to calculate the log-likelihood of the model, as created by apollo_makeLogLike If provided, the value of the analytical gradient will be compared to the value of the numerical gradient as calculated using apollo_logLike and the numDeriv package. If the difference between the two is bigger than 1 that the analytical gradient is wrong and NULL will be returned.

validateGrad

Logical. If TRUE, it compares the value of the analytical gradient evaluated at apollo_beta against the numeric gradient (using numDeriv) at the same value. If the difference is bigger than 1 return NULL.

Details

Internal use only. Called by apollo_estimate before estimation. The returned function can be single-threaded or multi-threaded based on the model options.