This function acts as a simple wrapper for lsoda, allowing for multiple parameter sets and initial conditions. It also allows lsoda to be used within the idmodelr framework.

solve_ode(
  model = NULL,
  inits = NULL,
  params = NULL,
  times = NULL,
  as.data.frame = TRUE,
  ...
)

Arguments

model

A model formatted as required by lsoda, see SI_ode for an example.

inits

The initial state (states) of the model. Can either be supplied as a named vector or as a matrix with each row representing a parameter.

params

A named vector or matrix of parameters. The matrix must have a row for each parameter and if inits is specified as a matrix then params must have the same number of columns

times

A numeric vector of the times for which explicit model estimates are required, this does not effect the timestep used by the solver

as.data.frame

A logical (defaults to TRUE) indicating if the results should be returned as a data frame.

...

Additional arguments to pass to lsoda.

Value

A dataframe or lsoda object containing a single or multiple model trajectories

See also

Examples

## Intialise
N = 100000
I_0 = 1
S_0 = N - I_0
R_0 = 1.1
beta = R_0

##Time for model to run over
tbegin = 0
tend = 50
times <- seq(tbegin, tend, 1)

##Vectorise input
parameters <- as.matrix(c(beta = beta))
inits <- as.matrix(c(S = S_0, I = I_0))

solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE)
#> # A tibble: 51 × 3
#>     time      S        I
#>    <dbl>  <dbl>    <dbl>
#>  1     0 99999      1   
#>  2     1 99997.     3.00
#>  3     2 99991.     9.02
#>  4     3 99973.    27.1 
#>  5     4 99919.    81.4 
#>  6     5 99756.   244.  
#>  7     6 99270.   730.  
#>  8     7 97839.  2161.  
#>  9     8 93778.  6222.  
#> 10     9 83382. 16618.  
#> # … with 41 more rows