summary.marginallaplace {aghq}R Documentation

Summary statistics for models using marginal Laplace approximations

Description

The summary.marginallaplace calls summary.aghq, but also computes summary statistics of the random effects, by drawing from their approximate posterior using aghq::sample_marginal with the specified number of samples.

Usage

## S3 method for class 'marginallaplace'
summary(object, M = 1000, max_print = 30, ...)

Arguments

object

Object inheriting from both classes aghq and marginallaplace, for example as returned by aghq::marginal_laplace or aghq::marginal_laplace_tmb.

M

Number of samples to use to compute summary statistics of the random effects. Default 1000. Lower runs faster, higher is more accurate.

max_print

Sometimes there are a lot of random effects. If there are more random effects than max_print, the random effects aren't summarized, and a note is printed to this effect. Default 30.

...

not used.

Value

A list containing an object of class aghqsummary (see summary.aghq).

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(), optimize_theta(), plot.aghq(), print.aghqsummary(), print.aghq(), print.laplacesummary(), print.laplace(), print.marginallaplacesummary(), summary.aghq(), summary.laplace()

Examples

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))
objfunc2dmarg <- function(W,theta) objfunc2d(c(W,theta))
objfunc2dmarggr <- function(W,theta) {
  fn <- function(W) objfunc2dmarg(W,theta)
  numDeriv::grad(fn,W)
}
objfunc2dmarghe <- function(W,theta) {
  fn <- function(W) objfunc2dmarg(W,theta)
  numDeriv::hessian(fn,W)
}

funlist2dmarg <- list(
  fn = objfunc2dmarg,
  gr = objfunc2dmarggr,
  he = objfunc2dmarghe
)

themarginallaplace <- aghq::marginal_laplace(funlist2dmarg,3,list(W = 0,theta = 0))
summary(themarginallaplace)

[Package aghq version 0.4.1 Index]