Laplace Approximations Using Automatic Differentiation

Computes Laplace-approximate maximum likelihood for hierarchical and latent Gaussian models. A formula interface specifies observation densities (e.g. Gaussian, negative Binomial), fixed effects, and random terms (independent effects, smoothing terms). Customized response distributions and models for random effects can be specified through a low-level interface or by writing interoperable packages. Derivatives are computed using automatic differentiation with 'CppAD', and used in trust region optimization to find modes of random effects. Derivatives of the Laplace approximation of the log-likelihood are computed using third order contractions and is compatible with custom atomics. The approach follows Kristensen, Nielsen, Berg, Skaug, and Bell (2016) .


# adlaplace

Laplace approximations for hierarchical models using CppAD (via the
**RCppAD** R package) and trust-region optimization.

## Install

From [R-universe](https://eborgnine.r-universe.dev) (binaries when available):

```r
install.packages(
  c("RCppAD", "adlaplace"),
  repos = c("https://eborgnine.r-universe.dev", "https://cloud.r-project.org")
)
```

## Vignettes

Built HTML vignettes (from CI):

- [Index](https://eborgnine.github.io/adlaplace/)
- [Laplace Approximations with adlaplace](https://eborgnine.github.io/adlaplace/adlaplace/adlaplace.html)
- [Germany BYM example](https://eborgnine.github.io/adlaplace/adlaplace/germany.html)
- [GAMM examples](https://eborgnine.github.io/adlaplace/adlaplace/gamm.html)
- [Case-crossover models with adlaplace](https://eborgnine.github.io/adlaplace/adlaplace/casecrossover.html)
- [Bayesian Bernoulli mixed model for the bacteria data](https://eborgnine.github.io/adlaplace/adlaplace/bacteria.html)
- [Equivalence to Conditional Gamma-Poisson Model](https://eborgnine.github.io/adlaplace/adlaplace/dirichlet_multinom.html)

## Dependencies

- **RCppAD** — `Imports` + `LinkingTo`; provides `#include <cppad/cppad.hpp>`.
  Install RCppAD before building this package. No system CppAD /
  `libcppad_lib` is required.
- **OpenMP** — recommended (`SystemRequirements: OpenMP`); configure enables
  it when available. Without OpenMP, install still works and `num_threads`
  is ignored.

## Package layout

| Layer | R | C++ |
| ------- | --- | ----- |
| Model (formula, S4 terms) | `effects.R`, `term_data_setup.R`, term `*.R` | — |
| Laplace (AD handle, profile likelihood) | `ad_pack.R`, `density_data.R`, `log_lik.R`, … | `inner_opt`, … |
| Engine (eval, optimizer) | `R/RcppExports.R` | `src/`, `src/include/adlaplace/` |

Public headers for backend packages live in `inst/include/adlaplace/`.
Private engine headers are in `src/include/adlaplace/`.

Backend packages (e.g. `adlaplaceExample`, `adlaplaceFem`, `hpolcc`) should
also `LinkingTo` / `Imports` **RCppAD**, and typically link against the
installed `adlaplace` shared library.

See the monorepo root [`README.md`](../README.md) for install order.

## CRAN notes

Vignettes are abbreviated during `R CMD check` on CRAN (`NOT_CRAN` unset) to
keep rebuild time under 10 minutes; full HTML is built in CI and published at
<https://eborgnine.github.io/adlaplace/>.
No `-Wno-*` flags are used in `PKG_CXXFLAGS`. The Windows `-Wuninitialized`
report was a real uninitialized read in CppAD's `sparse_rc` move constructor,
fixed in RCppAD (>= 1.20260000.0-1).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("adlaplace")

0.7.4 by Patrick Brown, 10 hours ago


Browse source code at https://github.com/cran/adlaplace


Authors: Patrick Brown [aut, cre, cph]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports Matrix, Rcpp, methods, data.table, stats, graphics, RCppAD

Suggests knitr, rmarkdown, trustOptim, testthat, mvQuad, mgcv, MASS, nlme, sn, terra, GET, WoodburyMatrix, extraDistr, RSpectra, aghq, numDeriv

Linking to Rcpp, RcppEigen, trustOptim, Matrix, RCppAD

System requirements: OpenMP


See at CRAN