Learn R Programming

CDM (version 4.8-0)

numerical_Hessian: Numerical Computation of the Hessian Matrix

Description

Computes numerically the Hessian matrix of a given function.

Usage

numerical_Hessian(par, FUN, h = 1e-05, gradient = FALSE)

Arguments

par
Parameter vector
FUN
Specified function with argument vector x
h
Numerical differentiation parameter. Can be also a vector.
gradient
Logical indicating whether the gradient should be calculated. If it is FALSE, then the Hessian matrix is computed.

Value

  • Gradient vector or Hessian matrix

See Also

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

Examples

Run this code
#############################################################################
# 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)

#--- compute gradient 
numerical_Hessian( par = par , FUN = f , gradient=TRUE )
mirt::numerical_deriv(par = par , f = f, gradient=TRUE)

#--- compute Hessian matrix
numerical_Hessian( par = par , FUN = f )
mirt::numerical_deriv(par = par , f = f, gradient=FALSE)
numerical_Hessian( par = par , FUN = f , h = 1E-4 )

Run the code above in your browser using DataLab