Skip to contents

CarPoissonTarget: log posterior and gradient of y_i ~ Poisson(E_i exp(beta_0 + phi_i)), phi ~ N(0, (tau (D - rho A))^(-1)), beta_0 ~ N(0, prior_sd^2). MhSpatial: random-walk Metropolis (joint or single-site), iteration t on Philox streams 2t (normals) and 2t + 1 (uniforms). HmcSpatial: leapfrog Hamiltonian Monte Carlo. NutsSpatial: efficient No-U-Turn sampler (Hoffman and Gelman 2014, Algorithm 3) with uniforms drawn in order from a block on stream 2t + 1. TemperedSpatial: parallel tempering with alternating adjacent swaps. Draws match the Python arm exactly.

Usage

CarPoissonTarget(y, expected, A, tau = 1, rho = 0.9, prior_sd = 10)

MhSpatial(logp, x0, n_iter, step = 0.1, single_site = FALSE, seed = 0)

HmcSpatial(logp, grad, x0, n_iter, eps = 0.05, n_leapfrog = 20, seed = 0)

NutsSpatial(logp, grad, x0, n_iter, eps = 0.05, max_depth = 8, seed = 0)

TemperedSpatial(logp, x0, n_iter, temps, step = 0.1, seed = 0)

Arguments

y, expected

Counts and expected counts.

A

Adjacency matrix.

tau, rho

CAR precision and spatial dependence.

prior_sd

Prior standard deviation of the intercept.

logp, grad

Log-density and gradient functions.

x0

Starting value.

n_iter

Number of iterations.

step

Random-walk step.

single_site

Update one coordinate at a time.

seed

Philox seed.

eps

Leapfrog step size.

n_leapfrog

Leapfrog steps per iteration.

max_depth

Maximum NUTS tree depth.

temps

Temperatures (the first is the target).

Value

A list (CarPoissonTarget returns the two functions).

References

Banerjee, S., Carlin, B. P. and Gelfand, A. E. (2014). Hierarchical Modeling and Analysis for Spatial Data. Hastings, W. K. (1970). Biometrika 57, 97-109. Neal, R. M. (2011). In Handbook of MCMC, ch. 5. Hoffman, M. D. and Gelman, A. (2014). JMLR 15, 1593-1623. Geyer, C. J. (1991). Computing Science and Statistics 23, 156-163.

Examples

tg <- CarPoissonTarget(c(1, 2), c(1, 1), rbind(c(0, 1), c(1, 0)))
tg$logp(c(0, 0, 0))
#> [1] -2