Skip to content

Commit

Permalink
add example using predefined functions in Get started vignette, relates
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Jul 17, 2024
1 parent a23061d commit 7df4e3f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion vignettes/simulist.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,28 @@ The `sim_*()` functions, by default, use an excess degree distribution to accoun

## Using functions for distributions instead of `<epidist>`

It is possible to use an [anonymous function](https://en.wikipedia.org/wiki/Anonymous_function) instead of an `<epidist>` object when specifying the parameters of the delay and contact distributions. We recommend using the `<epidist>` objects but here outline the alternative approach.
The `contact_distribution`, `infectious_period`, `onset_to_hosp`, `onset_to_death` and `onset_to_recovery` arguments can accept either an `<epidist>` object (as shown above), or can accept a function. It is possible to use a predefined function or an [anonymous function](https://en.wikipedia.org/wiki/Anonymous_function). Here we'll demonstrate how to use both.

### Predefined functions

```{r, sim-outbreak-func}
contact_distribution <- function(x) dpois(x = x, lambda = 2)
infectious_period <- function(x) rgamma(n = x, shape = 2, scale = 2)
onset_to_hosp <- function(x) rlnorm(n = x, meanlog = 1.5, sdlog = 0.5)
onset_to_death <- function(x) rweibull(n = x, shape = 0.5, scale = 0.2)
outbreak <- sim_outbreak(
contact_distribution = contact_distribution,
infectious_period = infectious_period,
prob_infection = 0.5,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death
)
head(outbreak$linelist)
head(outbreak$contacts)
```

### Anonymous functions

```{r, sim-outbreak-anon-func}
outbreak <- sim_outbreak(
Expand Down

0 comments on commit 7df4e3f

Please sign in to comment.