Learn R Programming

docopulae (version 0.2.1)

DerivLogf: Build Derivative Function for Log f

Description

Builds a function that evaluates to the first/second derivative of log(f) with respect to a predefined set of variables/variable combinations.

Usage

DerivLogf(f, names, map = NULL, yMap = NULL, thetaMap = NULL)

Deriv2Logf(f, names, map = NULL, yMap = NULL, thetaMap = NULL)

Arguments

f
an expression, a joint probability density.
names
a character vector of variable names.
map
a named list of character strings defining left assignments (a="b" => a <- b).
yMap
like map with a=b resolving to a <- y[b].
thetaMap
like map with a=b resolving to a <- theta[[b]].

Value

  • DerivLogf returns function(y, theta, i, ...) where theta is a list of parameters. It evaluates to the first derivative of log(f) with respect to variable i. Additionally the attribute "d" contains the list of sub functions.

    Deriv2Logf returns function(y, theta, i, j, ...) where theta is a list of parameters. It evaluates to the second derivative of log(f) with respect to the variables i and j. Additionally the attribute "d2" contains the list of sub functions.

Details

While numDerivLogf relies on numDeriv and therefore uses finite differences to evaluate the derivatives, DerivLogf utilizes Deriv to build sub functions for each variable in names. The same is true for Deriv2Logf.

Deriv won't recognize components or parameters accessed by [, [[ or $ as variables (e.g. theta[["beta1"]]). Therefore it's necessary to specify mappings from y and theta to the variables in f.

See Also

Deriv in package Deriv, buildf, numDerivLogf, fisherI

Examples

Run this code
## see examples for param
## mind the gain regarding runtime compared to numDeriv

Run the code above in your browser using DataLab