TABLE OF CONTENTS


initRoutine/numHess.par [ Functions ]

NAME

    numHess.par  --- compute a numerical Hessian for the parametric component

FUNCTION

Since there are so many parametric component specifications and parametrizations, it is easiest to compute the Hessian of the parameters numerically. Given a set of parameters and a likelihood function, this routine computes the Hessian of the function at the given parameters.

The method used is basic finite differences

SYNOPSIS

959 numHess.par <- function(param.par, fun, eps = 1e-5, ...)

INPUTS

    param.par  parameters of the parametric component
    fun        likelihood function for the parametric component
    eps        precision to use for numerical Hessian

OUTPUTS

SOURCE

962 {
963     # Utility function to compute numerical derivatives
964     numDer.par <- function(param.par, fun, eps = 1e-5, ...)
965     {        
966         lik1 <- fun(param.par, ...)
967         nd <- rep(0, length(param.par))
968         #   take finite differences along the set of parameters
969         for(i in 1:length(nd))
970         {
971             param.par2 <- param.par
972             param.par2[i] <- param.par2[i] + eps
973             lik2 <- fun(param.par2, ...)
974             nd[i] <- (lik2 - lik1) / eps
975         }
976         return(nd)
977     }
978     # allocate storage for numerical Hessian
979     nh <- matrix(0, length(param.par), length(param.par))
980     #   base gradient
981     gr1 <- numDer.par(param.par, fun, eps, ...)
982     #   compute gradients by finite differences
983     for(i in 1:length(param.par))
984     {
985         param.par2 <- param.par
986         param.par2[i] <- param.par2[i] + eps
987         gr2 <- numDer.par(param.par2, fun, eps, ...)
988         nh[i, ] <- (gr2 - gr1) / eps
989     }
990     return(nh)
991 }