View source: R/01-optimization.R
| optimize_theta | R Documentation |
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.
optimize_theta(ff, startingvalue, control = default_control(), ...)
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 |
A list with elements
ff: the function list that was provided
mode: the mode of the log posterior
hessian: the hessian of the log posterior at the mode
convergence: specific to the optimizer used, a message indicating whether it converged
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()
# 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.