Skip to contents

This is function draws samples from the latent states using the backward sampling algorithm. See WestHarr-DLM;textualkDGLM, chapter 15, for details.

Usage

# S3 method for class 'fitted_dlm'
simulate(object, nsim, seed = NULL, lag = -1, safe.mode = TRUE, ...)

Arguments

object

fitted_dlm: A fitted model from which to sample.

nsim

integer: The number of samples to draw.

seed

integer: An object specifying if and how the random number generator should be initialized.

lag

integer: The relative offset for forecast. Values for time t will be calculated based on the filtered values of time t-h. If lag is negative, then the smoothed distribution for the latent states will be used.

safe.mode

boolean: A flag indicating if consistency check should be performed at each time step. Recommended to be left on, but if you know what you are doing (i.e., you tested the model and it is safe) and need to fit it several times, you can disable the checks to save some time.

...

Extra arguments passed to the plot method.

Value

A list containing the following values:

  • theta array: An array containing a sample of the latent states. Dimensions are n x t x nsim, where n is the number of latent states in the model and t is the number of observed values.

  • lambda array: An array containing a sample of the linear predictors. Dimensions are k x t x nsim, where k is the number of linear predictors in the model and t is the number of observed values.

  • param list: A named list containing, for each model outcome, an array with the samples of the parameters of the observational model. Each array will have dimensions l x t x nsim, where l is the number of parameters in the observational model and t is the number of observed values.

See also

Other auxiliary functions for fitted_dlm objects: coef.fitted_dlm(), eval_dlm_norm_const(), fit_model(), forecast.fitted_dlm(), kdglm(), smoothing(), update.fitted_dlm()

Examples


structure <- polynomial_block(mu = 1, D = 0.95) +
  polynomial_block(V = 1, D = 0.95)

outcome <- Normal(mu = "mu", V = "V", data = cornWheat$corn.log.return[1:500])
fitted.data <- fit_model(structure, corn = outcome)

sample <- simulate(fitted.data, 5000)