compile: Compile a specified model.

Description Usage Arguments Value Examples

Description

This function turns the model specification into Stan code and compiles the program via rstan.

Usage

1
compile(spec, priorPredictive = FALSE, writeDir = tempdir(), ...)

Arguments

spec

An object returned by either specify or hmm.

priorPredictive

An optional logical stating whether the log-likelihood should be excluded from the program. If TRUE, the returned object can only be used to draw samples from the prior predictive density. If FALSE, the returned object can only be used to draw samples from the posterior predictive density. It defaults to FALSE.

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 stan_model.

Value

An instance of S4 class stanmodel.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## 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"
)

# Setting writeDir to store the Stan code file is useful
# if you plan to read and/or edit the automatically generated code
myModel <- compile(mySpec, writeDir = "stan_code")

## End(Not run)

luisdamiano/BayesHMM documentation built on May 20, 2019, 2:59 p.m.