importance_sample {bssm} | R Documentation |
Importance Sampling from non-Gaussian State Space Model
Description
Returns nsim
samples from the approximating Gaussian model with
corresponding (scaled) importance weights.
Probably mostly useful for comparing KFAS and bssm packages.
Usage
importance_sample(model, nsim, use_antithetic, max_iter, conv_tol, seed, ...)
## S3 method for class 'nongaussian'
importance_sample(
model,
nsim,
use_antithetic = TRUE,
max_iter = 100,
conv_tol = 1e-08,
seed = sample(.Machine$integer.max, size = 1),
...
)
Arguments
model |
Model of class |
nsim |
Number of samples (positive integer). Suitable values depend on the model and the data, and while larger values provide more accurate estimates, the run time also increases with respect to to the number of samples, so it is generally a good idea to test the filter first with a small number of samples, e.g., less than 100. |
use_antithetic |
Logical. If |
max_iter |
Maximum number of iterations as a positive integer. Default is 100 (although typically only few iterations are needed). |
conv_tol |
Positive tolerance parameter. Default is 1e-8. Approximation
is claimed to be converged when the mean squared difference of the modes of
is less than |
seed |
Seed for the C++ RNG (positive integer). |
... |
Ignored. |
Examples
data("sexratio", package = "KFAS")
model <- bsm_ng(sexratio[, "Male"], sd_level = 0.001,
u = sexratio[, "Total"],
distribution = "binomial")
imp <- importance_sample(model, nsim = 1000)
est <- matrix(NA, 3, nrow(sexratio))
for(i in 1:ncol(est)) {
est[, i] <- diagis::weighted_quantile(exp(imp$alpha[i, 1, ]), imp$weights,
prob = c(0.05,0.5,0.95))
}
ts.plot(t(est),lty = c(2,1,2))