Learn R Programming

bhm (version 1.19)

numHessian: Calculate Hessian or Information Matrix

Description

Calculate a numerical approximation to the Hessian matrix of a function at a parameter value.

Usage

numHessian(func, theta, h = 0.0001, method=c("fast", "easy"), ...)

Value

An p by p matrix of the Hessian of the function calculated at the point theta. If the func is a log likelihood function, then the negative of the p by p matrix is the information matrix.

Arguments

func

a function for which the first (vector) argument is used as a parameter vector.

theta

the parameter vector first argument to func.

h

the step used in the numerical calculation.

method

one of "fast" or "easy" indicating the method to use for the approximation.

...

additional named or unmaned arguments to be passed to func.

Details

The function numHessian calculates an numerical approximation to the p by p second order derivative of a scalar real valued function with p-vector argument theta. This function can be used to check if the information matrix of a log likelihood is correct or not.

See Also

numScore

Examples

Run this code
  g = function(x, a) (x[1]+2*x[2]^3 - x[3]^3 + a*sin(x[1]*x[2]))
  x0= c(1, 2, 3)
  numHessian(g, theta = x0, a = 9)
  numHessian(g, theta = x0, method = 'easy', a = 9)

Run the code above in your browser using DataLab