Skip to content

Add outbreak distribution vignette#304

Draft
joshwlambert wants to merge 1 commit intomainfrom
outbreak-dist-vig
Draft

Add outbreak distribution vignette#304
joshwlambert wants to merge 1 commit intomainfrom
outbreak-dist-vig

Conversation

@joshwlambert
Copy link
Member

  • Please check if the PR fulfills these requirements
  • I have read the CONTRIBUTING guidelines
  • A new item has been added to NEWS.md
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Checks have been run locally and pass
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

This PR adds a draft of a vignette describing how to plot the outbreak size and length distributions using {epichains}.

This PR supersedes PR #275 by documenting how users can easily achieve these outbreak distribution plots without requiring a new function in {epichains}.

@jamesmbaazam I've opened this as a draft PR. Please can you let me know if you're happy with the structure, scope and contents of the vignette. If so I'll refine the document and make the PR live. If there are more major revisions required let me know and we can discuss what needs to be worked on.

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No.

@joshwlambert joshwlambert added the documentation Improvements or additions to documentation label Apr 9, 2025
@jamesmbaazam
Copy link
Member

Thanks for adding. I'll take a look asap.

Comment on lines +29 to +35
::: {.alert .alert-primary}
**Glossary**

* Outbreak _size_: the total number of cases produced by an outbreak before it goes extinct.

* Outbreak _length_: the total (maximum) number of generations reached by a outbreak before it goes extinct.
:::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has already been defined severally in the docs, including here. Might be better to link to them.

* Outbreak _length_: the total (maximum) number of generations reached by a outbreak before it goes extinct.
:::

In this vignette we will outline how to show the distribution of outbreak sizes and lengths using the _epichains_ R package.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this vignette we will outline how to show the distribution of outbreak sizes and lengths using the _epichains_ R package.
In this vignette we will outline how to generate a distribution of outbreak sizes and lengths using the _epichains_ R package.


## Simulating an outbreak size distribution

First, we'll simulate the outbreak size distribution using the a Poisson offspring distribution. This is a simple one parameter distribution where the mean and variance of the distribution defined by $\lambda$ which is equal to the reproduction number ($R$).
Copy link
Member

@jamesmbaazam jamesmbaazam Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to offend Siméon Denis Poisson.

Suggested change
First, we'll simulate the outbreak size distribution using the a Poisson offspring distribution. This is a simple one parameter distribution where the mean and variance of the distribution defined by $\lambda$ which is equal to the reproduction number ($R$).
First, we'll simulate the outbreak size distribution using the a Poisson offspring distribution. This is a one-parameter distribution with an equal mean and variance, defined by $\lambda$.
In this use case, $\lambda$ is equal to the reproduction number ($R$).

R <- seq(0.1, 1.0, 0.1)
```

We will create a parameter space will each combination of parameters. In this simple outbreak size simulation, only the reproduction number varies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We will create a parameter space will each combination of parameters. In this simple outbreak size simulation, only the reproduction number varies.
We will create a parameter space with each combination of parameters. In this simple outbreak size simulation, only the reproduction number varies.

)
```

The branching process is stochastic so we need to specify how many simulation model replicates to run to capture the stochasticity in the epidemic. This is important, as mentioned above as a factor that influences outbreak size, the same epidemic transmissibility parameters can result in different sized outbreaks depending on randomness, such as the number of infectees from a given infector.
Copy link
Member

@jamesmbaazam jamesmbaazam Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The branching process is stochastic so we need to specify how many simulation model replicates to run to capture the stochasticity in the epidemic. This is important, as mentioned above as a factor that influences outbreak size, the same epidemic transmissibility parameters can result in different sized outbreaks depending on randomness, such as the number of infectees from a given infector.
Branching processes are stochastic processes, so we need to specify how many simulation model replicates to run to capture the variability in the epidemic. This is important, as mentioned above as a factor that influences outbreak size, the same epidemic transmissibility parameters can result in different sized outbreaks depending on randomness, such as the number of infectees from a given infector.

```

Here we choose to simulate each scenario `r n_chains` times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a leading statement.

```{r, define-breaks}
breaks <- c(0, 2, 5, 10, 20, 50, 100, Inf)
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a leading statement.

outbreak_list <- vector(mode = "list", length = nrow(scenarios))
for (i in seq_len(nrow(scenarios))) {
offspring_dist_fun <- match.fun(scenarios[i, "offspring_dist"])
outbreak_list[[i]] <- epichains::simulate_chain_stats(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outbreak_list[[i]] <- epichains::simulate_chain_stats(
outbreak_list[[i]] <- simulate_chain_stats(


Instead of looking at the outbreak size distribution, i.e. the total number of cases in an outbreak, we may instead be interested in the outbreak _length_ distribution. This is the distribution of the number of generations that an epidemic reaches before going extinct.

We can follow the same procedure as for the outbreak size, but specify `stasitics = "length` in the `simulate_chain_stats()` function. We use the same parameters as the outbreak size simulation above, simulating with a Poisson offspring distribution.
Copy link
Member

@jamesmbaazam jamesmbaazam Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We can follow the same procedure as for the outbreak size, but specify `stasitics = "length` in the `simulate_chain_stats()` function. We use the same parameters as the outbreak size simulation above, simulating with a Poisson offspring distribution.
We can follow the same procedure as for the outbreak size, but specify `statistic = "length"` in the `simulate_chain_stats()` function. We use the same parameters as the outbreak size simulation above, simulating with a Poisson offspring distribution.


We do not repeat the example of simulating an outbreak length distribution using a Negative binomial distribution, but this can be achieved using the code from the examples above, setting `statistic = "length"`.

## Simulating an outbreak size distribution excluding the index case
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section doesn't need to be long as it's quite intuitive. It can be a sentence or two explaining the use case and how it can be done in code, i.e., just subtract 1 case.

@@ -0,0 +1,318 @@
---
title: "Outbreak size and length distribution"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: "Outbreak size and length distribution"
title: "Simulating scenarios of outbreak size and length"

Copy link
Member

@jamesmbaazam jamesmbaazam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this vignette here, @joshwlambert.

I've gone through and left some comments.

My main comment is that this vignette applies a key function simulate_chain_stats() to answer a predictable question and is potentially more suited as a howto guide than as a vignette.

I made a similar decision with a previous vignette I was working on here. I am trying to keep the documentation/vignettes here focused on the package's functions and usage and transferring all applications and use cases to the howto guides.

These decisions are in line with the diataxis framework that we apply.

Let me know you think.

@joshwlambert
Copy link
Member Author

Thanks for the review @jamesmbaazam.

I agree with your assessment on the vignette being more so a how-to guide than an explanation which would be more in the scope of a vignette.

I will make a few minor adjustments and incorporate your suggestions, but then I can transfer this to a PR on howto and close this PR.

@jamesmbaazam
Copy link
Member

Hi @joshwlambert, I'm doing some clean up on this repo and just following up on this PR to see if it has been transferred to the howto's and whether it's safe to close it now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants