optimHess
Numerically Estimate Hessian Matrix

### Description

Given either a scalar-valued function or its gradient function, numerically estimates the matrix of its second derivatives.

### Usage

    optimHess(par, fn, gr = NULL, ..., control = list())

### Arguments

par | a numeric vector than can be used as the first argument to fn. The Hessian matrix is estimated at this point.
fn | a numeric scalar-valued function of at least one argument. Its Hessian (matrix of second derivatives with respect of all elements of its first argument) is estimated. Exactly one of fn and gr should be given (if gr is supplied, then fn is ignored).
gr | a function of at least one argument that returns a vector the same length as its first argument. This is taken to be the gradient (the vector of first derivatives with respect to all elements of its first argument) of fn and the matrix of second derivatives is estimated from it.
... | any other arguments are passed to fn or gr each time they are evaluated.
control | a list containing components named "parscale", "ndeps", or "fnscale". "parscale" and "ndeps" should be numeric vectors the same length as "par". If fn is given, then its gradient is estimated by evaluating it at replace(par, i, par[i]+control$ndeps[i]*control$parscale[i]) and replace(par, i, par[i]-control$ndeps[i]*control$parscale[i]) and computing the corresponding divided differences for i in seq_along(par). Then the Hessian is estimated by evaluating the gradient after perturbing par[i] by plus or minus control$ndeps[i]. The raw estimates for the i,j and j,i elements of the Hessian are replaced by their average. Currently control$fnscale is ignored.

Value
returns the estimated matrix of second derivatives.
See Also
numericDeriv, deriv
Examples

    optimHess(c(a=1,b=5,c=6), fn=function(x, alpha)prod(x-alpha), alpha=c(2, 3, 4))
    optimHess(c(a=1,b=5,c=6),
       gr=function(x,alpha)vapply(seq_along(x), function(i)prod(x[-i]-alpha[-i]), 0),
       alpha=c(2, 3, 4))

Package stats version 6.1.5-18
Package Index