optimize_theta {aghq} | R Documentation |
Obtain function information necessary for performing quadrature
Description
This function computes the two pieces of information needed about
the log posterior to do adaptive quadrature: the mode, and the hessian at the mode.
It is designed for use within aghq::aghq
, but is exported in case users
need to debug the optimization process and documented in case users want to
write their own optimizations.
Usage
optimize_theta(ff, startingvalue, control = default_control(), ...)
Arguments
ff |
A list with three elements:
The user may wish to use |
startingvalue |
Value to start the optimization. |
control |
A list with elements
|
... |
Additional arguments to be passed to |
Value
A list with elements
ff
: the function list that was providedmode
: the mode of the log posteriorhessian
: the hessian of the log posterior at the modeconvergence
: specific to the optimizer used, a message indicating whether it converged
See Also
Other quadrature:
aghq()
,
get_hessian()
,
get_log_normconst()
,
get_mode()
,
get_nodesandweights()
,
get_numquadpoints()
,
get_opt_results()
,
get_param_dim()
,
laplace_approximation()
,
marginal_laplace_tmb()
,
marginal_laplace()
,
nested_quadrature()
,
normalize_logpost()
,
plot.aghq()
,
print.aghqsummary()
,
print.aghq()
,
print.laplacesummary()
,
print.laplace()
,
print.marginallaplacesummary()
,
summary.aghq()
,
summary.laplace()
,
summary.marginallaplace()
Examples
# Poisson/Exponential example
logfteta <- function(eta,y) {
sum(y) * eta - (length(y) + 1) * exp(eta) - sum(lgamma(y+1)) + eta
}
y <- rpois(10,5) # Mode should be (sum(y) + 1) / (length(y) + 1)
objfunc <- function(x) logfteta(x,y)
funlist <- list(
fn = objfunc,
gr = function(x) numDeriv::grad(objfunc,x),
he = function(x) numDeriv::hessian(objfunc,x)
)
optimize_theta(funlist,1.5)
optimize_theta(funlist,1.5,control = default_control(method = "trust"))
optimize_theta(funlist,1.5,control = default_control(method = "BFGS"))