dmnorm_NN_GP: Compute Nearest-Neighbor Gaussian Process (NNGP) log-density

dmnorm_NN_GPR Documentation

Compute Nearest-Neighbor Gaussian Process (NNGP) log-density

Description

Evaluates the log-density of a multivariate normal distribution under the Nearest-Neighbor Gaussian Process (NNGP) approximation as defined by Data et al 2016.

Usage

dmnorm_NN_GP(x, mu, AD, neighbors.id, log = 1)

Arguments

x

Numeric vector (length M). Observed spatial process values.

mu

Numeric vector (length M). Mean vector.

AD

Numeric matrix (M \times (k+1)). Output from computeAD, where:

  • Columns 1:k contain regression coefficients A_i

  • Column k+1 contains conditional variances D_i

neighbors.id

Integer matrix (M \times k). Neighbor indices defining the conditioning sets N(i). Output from computeNeighbors

log

Logical/Integer. If TRUE (or 1), returns the log-density; otherwise returns the density.

Details

The NNGP approximation factorizes the joint density as:

p(\mathbf{x}) \approx \prod_{i=1}^M p(x_i \mid x_{N(i)})

leading to the log-density:

-\frac{1}{2} \left( N \log(2\pi) + \sum_i \log D_i + Q \right)

where:

  • D_i are conditional variances

  • Q is the quadratic form computed by computeQF

The quadratic form corresponds to:

Q = \sum_{i=1}^M \frac{(x_i - \mu_i - A_i(x_{N(i)} - \mu_{N(i)}))^2}{D_i}

This formulation avoids constructing the sparse covariance matrix, enabling scalable likelihood evaluation for large spatial datasets.

Value

A scalar value corresponding to the (log-)density.

Author(s)

Fabian Ketwaroo

References

Datta, A., Banerjee, S., Finley, A.O. and Gelfand, A.E., 2016. Hierarchical nearest-neighbor Gaussian process models for large geostatistical datasets. *Journal of the American Statistical Association*, 111(514), 800-812. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2015.1044091")}

Examples

M <- 2000      # number of spatial locations
coords <- matrix(runif(2*M), ncol = 2)
Nk <- 15       # number of neighbors
res <- computeNeighbors(coords, k = Nk)
AD <- computeAD(edist = res$edist_sorted,
                nid.dist = res$neighbors_dist,
                neighbors.id = res$neighbor_idx,
                rho = 0.1,
                sigma2 = 0.3,
                k = Nk)
w <- rmnorm_NN_GP(n = 1, mu = rep(0, M),
                 AD = AD[1:M, 1:(Nk+1)],
                 neighbors.id = res$neighbor_idx[1:M, 1:Nk])
loglike <- dmnorm_NN_GP(w, mu = rep(0, M),
                       AD = AD[1:M, 1:(Nk+1)],
                       neighbors.id = res$neighbor_idx[1:M, 1:Nk],
                       log = TRUE)


BayesNSGP documentation built on Sept. 10, 2026, 5:08 p.m.