Last data update: 2014.03.03

R: Calculate Two-Sided Hessian Approximation
tsHessianR Documentation

Calculate Two-Sided Hessian Approximation

Description

Calculates an approximation to the Hessian of a function. Used for obtaining an approximation to the information matrix for maximum likelihood estimation.

Usage

tsHessian(param, fun, ...)

Arguments

param

Numeric. The Hessian is to be evaluated at this point.

fun

A function of the parameters specified by param, and possibly other parameters.

...

Values of other parameters of the function fun if required.

Details

As a typical statistical application, the function fun is the log-likelihood function, param specifies the maximum likelihood estimates of the parameters of the distribution, and the data constitutes the other parameter values required for determination of the log-likelihood function.

Value

The approximate Hessian matrix of the function fun where differentiation is with respect to the vector of parameters param at the point given by the vector param.

Note

This code was borrowed from the fBasics function, in the file ‘utils-hessian.R’ with slight modification. This was in turn borrowed from Kevin Sheppard's Matlab garch toolbox as implemented by Alexios Ghalanos in his rgarch package.

Author(s)

David Scott d.scott@auckland.ac.nz, Christine Yang Dong c.dong@auckland.ac.nz

See Also

hyperbHessian and summary.hyperbFit in GeneralizedHyperbolic.

Examples

### Consider Hessian of log(1 + x + 2y)
### Example from Lang: A Second Course in Calculus, p.74
fun <- function(param){
  x <- param[1]
  y <- param[2]
  return(log(1 + x + 2*y))
}

### True value of Hessian at (0,0)
trueHessian <- matrix( c(-1,-2,
                         -2,-4), byrow = 2, nrow = 2)
trueHessian

### Value from tsHessian
approxHessian <- tsHessian(c(0,0), fun = fun)
approxHessian
maxDiff <- max(abs(trueHessian - approxHessian))
### Should be approximately 0.045
maxDiff

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DistributionUtils)
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DistributionUtils/tsHessian.Rd_%03d_medium.png", width=480, height=480)
> ### Name: tsHessian
> ### Title: Calculate Two-Sided Hessian Approximation
> ### Aliases: tsHessian
> ### Keywords: math
> 
> ### ** Examples
> 
> ### Consider Hessian of log(1 + x + 2y)
> ### Example from Lang: A Second Course in Calculus, p.74
> fun <- function(param){
+   x <- param[1]
+   y <- param[2]
+   return(log(1 + x + 2*y))
+ }
> 
> ### True value of Hessian at (0,0)
> trueHessian <- matrix( c(-1,-2,
+                          -2,-4), byrow = 2, nrow = 2)
> trueHessian
     [,1] [,2]
[1,]   -1   -2
[2,]   -2   -4
> 
> ### Value from tsHessian
> approxHessian <- tsHessian(c(0,0), fun = fun)
> approxHessian
          [,1]      [,2]
[1,] -1.015139 -2.000000
[2,] -2.000000 -3.954584
> maxDiff <- max(abs(trueHessian - approxHessian))
> ### Should be approximately 0.045
> maxDiff
[1] 0.0454159
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>