stan_transform: Create a StanTransformation object

View source: R/main-declarations.R

stan_transformR Documentation

Create a StanTransformation object

Description

Create a StanTransformation object

Usage

stan_transform(decl, origin = "model", code = "")

Arguments

decl

The Stan variable declaration for the quantity. Must be an object that inherits from StanDeclaration.

origin

Must be either "data", "parameters", or "model". These correspond to the ⁠transformed data⁠, ⁠transformed parameters⁠, and ⁠generated quantities⁠ blocks, respectively.

code

A string of Stan code that defines how the quantity is computed from other variables/parameters. The default is empty string (no definition). If code doesn't include any assignments (with =), it is prepended with paste0(decl$name, " = "). In this case also a semicolon is added to the end if it is missing.

See Also

Other Stan variable declaration functions: stan_array(), stan_dim(), stan_matrix(), stan_param(), stan_var(), stan_vector(), stan_vector_array()

Examples

N <- stan_dim("N")
D <- stan_dim("D")
decl <- stan_array("y", dims = list(N, D), type = "int")
code <- "
for(n in 1:N) {
  for(d in 1:D) {
    y[n, d] ~ poisson_rng(0.2);
  }
}"
y <- stan_transform(decl, code = code)
print(y)

jtimonen/odemodeling documentation built on Sept. 15, 2024, 4:29 a.m.