Learn R Programming

bssm (version 1.0.0)

bootstrap_filter: Bootstrap Filtering

Description

Function bootstrap_filter performs a bootstrap filtering with stratification resampling.

Usage

bootstrap_filter(model, nsim, ...)

# S3 method for gaussian bootstrap_filter( model, nsim, seed = sample(.Machine$integer.max, size = 1), ... )

# S3 method for nongaussian bootstrap_filter( model, nsim, seed = sample(.Machine$integer.max, size = 1), ... )

# S3 method for ssm_nlg bootstrap_filter( model, nsim, seed = sample(.Machine$integer.max, size = 1), ... )

# S3 method for ssm_sde bootstrap_filter( model, nsim, L, seed = sample(.Machine$integer.max, size = 1), ... )

Arguments

model

of class bsm_lg, bsm_ng or svm.

nsim

Number of samples.

...

Ignored.

seed

Seed for RNG.

L

Integer defining the discretization level for SDE models.

Value

A list containing samples, weights from the last time point, and an estimate of log-likelihood.

Examples

Run this code
# NOT RUN {
set.seed(1)
x <- cumsum(rnorm(50))
y <- rnorm(50, x, 0.5) 
model <- bsm_lg(y, sd_y = 0.5, sd_level = 1, P1 = 1)
  
out <- bootstrap_filter(model, nsim = 1000)
ts.plot(cbind(y, x, out$att), col = 1:3)
ts.plot(cbind(kfilter(model)$att, out$att), col = 1:3)

data("poisson_series")
model <- bsm_ng(poisson_series, sd_level = 0.1, sd_slope = 0.01, 
  P1 = diag(1, 2), distribution = "poisson")
  
out <- bootstrap_filter(model, nsim = 100)
ts.plot(cbind(poisson_series, exp(out$att[, 1])), col = 1:2)

# }

Run the code above in your browser using DataLab