Last chance! 50% off unlimited learning
Sale ends in
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
or get_hessian
calculates the gradient or Hessian matrix of the
log-likelihood function at the parameter estimates of a class 'gmvar'
object. get_soc
returns eigenvalues of the Hessian matrix, and get_foc
is the same as get_gradient
but named conveniently.
calc_gradient(x, fn, h = 6e-06, ...)calc_hessian(x, fn, h = 6e-06, ...)
get_gradient(gmvar, h = 6e-06)
get_hessian(gmvar, h = 6e-06)
get_soc(gmvar, h = 6e-06)
get_foc(gmvar, h = 6e-06)
a numeric vector specifying the point where the gradient or Hessian should be calculated.
a function that takes in argument x
as the first argument.
difference used to approximate the derivatives.
other arguments passed to fn
an object of class 'gmvar'
created with fitGMVAR
or GMVAR
.
Gradient functions return numerical approximation of the gradient and Hessian functions return
numerical approximation of the Hessian. get_soc
returns eigenvalues of the Hessian matrix.
No argument checks!
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. Note that
profile log-likelihood functions can be conveniently plotted with the function profile_logliks
.
# NOT RUN {
# Simple function
foo <- function(x) x^2 + x
calc_gradient(x=1, fn=foo)
calc_gradient(x=-0.5, 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)
# }
# NOT RUN {
# GMVAR(1,2), d=2 model:
params12 <- c(0.55, 0.112, 0.344, 0.055, -0.009, 0.718, 0.319, 0.005,
0.03, 0.619, 0.173, 0.255, 0.017, -0.136, 0.858, 1.185, -0.012,
0.136, 0.674)
mod12 <- GMVAR(gdpdef, p=1, M=2, params=params12)
get_gradient(mod12)
get_hessian(mod12)
get_soc(mod12)
# }
Run the code above in your browser using DataLab