Skip to content

Remove double seed #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions episodes/superspreading-simulate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ With this configuration, each **chain** will represent **one initial case**. The
Now, let's simulate **100** transmission chains:

```{r,message=FALSE,warning=FALSE,eval=TRUE}
# Run all this chunk together for the set.seed
# Run all this chunk together to let set.seed() work!
# Set seed for random number generator
set.seed(33)
multiple_epichains <- epichains::simulate_chains(
Expand Down Expand Up @@ -385,11 +385,11 @@ We can configure the simulation of multiple chains by simply increasing the numb
If we assume that each initial case start in a different time, we need to iterate over one specific chain simulation.
This table compare the alternatives:

| Number of chains | Replicates | Start time (`t0`) | Use |
| Simulation runs | Initial cases | Start time (`t0`) | Use |
|---|---|---|---|
| Single | 1 | Same | `epichains::simulate_chains(n_chains = 1)` |
| Multiple | 1000, e.g. | Same | `epichains::simulate_chains(n_chains = 1000)` |
| Multiple | 1000, e.g. | Different | Iterate using `purrr::map()` over `epichains::simulate()` |
| One | 1 | Same | `epichains::simulate_chains()` with `n_chains = 1` |
| Multiple (1000, e.g.) | 1 | Same | `epichains::simulate_chains()` with `n_chains = 1000` |
| Multiple (1000, e.g.) | More than one | Different | Iterate 1000 times using `purrr::map()` over `epichains::simulate()` |

The key difference of the third configuration is the `t0` argument from `epichains::simulate_chains()`.
The argument `t0` defines the start time of each initial case per chain.
Expand Down Expand Up @@ -963,7 +963,13 @@ superspreading::probability_epidemic(

[Christian Althaus, 2015](https://www.thelancet.com/journals/laninf/article/PIIS1473-3099(15)70135-0/fulltext) reused data published by [Faye et al., 2015 (Figure 2)](https://www.thelancet.com/journals/laninf/article/PIIS1473-3099(14)71075-8/fulltext#gr2) on the transmission tree on Ebola virus disease in Conakry, Guinea, 2014.

Using the data under the **hint** tab, estimate the offspring distribution from the distribution of secondary cases. Then estimate the large outbreak potential from this data, simulating 100 runs with a seed of one initial case.
Using the data under the **hint** tab:

- Estimate the offspring distribution from the distribution of secondary cases.
- Then estimate the large outbreak potential from this data, simulating 100 runs with one initial case.
- Print the summary of the `<epichains>` class object. This should help us count how many chains reach a `size` of more than 100 infected cases.

For reproducible results use `set.seed(645)`.

::::::::::: hint

Expand All @@ -981,9 +987,13 @@ c0 <- c(c1, rep(0, n - length(c1)))
c0 %>%
enframe() %>%
ggplot(aes(value)) +
geom_histogram()
geom_histogram(binwidth = 1)
```

Optional challenge:

- Reproduce Figure (B) from [Christian Althaus, 2015](https://www.thelancet.com/journals/laninf/article/PIIS1473-3099(15)70135-0/fulltext) with the simulation output.

:::::::::::

:::::::::::::::::::::::::::::
Expand Down Expand Up @@ -1026,6 +1036,10 @@ sim_multiple_chains <- epichains::simulate_chains(
generation_time = function(x) generate(x = ebola_serialinter, times = x)
)

# summarise ----------------------------------------

summary(sim_multiple_chains)

# visualize ----------------------------------------

sim_chains_aggregate <-
Expand All @@ -1046,6 +1060,8 @@ sim_chains_aggregate %>%
geom_line() +
# Define a 100-case threshold
geom_hline(aes(yintercept = 100), lty = 2) +
ylim(0, 100) +
xlim(0, 100) +
labs(x = "Day", y = "Cumulative cases")
```

Expand Down
Loading