RWNNGP_setup: Helper to extract NNGP local neighborhood nodes for custom...

View source: R/v03_RWNNGP_sampler.R

RWNNGP_setupR Documentation

Helper to extract NNGP local neighborhood nodes for custom MCMC sampling

Description

Pre-calculates the local graph structure, target indices, and specific coordinate strings within the AD matrix for a single target node. This forms the control list payload needed by sampler_RW_NN_GP.

Usage

RWNNGP_setup(node_id, AD, neighbors.id, Rneighbors.id, N.neighbors, k = k)

Arguments

node_id

Integer. The index of the specific spatial location currently being set up for targeted random-walk sampling (ranges from 1 to M).

AD

Character. The name of the matrix containing the NNGP coefficients within the NIMBLE model object (typically passed as a string like "AD").

neighbors.id

Integer matrix (M \times k). The forward neighbor index tracking matrix where rows indicate the target location.

Rneighbors.id

Integer vector. The reverse neighbor indices (children) for node_id, computed by get_single_reverse_neighbors.

N.neighbors

Integer vector. A vector of length M storing the exact number of active forward neighbors assigned to each location.

k

Integer. The maximum number of neighbors specified in the NNGP configuration.

Details

This utility is designed to run in an R loop when configuring an MCMC specification prior to model compilation. By converting matrix indexing operations into explicit character node paths (e.g., "AD[5,1]"), it shifts the burden of matrix searching from the runtime execution loop of the C++ compiled sampler into a one-time R setup cost.

It maps out how a change in node_id will ripple through its forward neighbors and back through the reverse neighbors whose conditional distributions depend directly on the target node's value.

Value

A named list containing specific structural elements for the target node:

  • update_id: Integer vector combining the node_id and its reverse neighbors.

  • Fneighbors.id: Integer vector containing non-zero forward neighbor indices.

  • AFnodes: Character vector of parsed string addresses pointing to forward coefficients.

  • ARnodes: Character vector of parsed string addresses pointing to reverse coefficients.

  • A.neighbors: Flattened character vector of matrix addresses representing all relevant neighborhood coefficients needed to re-evaluate residuals during the loop.

Author(s)

Fabian Ketwaroo


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