build.model: Build Stan model

Description Usage Arguments Details Value Examples

Description

Builds and compiles a defined Stan model

Usage

1
build.model(ikde.model)

Arguments

ikde.model

An object of class ikde.model, e.g., from define.model

Details

Builds Stan model using defined ikde.model, then compiles the model and stores DSO for fast running.

Value

Returns an ikde.model object with the following elements

data

A list of data passed to the Stan program

transformed.data

A list describing data transformations for the Stan program to perform

parameters

A list of parameters used in the Stan program

transformed.parameters

A list describing parameter transformations for the Stan program to perform

model

A list describing the Stan model

stan.code

Stan code for the model

stan.data

Data passed to Stan for estimation

stan.dso

DSO for Stan model, allows Stan to run model without recompilation

built

Boolean indicating whether the model has been built

density.variable

List containing two elements: "name" of the variable on which density estimation should be performed on, and "value" indicating the point at which density should be estimated

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(lm.generated)

X <- lm.generated$X
y <- lm.generated$y

data <- list(N = list(type = "int<lower=1>", dim = 1, value = nrow(X)),
             k = list(type = "int<lower=1>", dim = 1, value = ncol(X)),
             X = list(type = "matrix", dim = "[N, k]", value = X),
             y = list(type = "vector", dim = "[N]", value = y))
parameters <- list(beta = list(type = "vector", dim = "[k]"),
                   sigma_sq = list(type = "real<lower=0>", dim = 1))
model <- list(priors = c("beta ~ normal(0, 10);",
                         "sigma_sq ~ inv_gamma(1, 1);"),
              likelihood = c("y ~ normal(X * beta, sqrt(sigma_sq));"))

ikde.model <- define.model(data, parameters, model)
ikde.model <- build.model(ikde.model)

cat(ikde.model$stan.code)

tkmckenzie/ikde documentation built on May 13, 2019, 9:53 p.m.