dust_example | R Documentation |
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.
dust_example(name)
name |
The name of the example to use. There are four
examples: |
sir
: a basic SIR (Susceptible, Infected, Resistant)
epidemiological model. Draws from the binomial distribution to
update the population between each 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.
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") sir # Initialise the model at step 0 with 50 independent trajectories mod <- sir$new(list(), 0, 50) # Run the model for 400 steps, collecting "infected" every 4th step steps <- seq(0, 400, by = 4) mod$set_index(2L) y <- mod$simulate(steps) # A plot of our epidemic matplot(steps, t(drop(y)), type = "l", lty = 1, col = "#00000044", las = 1, xlab = "Step", ylab = "Number infected")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.