Learn R Programming

maxLik (version 0.8-0)

estfun.maxLik: Extract Gradients Evaluated at each Observation

Description

Extract the gradients of the log-likelihood function evaluated at each observation (Empirical Estimating Function, see estfun).

Usage

## S3 method for class 'maxLik':
estfun( x, ... )

Arguments

x
an object of class maxLik.
...
further arguments (currently ignored).

Value

  • Matrix of gradients of the log-likelihood function at the estimated parameter value evaluated at each observation

Warnings

The sandwich package must be loaded before this method can be used.

This method works only if maxLik was called with argument grad equal to a gradient function or (if no gradient function is specified) argument logLik equal to a log-likelihood function that return the gradients or log-likelihood values, respectively, for each observation.

See Also

estfun, maxLik.

Examples

Run this code
## ML estimation of exponential duration model:
t <- rexp(100, 2)
loglik <- function(theta) log(theta) - theta*t

## Estimate with numeric gradient and hessian
a <- maxLik(loglik, start=1 )

# Extract the gradients evaluated at each observation
library( sandwich )
estfun( a )

## Estimate with analytic gradient
gradlik <- function(theta) 1/theta - t
b <- maxLik(loglik, gradlik, start=1)
estfun( b )
all.equal( c( estfun( b ) ), gradlik( coef( b ) ) )

Run the code above in your browser using DataLab