| laplace_approximation | R Documentation |
Wrapper function to implement a Laplace approximation to the posterior. A
Laplace approximation is AGHQ with k = 1 quadrature points.
However, the returned
object is of a different class laplace, and a different summary
method is given for it. It is especially useful for high-dimensional problems where
the curse of dimensionality renders the use of k > 1 quadrature points
infeasible. The summary method reflects the fact that the user may
be using this for a high-dimensional problem, and no plot method is given,
because there isn't anything
interesting to plot.
laplace_approximation(
ff,
startingvalue,
optresults = NULL,
control = default_control(),
...
)
ff |
A list with three elements:
The user may wish to use |
startingvalue |
Value to start the optimization. |
optresults |
Optional. A list of the results of the optimization of the log
posterior, formatted according to the output of |
control |
A list with elements
|
... |
Additional arguments to be passed to |
An object of class laplace with summary and plot methods. This
is simply a list with elements lognormconst containing the log of the
approximate normalizing constant, and optresults containing the optimization
results formatted the same way as optimize_theta and aghq.
Other quadrature:
aghq(),
get_hessian(),
get_log_normconst(),
get_mode(),
get_nodesandweights(),
get_numquadpoints(),
get_opt_results(),
get_param_dim(),
marginal_laplace_tmb(),
marginal_laplace(),
nested_quadrature(),
normalize_logpost(),
optimize_theta(),
plot.aghq(),
print.aghqsummary(),
print.aghq(),
print.laplacesummary(),
print.laplace(),
print.marginallaplacesummary(),
summary.aghq(),
summary.laplace(),
summary.marginallaplace()
logfteta2d <- function(eta,y) {
# eta is now (eta1,eta2)
# y is now (y1,y2)
n <- length(y)
n1 <- ceiling(n/2)
n2 <- floor(n/2)
y1 <- y[1:n1]
y2 <- y[(n1+1):(n1+n2)]
eta1 <- eta[1]
eta2 <- eta[2]
sum(y1) * eta1 - (length(y1) + 1) * exp(eta1) - sum(lgamma(y1+1)) + eta1 +
sum(y2) * eta2 - (length(y2) + 1) * exp(eta2) - sum(lgamma(y2+1)) + eta2
}
set.seed(84343124)
n1 <- 5
n2 <- 5
n <- n1+n2
y1 <- rpois(n1,5)
y2 <- rpois(n2,5)
objfunc2d <- function(x) logfteta2d(x,c(y1,y2))
funlist2d <- list(
fn = objfunc2d,
gr = function(x) numDeriv::grad(objfunc2d,x),
he = function(x) numDeriv::hessian(objfunc2d,x)
)
thequadrature <- aghq(funlist2d,3,c(0,0))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.