You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/superspreading-simulate.Rmd
+27-2Lines changed: 27 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -212,6 +212,15 @@ We input an offspring distribution to `{epichains}` by referring to the R functi
212
212
size=mers_offspring["dispersion"],
213
213
```
214
214
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
+
215
224
The reference manual in `?rnbinom` tells us our required specific arguments.
216
225
217
226
::::::::::::::::::::::::::::
@@ -251,7 +260,7 @@ Let's use the `{epiparameter}` package to access and use the available serial in
251
260
<!-- For `{epichains}` we need a **discretised** input distribution, se we use `epiparameter::discretise()`: -->
252
261
253
262
```{r,message=FALSE,warning=FALSE}
254
-
serial_interval <- epiparameter_db(
263
+
serial_interval <- epiparameter::epiparameter_db(
255
264
disease = "mers",
256
265
epi_name = "serial",
257
266
single_epiparameter = TRUE
@@ -273,7 +282,23 @@ The serial interval for MERS has a mean of `r serial_summary$mean` days and a st
273
282
274
283
### generation time for epichains
275
284
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.
0 commit comments