Skip to contents

Finds the posterior distribution of the hyperparameters \(\boldsymbol{\theta}\), latent field \(\mathbf{x}\), mixing variables \(\mathbf{V}\), and non-Gaussianity parameters \(\eta\) of latent non-Gaussian models (LnGMs) using INLA and variational Bayes approximations. These LnGMs are flexible extensions of latent Gaussian models (LGMs). The LnGMs are specified either through an INLA object (fit) that fits an LGM or through a list of configurations (manual.configs). Run `devtools::build_vignettes("ngvb")` and `vignette("ngvb")` to see several use cases.

Usage

ngvb(
  fit = NULL,
  manual.configs = NULL,
  selection = NULL,
  alpha.eta = rep(1, length(selection)),
  n.sampling = 1000,
  d.sampling = FALSE,
  method = "SCVI",
  fast = FALSE,
  verbose = TRUE,
  history = FALSE,
  V.init = NULL,
  eta.init = NULL,
  iter = 10,
  stop.rel.change = NULL
)

Arguments

fit

The inla object that fits the LGM.

manual.configs

Not necessary if fit is provided. List containing:

  • inla.fit.V Function that receives as input the mixing variables \(\mathbf{V}\) and the output is an inla object that fits the LGM \((\mathbf{x},\boldsymbol{\theta} | \mathbf{V}, \mathbf{y})\).

  • Dfunc Function that receives as input the hyperparameter vector \(\boldsymbol{\theta}\) in internal scale and the output is \(\mathbf{D}(\boldsymbol{\theta})\), where \(\mathbf{D}\) is the dependency matrix that specifies the non-Gaussian latent field. If there is more than one latent component to be extended to non-Gaussianity, this should be a list of functions \(\mathbf{D}_i(\boldsymbol{\theta})\), where \(\mathbf{D}_i(\boldsymbol{\theta})\) is the dependency matrix that specifies component i.

  • h Predefined constant \(\mathbf{h}\) vector that contains the distance between locations or area of the basis functions. For models defined in discrete space this should be a vector of ones. If there is more than one latent component to be extended to non-Gaussianity, this should be a list of vectors \(\mathbf{h_i}\) where \(\mathbf{h_i}\) is the predefined constant vector of component i.

selection

List which specifies which model components of the LGM are to be extended to non-Gaussianity. Same syntax as the argument selection of the function inla.posterior.sample.

alpha.eta

Numeric. Rate parameter of the exponential prior of the non-Gaussianity parameter \(\alpha\). Should be a vector with the same dimension as the number of model components to extend.

n.sampling

Numeric. Number of samples uses in several sampling task throughout the SVI or SCVI algorithm.

d.sampling

Logical. If TRUE the expectations \(d_i = E([\mathbf{D}\mathbf{x}]_i^2)\) are computed by sampling (slower). If FALSE (default) uses the mixture Gaussian approximation of \(\mathbf{x}\) obtained in INLA.

method

Character. Should be "SCVI", "SVI", or "Gibbs" if the algorithm should be the structural and collapsed variational inference algorithm (faster) or the structural variational inference algorithm (slower), or a Gibbs sampler (even slower), respectively.

fast

Logical. If TRUE then INLA will be run with the empirical Bayes mode and several control variables will be turned off to improve the speed of the algorithm.

verbose

Logical. If TRUE print the posterior mean of \(\eta\) and plot the posterior mean of \(\mathbf{V}\) at each iteration.

history

Logical. If TRUE save LGM inla object of each iteration. If FALSE only save the LGM inla object of the last iteration.

V.init

List of numeric vectors. Initial values for \(\mathbf{V}\). By default \(\mathbf{V}=\mathbf{h}\).

eta.init

Numeric vector. Initial values of \(\eta\). By default eta.init = 0.5.

iter

Integer. Maximum number of iterations.

stop.rel.change

Numeric. Stop the algorithm when the relative change in the posterior mean of \(\eta\) is smaller than stop.rel.change.

Value

An S4 object containing the outputs. Slots are accessed with @. These are:

  • history List containing summaries and inla objects (if history = TRUE) of each iteration (except the last one).

  • LGM inla object containing summaries and marginals of the latent field \(\mathbf{x}\) and hyperparameters \(\boldsymbol{\theta}\) of the last iteration.

  • summary.mixing Data frame containing summaries of the mixing variables \(\mathbf{V}\).

  • summary.ng Data frame containing summaries of the non-Gaussianiy parameters \(\eta\).

  • configs List containing the LnGM model specifications

Examples

if (FALSE) {
 #Here we fit an RW1 latent process to the jumpts time series
 plot(jumpts)

 #Fit LGM with INLA
 LGM     <- inla(y ~ -1 + f(x,  model = "rw1"),
                 data = jumpts)

 #Check adequacy of latent Gaussianity assumption
 check.list <- ng.check(fit = LGM)

 #Fit LnGM with ngvb
 LnGM <- ngvb(fit = LGM)

 #Available methods
 summary(LnGM)
 print(LnGM)
 plot(LnGM)
 fitted(LnGM)
 samples <- simulate(LnGM)
 }