apollo_insertFunc {apollo} | R Documentation |
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)
Arguments
f |
Function. Expressions inside it will be turned into functions. Usually |
like |
Logical. Must be TRUE if |
randCoeff |
Logical. Must be TRUE if |
lcPars |
Logical. Must be TRUE if |
Details
It modifies the definition of the following models.
-
apollo_mnl
: Turns all elements insidemnl_settings$V
into functions. -
apollo_ol
: Turnsol_settings$V
and all elements insideol_settings$tau
into functions. -
apollo_op
: Turnsop_settings$V
and all elements insideop_settings$tau
into functions. -
apollo_normalDensity
: TurnsnormalDensity_settings$xNormal
,normalDensity_settings$mu
andnormalDensity_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.
Value
Function f
but with relevant expressions turned into function definitions.