Learn R Programming

bssm (version 0.1.8)

run_mcmc.ngssm: Bayesian inference of non-Gaussian or non-linear state space models using MCMC

Description

Methods for posterior inference of states and parameters.

Usage

# S3 method for ngssm
run_mcmc(object, n_iter, nsim_states, type = "full",
  method = "da", simulation_method = "psi",
  n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3,
  target_acceptance = 0.234, S, end_adaptive_phase = TRUE,
  local_approx = TRUE, n_threads = 1,
  seed = sample(.Machine$integer.max, size = 1), max_iter = 100,
  conv_tol = 1e-08, ...)

# S3 method for ng_bsm run_mcmc(object, n_iter, nsim_states, type = "full", method = "da", simulation_method = "psi", n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3, target_acceptance = 0.234, S, end_adaptive_phase = TRUE, local_approx = TRUE, n_threads = 1, seed = sample(.Machine$integer.max, size = 1), max_iter = 100, conv_tol = 1e-08, ...)

# S3 method for ng_ar1 run_mcmc(object, n_iter, nsim_states, type = "full", method = "da", simulation_method = "psi", n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3, target_acceptance = 0.234, S, end_adaptive_phase = TRUE, local_approx = TRUE, n_threads = 1, seed = sample(.Machine$integer.max, size = 1), max_iter = 100, conv_tol = 1e-08, ...)

# S3 method for svm run_mcmc(object, n_iter, nsim_states, type = "full", method = "da", simulation_method = "psi", n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3, target_acceptance = 0.234, S, end_adaptive_phase = TRUE, local_approx = TRUE, n_threads = 1, seed = sample(.Machine$integer.max, size = 1), max_iter = 100, conv_tol = 1e-08, ...)

# S3 method for nlg_ssm run_mcmc(object, n_iter, nsim_states, type = "full", method = "da", simulation_method = "psi", n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3, target_acceptance = 0.234, S, end_adaptive_phase = TRUE, n_threads = 1, seed = sample(.Machine$integer.max, size = 1), max_iter = 100, conv_tol = 1e-04, iekf_iter = 0, ...)

# S3 method for sde_ssm run_mcmc(object, n_iter, nsim_states, type = "full", method = "da", L_c, L_f, n_burnin = floor(n_iter/2), n_thin = 1, gamma = 2/3, target_acceptance = 0.234, S, end_adaptive_phase = TRUE, n_threads = 1, seed = sample(.Machine$integer.max, size = 1), ...)

Arguments

object

Model object.

n_iter

Number of MCMC iterations.

nsim_states

Number of state samples per MCMC iteration. If <2, approximate inference based on Gaussian approximation is performed.

type

Either "full" (default), or "summary". The former produces samples of states whereas the latter gives the mean and variance estimates of the states.

method

What MCMC algorithm to use? Possible choices are "pm" for pseudo-marginal MCMC, "da" for delayed acceptance version of PMCMC (default), or one of the three importance sampling type weighting schemes: "is3" for simple importance sampling (weight is computed for each MCMC iteration independently), "is2" for jump chain importance sampling type weighting, or "is1" for importance sampling type weighting where the number of particles used for weight computations is proportional to the length of the jump chain block.

simulation_method

If "spdk", non-sequential importance sampling based on Gaussian approximation is used. If "bsf", bootstrap filter is used (default for "nlg_ssm" and only option for "sde_ssm"), and if "psi", psi-auxiliary particle filter is used (default for models with linear-Gaussian state equation).

n_burnin

Length of the burn-in period which is disregarded from the results. Defaults to n_iter / 2.

n_thin

Thinning rate. Defaults to 1. Increase for large models in order to save memory. For IS-corrected methods, larger value can also be statistically more effective. Note: With type = "summary", the thinning does not affect the computations of the summary statistics in case of pseudo-marginal methods.

gamma

Tuning parameter for the adaptation of RAM algorithm. Must be between 0 and 1 (not checked).

target_acceptance

Target acceptance ratio for RAM. Defaults to 0.234.

S

Initial value for the lower triangular matrix of RAM algorithm, so that the covariance matrix of the Gaussian proposal distribution is \(SS'\). Note that for some parameters (currently the standard deviation and dispersion parameters of bsm models) the sampling is done for transformed parameters with internal_theta = log(1 + theta).

end_adaptive_phase

If TRUE (default), $S$ is held fixed after the burnin period.

local_approx

If TRUE (default), Gaussian approximation needed for importance sampling is performed at each iteration. If false, approximation is updated only once at the start of the MCMC. Not used for non-linear models.

n_threads

Number of threads for state simulation.

seed

Seed for the random number generator.

max_iter

Maximum number of iterations used in Gaussian approximation. Used psi-PF.

conv_tol

Tolerance parameter used in Gaussian approximation. Used psi-PF.

...

Ignored.

iekf_iter

If zero (default), first approximation for non-linear Gaussian models is obtained from extended Kalman filter. If iekf_iter > 0, iterated extended Kalman filter is used with iekf_iter iterations.

L_c, L_f

Integer values defining the discretization levels for first and second stages. For PM methods, maximum of these is used.

Examples

Run this code
# NOT RUN {
set.seed(1)
n <- 50 
slope <- cumsum(c(0, rnorm(n - 1, sd = 0.001)))
level <- cumsum(slope + c(0, rnorm(n - 1, sd = 0.2)))
y <- rpois(n, exp(level))
poisson_model <- ng_bsm(y, 
  sd_level = halfnormal(0.01, 1), 
  sd_slope = halfnormal(0.01, 0.1), 
  P1 = diag(c(10, 0.1)), distribution = "poisson")
mcmc_is <- run_mcmc(poisson_model, n_iter = 1000, nsim_states = 10, method = "is2")
summary(mcmc_is, only_theta = TRUE, return_se = TRUE)
# }

Run the code above in your browser using DataLab