Skip to content

Commit 949ba5a

Browse files
committed
change text from purrr to simpler simulation
1 parent f3d5679 commit 949ba5a

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

episodes/superspreading-simulate.Rmd

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -386,29 +386,31 @@ If you need help, return to the "Chain size and length" callout box from the beg
386386
```{r,echo=FALSE}
387387
#### get simulated chain with more infections --------------------------------
388388
389-
chains_subgroup <- simulated_chains_map %>%
389+
epichain_output <- multiple_epichains
390+
391+
chains_subgroup <- epichain_output %>%
390392
as_tibble() %>%
391-
group_by(simulation_id) %>%
393+
group_by(chain) %>%
392394
distinct(infector) %>%
393-
count(simulation_id) %>%
395+
count(chain) %>%
394396
filter(n < 5, n >= 3) %>%
395-
pull(simulation_id)
397+
pull(chain)
396398
397-
chain_to_observe <- simulated_chains_map %>%
399+
chain_to_observe <- epichain_output %>%
398400
as_tibble() %>%
399-
count(simulation_id, sort = TRUE) %>%
401+
count(chain, sort = TRUE) %>%
400402
filter(
401403
magrittr::is_in(
402-
simulation_id, chains_subgroup
404+
chain, chains_subgroup
403405
)
404406
) %>%
405-
filter(n < 10) %>%
407+
# filter(n < 10) %>%
406408
filter(n == max(n)) %>%
407-
slice_min(simulation_id) %>%
408-
pull(simulation_id)
409+
slice_min(chain) %>%
410+
pull(chain)
409411
```
410412

411-
To explore the output format of the `<epichains>` class object of name `simulated_chains_map`, let's look at the simulated `simulation_id` number `r chain_to_observe`.
413+
To explore the output format of the `<epichains>` class object of name `multiple_epichains`, let's look at the simulated `chain` number `r chain_to_observe`.
412414

413415
:::::::::::::::::::::::::::::::::
414416

@@ -419,24 +421,27 @@ To explore the output format of the `<epichains>` class object of name `simulate
419421
Let's use `dplyr::filter()` for this:
420422

421423
```r
422-
chain_to_observe <- 806
424+
chain_to_observe <- 30
423425
```
424426

425427
```{r}
426428
#### get epichain summary ----------------------------------------------------
427429
428-
simulated_chains_map %>%
429-
dplyr::filter(simulation_id == chain_to_observe)
430+
multiple_epichains %>%
431+
dplyr::filter(chain == chain_to_observe)
430432
```
431433

432-
Key elements from this output are in the footer, the piece of text that appears at the bottom:
434+
This output contains two parts:
435+
436+
- A `head()` print of the infector-infectee pairs __starting from the first known infector__.
437+
- A summary footer, the piece of text that appears at the bottom:
433438

434439
```output
435440
Number of infectors (known): 3
436441
Number of generations: 3
437442
```
438443

439-
The simulated `simulation_id` number `r chain_to_observe` has three known infectors and three generations. These numbers are more visible when reading the `<epichains>` objects as a data frame.
444+
The simulated `chain` number `r chain_to_observe` has three known infectors and three generations. These numbers are more visible when printing the `<epichains>` objects as a data frame (or `<tibble>`).
440445

441446
:::::::::::::::::::::::::
442447

@@ -447,15 +452,21 @@ The simulated `simulation_id` number `r chain_to_observe` has three known infect
447452
```{r}
448453
#### infector-infectee data frame --------------------------------------------
449454
450-
simulated_chains_map %>%
451-
dplyr::filter(simulation_id == chain_to_observe) %>%
455+
multiple_epichains %>%
456+
dplyr::filter(chain == chain_to_observe) %>%
452457
dplyr::as_tibble()
453458
```
454459

455460
Chain `r chain_to_observe` tells us a **story**:
456-
"In the first transmission generation at `time = 0`, one index case (`infector = NA`) infected the first case with `infectee = 1`.
457-
Then, in the second transmission generation (between `time` 10 to 16), `infector = 1` infected five cases.
458-
Later, in the third transmission generation (between `time` 26 to 30), `infector = 2` infected three new cases."
461+
462+
"In the first transmission generation at `time = 0`, one subject (`ID = NA`) infected the subject with `ID = 1`.
463+
Subject `ID = 1` is the first known infector.
464+
465+
"Then, in the second transmission generation, subject `ID = 1` infected seven subjects, from `ID = 2` to `ID = 8`.
466+
These infections ocurred in `time` between day 9 and day 15, after the first known infection.
467+
468+
"Later, in the third transmission generation, subject `ID = 4` infected six new subjects, from `ID = 9` to `ID = 14`.
469+
These infections ocurred in `time` between day 24 and day 31, after the first known infection."
459470

460471
:::::::::::::::::::::::::
461472

@@ -465,12 +476,12 @@ Later, in the third transmission generation (between `time` 26 to 30), `infector
465476

466477
The output data frame collects **infectees** as the observation unit:
467478

468-
- Each infectee has a `infectee` "id".
479+
- Each infectee has a `infectee` "ID".
469480
- Each _infectee_ that behaved as an _infector_ is registered in the `infector` column using `infectee` "id".
470481
- Each infectee got infected in a specific `generation` and (continuous) `time`.
471-
- The simulation number is registered under the `simulation_id` column.
482+
- The simulation number is registered under the `chain` column.
472483

473-
**Note:** The `Number of infectors (known)` includes the `NA` observation under the `infector` column. This refers to the infector specified as index case (in the `n_chains` argument), which started the transmission chain to the infectee of `sim_id = 1`, at `generation = 1`, and `time = 0`.
484+
**Note:** The `Number of infectors (known)` includes the subject `ID = NA` under the `infector` column. This refers to the infector specified as index case (in the `n_chains` argument), which started the transmission chain to the infectee of `ID = 1`, at `generation = 1`, and `time = 0`.
474485

475486
:::::::::::::::::::::::::
476487

0 commit comments

Comments
 (0)