dust_example: Access dust's built-in examples

View source: R/examples.R

dust_exampleR Documentation

Access dust's built-in examples


Access dust's built-in examples. These are compiled into the package so that examples and tests can be run more quickly without having to compile code directly via dust(). These examples are all "toy" examples, being small and fast to run.





The name of the example to use. There are five examples: sir, sirs, variable, volatility, walk and logistic (see Details).


  • sir: a basic SIR (Susceptible, Infected, Resistant) epidemiological model. Draws from the binomial distribution to update the population between each time step.

  • sirs: an SIRS model, the SIR model with an added R->S transition. This has a non-zero steady state, so can be run indefinitely for testing.

  • volatility: A volatility model that might be applied to currency fluctuations etc.

  • walk: A 1D random walk, following a Gaussian distribution each time step.

  • logistic: Logistic growth in continuous time


A dust_generator object that can be used to create a model. See examples for usage.


# A SIR (Susceptible, Infected, Resistant) epidemiological model
sir <- dust::dust_example("sir")

# Initialise the model at time step 0 with 50 independent trajectories
mod <- sir$new(list(), 0, 50)

# Run the model for 400 steps, collecting "infected" every 4th time step
times <- seq(0, 400, by = 4)
y <- mod$simulate(times)

# A plot of our epidemic
matplot(times, t(drop(y)), type = "l", lty = 1, col = "#00000044",
        las = 1, xlab = "Time", ylab = "Number infected")

mrc-ide/dust documentation built on Sept. 25, 2023, 10:09 p.m.