Description Usage Arguments Details Value See Also Examples
Workhorse function that inputs in the ODE system as an R function (and associated state variables and parameters) and outputs the analogous function in terms of Stan syntax.
1 | stan_lines(func, state, pars, times)
|
func |
A function (currently if-else statements are not supported). |
state |
A named vector of the initial conditions of the state variables. |
pars |
A named vector of the parameter values. |
times |
A sequence of time steps. |
See stan_ode
for details on function arguments.
A a string vector whose elements are equations of the R ODE system translated into Stan syntax.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## Not run:
# EXAMPLE 1
f1 <- function(y, t, p) {
with(as.list(c(y,parms)), {
dy1 <- y2
dy2 <- -y1 - theta1 * y2
return(c(list(dy1 = dy1, dy2 = dy2)))
})
}
stan_lines(f1, state = c("y1" = 2, "y2" = 5),
pars = c("theta1" = 0.5),
times = seq(1,10,by=0.01))
# EXAMPLE 2
f2 <- function(y, t, p) {
dy1 <- theta1 * y1 + y2 * y3
dy2 <- theta2 * (y2 - y3)
dy3 <- -y1*y2 + (theta3)^2*y2 - y3
return(c(dy1=dy1, dy2=dy2, dy3=dy3))
}
stan_lines(f2, state = c("y1" = 2, "y2" = 5, "y3" = 8),
pars = c("theta1" = 0.5, "theta2" = 0.2, "theta3" = 0.8),
times = seq(1,10,by=0.01))
# EXAMPLE 3
f3 <- function(y, t, p) {
dy1 <- ((y1 + theta1)^2 + y2^2)^(3/2)
dy2 <- ((y1 - theta2)^2 + y2^2)^(3/2)
dy3 <- y1 + 2*dy2 - theta2 * ((y1 + theta1)/dy1) - theta1 * ((y1 - theta2)/ dy2)
dy4 <- y2 - 2*dy1 - theta2 * (y2/dy1) - theta1 * (y2/dy2)
return(c(dy1=dy1, dy2=dy2, dy3=dy3, dy4=dy4))
}
stan_lines(f3, state = c("y1" = 2, "y2" = 5),
pars = c("theta1" = 0.5, "theta2" = 0.2),
times = seq(1,10,by=0.01))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.