| calc_gradient {uGMAR} | R Documentation | 
Calculate gradient or Hessian matrix
Description
calc_gradient or calc_hessian calculates the gradient or Hessian matrix
of the given function at the given point using central difference numerical approximation.
get_gradient (and get_foc) or get_hessian calculates the gradient or Hessian matrix of the
log-likelihood function at the parameter values of a class 'gsmar' object.
get_soc returns eigenvalues of the Hessian matrix.
Usage
calc_gradient(x, fn, h = 6e-06, varying_h = NULL, ...)
calc_hessian(x, fn, h = 6e-06, varying_h = NULL, ...)
get_gradient(gsmar, custom_h = NULL)
get_foc(gsmar, custom_h = NULL)
get_hessian(gsmar, custom_h = NULL)
get_soc(gsmar, custom_h = NULL)
Arguments
| x | a numeric vector specifying the point at which the gradient or Hessian should be evaluated. | 
| fn | a function that takes in the argument  | 
| h | the difference used to approximate the derivatives. | 
| varying_h | a numeric vector with the same length as  | 
| ... | other arguments passed to  | 
| gsmar | a class 'gsmar' object, typically generated by  | 
| custom_h | same as  | 
Details
In particular, the functions get_foc and get_soc can be used to check whether
the found estimates denote a (local) maximum point, a saddle point, or something else.
Value
The gradient functions return numerical approximation of the gradient, and the Hessian functions return
numerical approximation of the Hessian. get_soc returns eigenvalues of the Hessian matrix, get_foc
is the same as get_gradient but named conveniently.
Warning
No argument checks!
See Also
Examples
# Simple function
foo <- function(x) x^2 + x
calc_gradient(x=1, fn=foo)
calc_gradient(x=-0.5, fn=foo)
calc_hessian(x=2, fn=foo)
# More complicated function
foo <- function(x, a, b) a*x[1]^2 - b*x[2]^2
calc_gradient(x=c(1, 2), fn=foo, a=0.3, b=0.1)
calc_hessian(x=c(1, 2), fn=foo, a=0.3, b=0.1)
# GMAR model
params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63)
gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR")
get_gradient(gmar12)
get_foc(gmar12)
get_hessian(gmar12)
get_soc(gmar12)