stan_ode_generate: stan_ode_generate

Description Usage Arguments Value See Also Examples

Description

Generates a syntactically valid Stan program using the ODE system generated by stan_lines.

Usage

1
stan_ode_generate(obj, path, n_states)

Arguments

obj

Output of stan_lines.

path

String path generated by stan_prog.

n_states

Number of states in the ODE system.

Value

A string with the Stan model which can be used in stan. A more readable representation of the model can be constructed by applying the cat function to the output.

See Also

stan_lines, stan_prog.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
# Define the ODE system as an R function
two_cpt <- function(t, y, parms) {
  with(as.list(c(y, parms)), {
    dy_gut = -ka * y_gut
    dy_cent = ka * y_gut - (CL/V_cent + Q/V_cent) * y_cent + (Q/V_peri) * y_peri
    dy_peri = (Q/V_cent) * y_cent - (Q/V_peri) * y_peri
    return(list(c(dy_gut=dy_gut, dy_cent=dy_cent, dy_peri=dy_peri)))
  })
}
# Create the time steps, inital state values, and parameter values
pars <- c("CL" = 10, Q = 13, "V_cent" = 20, "V_peri" = 73, ka = 3)
yini <- c("y_gut" = 0, "y_cent" = 0, "y_peri" = 0)
time_steps <- seq(0, 150, by = 0.01)
# Convert the R defined ODE into Stan syntax
sl <- stan_lines(two_cpt, state = yini,
                 pars = pars,
                 times = time_steps)
# Generate the useable Stan file
cat(stan_ode_generate(sl, has_events = TRUE, integrator = "rk45", n_states = 3))

## End(Not run)

imadmali/stanode documentation built on May 3, 2019, 11:48 p.m.