Skip to contents

Integrates a likelihood against a Gaussian distribution of the latent value, \(\int p(y_* \mid f_*) N(f_* \mid \mu, \sigma^2) df_*\): the predictive distribution of a new response given the posterior of the latent function at its input.

Usage

likelihood_predictive(
  likelihood,
  mean,
  variance,
  observed = NULL,
  exposure = NULL,
  quadrature_order = 40L
)

Arguments

likelihood

A likelihood specification (gp_likelihoods).

mean, variance

Mean and variance of the latent value, one per prediction.

observed

Optional responses whose log predictive density is returned.

exposure

Optional positive exposure for Poisson likelihoods: one value or one per response.

quadrature_order

Number of Gauss-Hermite nodes for integrals without a closed form.

Value

A list with the predictive mean and variance of \(y_*\), probability, \(\Pr(y_* = 1)\), for Bernoulli likelihoods, and log_density of observed when it is given.

Details

Closed forms are used where they exist: the Gaussian likelihood adds its variance, the probit link gives \(\Pr(y_* = 1) = \Phi(\mu / \sqrt{1 + \sigma^2})\), and the Poisson mean and variance are those of a Poisson with a lognormal rate, \(E e^{\mu + \sigma^2 / 2}\) and \(\mathrm{E}[y_*] + E^2 e^{2\mu + \sigma^2}(e^{\sigma^2} - 1)\). The logistic probability and the Poisson and logistic predictive densities use adaptive Gauss-Hermite quadrature (Liu and Pierce, 1994). With \(\hat f\) the mode of \(\psi(f) = \log p(y \mid f) + \log N(f \mid \mu, \sigma^2)\), found by Newton's method, and \(s = (-\psi''(\hat f))^{-1/2}\), $$\int p(y \mid f) N(f \mid \mu, \sigma^2) df \approx \sqrt{2} s \sum_j w_j e^{t_j^2} e^{\psi(\hat f + \sqrt{2} s t_j)},$$ computed in logs. Centring the nodes on the integrand rather than on \(\mu\) matters when the observation lies in the tail of the latent distribution, as for large counts.

Quadrature converges more slowly as \(\sigma^2\) grows, because the logistic function has poles at \(\pm i\pi\). With the default 40 nodes, the logistic probability is accurate to \(10^{-10}\) for \(\sigma^2\) up to 3; increase quadrature_order for wider latent distributions.

Stability

Experimental: this interface may change in a minor release, and every change is listed in NEWS. See gaussianprocesses-package for the policy.

References

Liu, Q. and Pierce, D. A. (1994). A note on Gauss-Hermite quadrature. Biometrika, 81(3), 624–629.

Examples

likelihood_predictive(bernoulli_likelihood("probit"), mean = c(-1, 0, 2),
  variance = c(0.5, 1, 4))$probability
#> [1] 0.2071081 0.5000000 0.8144533

likelihood_predictive(poisson_likelihood(), mean = log(3), variance = 0.2,
  observed = 4, exposure = 2)
#> $mean
#> [1] 6.631026
#> 
#> $variance
#> [1] 16.36622
#> 
#> $log_density
#> [1] -2.168429
#>