numerical_Hessian {CDM} R Documentation

## Numerical Computation of the Hessian Matrix

### Description

Computes numerically the Hessian matrix of a given function for all coordinates (numerical_Hessian), for a selected direction (numerical_Hessian_partial) or the gradient of a multivariate function (numerical_gradient).

### Usage

numerical_Hessian(par, FUN, h=1e-05, gradient=FALSE,
hessian=TRUE, diag_only=FALSE, ...)

numerical_Hessian_partial(par, FUN, h=1e-05, coordinate=1, ... )

numerical_gradient(par, FUN, h=1E-5, ...)


### Arguments

 par Parameter vector FUN Specified function with argument vector x h Numerical differentiation parameter. Can be also a vector. The increment in the numerical approximation of the derivative is defined as h_i \max ( 1, \theta_i) where \theta_i denotes the ith parameter. gradient Logical indicating whether the gradient should be calculated. hessian Logical indicating whether the Hessian matrix should be calculated. diag_only Logical indicating whether only the diagonal of the hessian should be computed. ... Further arguments to be passed to FUN. coordinate Coordinate index for partial derivative

### Value

Gradient vector or Hessian matrix or a list of both elements

See the numDeriv package and the mirt::numerical_deriv function from the mirt package.

### Examples

#############################################################################
# EXAMPLE 1: Toy example for Hessian matrix
#############################################################################

# define function
f <- function(x){
3*x[1]^3 - 4*x[2]^2 - 5*x[1]*x[2] + 10 * x[1] * x[3]^2 + 6*x[2]*sqrt(x[3])
}
# define point for evaluating partial derivatives
par <- c(3,8,4)

CDM::numerical_Hessian( par=par, FUN=f, gradient=TRUE, hessian=FALSE)
## Not run: