Learn R Programming

apollo (version 0.3.4)

apollo_insertFunc: Modifies function to make it compatible with analytic gradients

Description

Takes a likelihood function and inserts function () before key elements to allow for analytic gradient calculation

Usage

apollo_insertFunc(f, like = TRUE, randCoeff = FALSE, lcPars = FALSE)

Value

Function f but with relevant expressions turned into function definitions.

Arguments

f

Function. Expressions inside it will be turned into functions. Usually apollo_probabilities or apollo_randCoeff.

like

Logical. Must be TRUE if f is apollo_probabilities. FALSE otherwise.

randCoeff

Logical. Must be TRUE if f is apollo_randCoeff. FALSE otherwise.

lcPars

Logical. Must be TRUE if f is apollo_lcPars. FALSE otherwise.

Details

It modifies the definition of the following models.

  • apollo_mnl: Turns all elements inside mnl_settings$V into functions.

  • apollo_ol: Turns ol_settings$V and all elements inside ol_settings$tau into functions.

  • apollo_op: Turns op_settings$V and all elements inside op_settings$tau into functions.

  • apollo_normalDensity: Turns normalDensity_settings$xNormal, normalDensity_settings$mu and normalDensity_settings$sigma into functions.

It can only track a maximum of 3 levels of depth in definitions. For example: V <- list() V[["A"]] <- b1*x1A + b2*x2A V[["B"]] <- b1*x1B + b2*x2B mnl_settings1 <- list(alternatives=c("A", "B"), V = V, choiceVar= Y, avail = 1, componentName="MNL1") P[["MNL1"]] <- apollo_mnl(mnl_settings1, functionality) But it may not be able to deal with the following: VA <- b1*x1A + b2*x2A V <- list() V[["A"]] <- VA V[["B"]] <- b1*x1B + b2*x2B mnl_settings1 <- list(alternatives=c("A", "B"), V = V, choiceVar= Y, avail = 1, componentName="MNL1") P[["MNL1"]] <- apollo_mnl(mnl_settings1, functionality) But that might be enough given how apollo_dVdB works.