Simulate data from the prior predictive density.

sim(object, T = 1000, x = NULL, u = NULL, v = NULL,
  nSimulations = 500, writeDir = tempdir(), ...)

Arguments

object

An object returned by specify, hmm, compile, draw_samples, fit or optimizing.

T

An optional integer with the length of the time series. It defaults to 1000 observations.

x

An optional numeric matrix with the covariates for the observation model. It must have as many rows as the time series length T and as many columns as the dimension of the covariate vector M. If not a matrix, the function tries to cast the object to a \(T\times M\) matrix. Useful for Hidden Markov Regression Model (also known as Markov-switching regressions).

u

An optional numeric matrix with the covariates for the transition model. It must have as many rows as the time series length T and as many columns as the dimension of the transition covariate vector P. If not a matrix, the function tries to cast the object to a \(T\times P\) matrix. Useful for Hidden Markov Models with time-varying transition probabilities.

v

An optional numeric matrix with the covariates for the initial distribution model. It must have as many rows as the number of hidden states K and as many columns as the dimension of the initial covariate vector Q. If not a matrix, the function tries to cast the object to a \(K\times Q\) matrix.

nSimulations

An optional integer with the number of simulations. It defaults to 500 time series.

writeDir

An optional character string with the path where the Stan file should be written. Useful to inspect and modify the Stan code manually. It defaults to a temporary directory.

...

Arguments to be passed to rstan's sampling.

Value

An object of S4 class stanfit with some additional attributes (the dataset data, the name of the Stan code file filename, and the Specification object spec). This object is completely compatible with all other functions.

Examples

# NOT RUN {
mySpec   <- hmm(
  K = 2, R = 1,
  observation = Gaussian(
    mu    = Gaussian(0, 10),
    sigma = Student(
      mu = 0, sigma = 10, nu = 1, bounds = list(0, NULL)
    )
  ),
  initial     = Dirichlet(alpha = c(1, 1)),
  transition  = Dirichlet(alpha = c(1, 1)),
  name = "Univariate Gaussian Hidden Markov Model"
)

mySims <- sim(mySpec, T = 500, nSimulations = 200, seed = 9000)
# }