Title: | Sequential Monte Carlo for Latent Conditional Autoregressive Model |
---|---|
Description: | Functions for replicating the results of the latent Gaussian Markov random field experiment of Lindsten, Helske, Vihola (2018), XX. Contains also functions for performing particle Markov chain Monte Carlo estimation of the model parameters. |
Authors: | Jouni Helske [aut, cre] |
Maintainer: | Jouni Helske <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.1 |
Built: | 2024-11-06 03:25:48 UTC |
Source: | https://github.com/helske/particlefield |
Gaussian approximation for Binomial model with latent CAR field
approximate_binomial_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, initial_mode, max_iter = 100, conv_tol = 1e-08, reorder = TRUE, ratio_correction = TRUE)
approximate_binomial_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, initial_mode, max_iter = 100, conv_tol = 1e-08, reorder = TRUE, ratio_correction = TRUE)
nnbs |
Vector defining the number of neighbours for each vertex. |
nbs |
Matrix of indices of defining neighbours for each vertex. |
tau |
Precision parameter for CAR field. |
d |
Properness parameter for the CAR field. |
y |
Vector of observations. |
u |
Vector of trials. Default to 1. |
idx |
Vector defining the dependencies between y and x. |
mu |
Intercept of the linear predictor. Defaults to 0. |
use_mu |
Use mu in the model or not. Default is |
initial_mode |
Initial mode estimate of x. |
max_iter |
Maximum number of iterations for the approximation algorithm. |
conv_tol |
Tolerance parameter for the approximation algorithm. |
reorder |
If |
ratio_correction |
Should the returned log-likelihood estimate contain the ratio correction
term? Default is |
Boostrap SMC for CAR model with Binomial observations
bsf_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_particles, ess_threshold = NULL, reorder = TRUE, seed = sample(.Machine$integer.max, size = 1))
bsf_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_particles, ess_threshold = NULL, reorder = TRUE, seed = sample(.Machine$integer.max, size = 1))
nnbs |
Vector defining the number of neighbours for each vertex. |
nbs |
Matrix of indices of defining neighbours for each vertex. |
tau |
Precision parameter for CAR field. |
d |
Properness parameter for the CAR field. |
y |
Vector of observations. |
u |
Vector of trials. Default to 1. |
idx |
Vector defining the dependencies between y and x. |
mu |
Intercept of the linear predictor. Defaults to 0. |
use_mu |
Use mu in the model or not. Default is |
n_particles |
Number of particles for SMC. |
ess_threshold |
Resampling is done when the effective sample size estimator is less than this threshold times the number of particles.
For example if |
reorder |
If |
seed |
Seed for the random number generator. |
Markov chain Monte Carlo for Binomial CAR model
mcmc_binomial_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_iter, n_burnin, n_particles = 0, initial_mode, max_iter = 100, conv_tol = 1e-08, seed = sample(.Machine$integer.max, size = 1), S = NULL, ratio_correction = TRUE, reorder = TRUE, ess_threshold = 1)
mcmc_binomial_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_iter, n_burnin, n_particles = 0, initial_mode, max_iter = 100, conv_tol = 1e-08, seed = sample(.Machine$integer.max, size = 1), S = NULL, ratio_correction = TRUE, reorder = TRUE, ess_threshold = 1)
nnbs |
Vector defining the number of neighbours for each vertex. |
nbs |
Matrix of indices of defining neighbours for each vertex. |
tau |
Precision parameter for CAR field. |
d |
Properness parameter for the CAR field. |
y |
Vector of observations. |
u |
Vector of trials. Default to 1. |
idx |
Vector defining the dependencies between y and x. |
mu |
Intercept of the linear predictor. Defaults to 0. |
use_mu |
Use mu in the model or not. Default is |
n_iter |
Number of iterations for the MCMC. |
n_burnin |
Number of iterations to discard as burn-in. |
n_particles |
Number of particles used in the SMC. If set to zero, approximate MCMC is used. |
initial_mode |
Initial mode estimate of x. |
max_iter |
Maximum number of iterations for the approximation algorithm. |
conv_tol |
Tolerance parameter for the approximation algorithm. |
seed |
Seed for the random number generator. |
S |
A lower triangular matrix defining the Cholesky decomposition of the Gaussian proposal distribution. |
ratio_correction |
Should the returned log-likelihood estimate contain the ratio correction
term? Default is |
reorder |
If |
ess_threshold |
Resampling is done when the effective sample size estimator is less than this threshold times the number of particles.
For example if |
This package contains codes for running sequential Monte Carlo (SMC) for simple latent Gaussian Markov random field (GMRF) where the observations are Poisson or binomial. The methodology is introduced in Lindsten, Helske, Vihola (2018).
Print the graph structure to console
print_graph(nnbs, nbs)
print_graph(nnbs, nbs)
nnbs |
Vector defining the number of neighbours for each vertex. |
nbs |
Matrix of indices of defining neighbours for each vertex. |
# Graph on line with 10 vertices nnbs <- c(1, rep(2, 8), 1) nbs <- matrix(0, 10, 10) nbs[1, 1] <- 2 for (i in 2:9) nbs[i, 1:2] <- c(i - 1, i + 1) nbs[10, 1] <- 9 print_graph(nnbs, nbs)
# Graph on line with 10 vertices nnbs <- c(1, rep(2, 8), 1) nbs <- matrix(0, 10, 10) nbs[1, 1] <- 2 for (i in 2:9) nbs[i, 1:2] <- c(i - 1, i + 1) nbs[10, 1] <- 9 print_graph(nnbs, nbs)
Twisted SMC for CAR model with Binomial observations
psi_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_particles, ess_threshold = NULL, reorder = TRUE, initial_mode, max_iter = 100, conv_tol = 1e-08, seed = sample(.Machine$integer.max, size = 1))
psi_car(nnbs, nbs, tau, d, y, u, idx, mu = 0, use_mu = TRUE, n_particles, ess_threshold = NULL, reorder = TRUE, initial_mode, max_iter = 100, conv_tol = 1e-08, seed = sample(.Machine$integer.max, size = 1))
nnbs |
Vector defining the number of neighbours for each vertex. |
nbs |
Matrix of indices of defining neighbours for each vertex. |
tau |
Precision parameter for CAR field. |
d |
Properness parameter for the CAR field. |
y |
Vector of observations. |
u |
Vector of trials. Default to 1. |
idx |
Vector defining the dependencies between y and x. |
mu |
Intercept of the linear predictor. Defaults to 0. |
use_mu |
Use mu in the model or not. Default is |
n_particles |
Number of particles for SMC. |
ess_threshold |
Resampling is done when the effective sample size estimator is less than this threshold times the number of particles.
For example if |
reorder |
If |
initial_mode |
Initial mode estimate of x. |
max_iter |
Maximum number of iterations for the approximation algorithm. |
conv_tol |
Tolerance parameter for the approximation algorithm. |
seed |
Seed for the random number generator. |