Learn R Programming

SMPracticals (version 1.4-3.1)

ihess: Inverse Hessian

Description

Inverse Hessian matrix, useful for obtaining standard errors

Usage

ihess(f, x, ep = 1e-04, ...)

Value

Matrix of dimension dim(x) times dim(x), containing inverse Hessian matrix of f at x.

Arguments

f

Usually a negative log likelihood

x

Usually maximum likelihood estimates for f

ep

Step length used to compute numerical second derivatives

...

Extra arguments for f, if any

Author

Anthony Davison

References

Based on code written by Stuart Coles of Padova University

Examples

Run this code
# ML fit of t distribution
nlogL <- function(x, data) # negative log likelihood
{ mu <- x[1]
  sig <- x[2]
  df <- x[3]
  -sum(log( dt((data-mu)/sig, df=df)/sig )) }
y <- rt(n=100, df=10) # generate t data
# this is Splus code.....so remove the #'s for it to work in R
# fit <- nlminb(c(1,1,4), nlogL, upper=c(Inf,Inf,Inf), lower=c(-Inf,0,0),
#               data=y)
# fit$parameters # maximum likelihood estimates
# J <- ihess(nlogL, fit$parameters, data=y)
#  sqrt(diag(J)) # standard errors based on observed information
# 
# In this example the standard error can be a bad measure of
# uncertainty for the df.

Run the code above in your browser using DataLab