dust_example: Access dust's built-in examples

Description Usage Arguments Details Value Examples

View source: R/examples.R

Description

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.

Usage

1

Arguments

name

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

Details

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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")

mrc-ide/dust documentation built on Dec. 31, 2021, 7:12 p.m.