Skip to content

Commit 67617a4

Browse files
committed
clarify the random values functions
1 parent ba03bbd commit 67617a4

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

episodes/superspreading-simulate.Rmd

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ We input an offspring distribution to `{epichains}` by referring to the R functi
212212
size = mers_offspring["dispersion"],
213213
```
214214

215+
Internally, `{epichains}` will draw one random value, given the parameters,
216+
to simulate the number of new infections from an infected individual (onward transmission).
217+
218+
```{r}
219+
# generate one random number given the distribution family and its parameters
220+
rnbinom(n = 1, mu = mers_offspring["mean"], size = mers_offspring["dispersion"])
221+
# run this line many times to get different values
222+
```
223+
215224
The reference manual in `?rnbinom` tells us our required specific arguments.
216225

217226
::::::::::::::::::::::::::::
@@ -251,7 +260,7 @@ Let's use the `{epiparameter}` package to access and use the available serial in
251260
<!-- For `{epichains}` we need a **discretised** input distribution, se we use `epiparameter::discretise()`: -->
252261

253262
```{r,message=FALSE,warning=FALSE}
254-
serial_interval <- epiparameter_db(
263+
serial_interval <- epiparameter::epiparameter_db(
255264
disease = "mers",
256265
epi_name = "serial",
257266
single_epiparameter = TRUE
@@ -273,7 +282,23 @@ The serial interval for MERS has a mean of `r serial_summary$mean` days and a st
273282

274283
### generation time for epichains
275284

276-
In `{epichains}`, we need to specify the generation time as a function that generates random numbers. Using `{epiparameter}` has the advantage of using the distribution function `epiparameter::generate()` for this input. This will look like this:
285+
In each simulation step, `{epichains}` will draw generation time values for each new infection generated from the offspring distribution.
286+
With `<epiparameter>` class objects we can use the distribution function `epiparameter::generate()` for this input.
287+
288+
```{r}
289+
# In step one, the number of new infections is 2, then:
290+
# generate 2 random values given the serial interval distribution
291+
generate(x = serial_interval, times = 2)
292+
293+
# In step two, the number of new infections is 6, then:
294+
# generate 6 random values given the serial interval distribution
295+
generate(x = serial_interval, times = 6)
296+
```
297+
298+
Given that the input value in `times` will vary each step,
299+
we need to embed `generate()` within a function.
300+
`{epichains}` will draw as many random values from the generation time as number of new infections in that step.
301+
This will look like this:
277302

278303
```r
279304
function(x) generate(x = serial_interval, times = x)

0 commit comments

Comments
 (0)