define.model: Define Stan model

Description Usage Arguments Details Value Examples

Description

Defines Stan model and stores input data

Usage

1
2
define.model(data, parameters, model, transformed.data = list(),
  transformed.parameters = list())

Arguments

data

A list of data passed to the Stan program. Should be of the form list(data.name = list(type = string, dim = number/string (e.g., "[N]"), value = data.object)).

parameters

A list of parameters used in the Stan program. Should be of the form list(parameter.name = list(type = string, dim = number/string)).

model

A list describing the Stan model. Should be a list with components "priors" and "likelihood".

transformed.data

A list describing data transformations for the Stan program to perform. Should be of the form list(variable.name = list(type = string, dim = number/string, expression = string)).

transformed.parameters

A list describing parameter transformations for the Stan program to perform. Should be of the form list(variable.name = list(type = string, dim = number/string, expression = string)).

Details

Defines inputs to be used for building and eventually fitting Stan model.

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
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)

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