Skip to content
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

replace figure on "evidence for variation in individual reproductive number" by Lloyd-Smith et al., 2005 #121

Open
avallecam opened this issue Oct 8, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation priority

Comments

@avallecam
Copy link
Member

In epiverse-trace/superspreading#93 was solved how to reproduce the figure in paper pasted in the episode checklist. This code is now in vignette https://epiverse-trace.github.io/superspreading/articles/proportion_transmission.html

Episode section to replace:

![**Evidence for variation in individual reproductive number**. (Left, c) Proportion of transmission expected from the most infectious 20% of cases, for 10 outbreak or surveillance data sets (triangles). Dashed lines show proportions expected under the 20/80 rule (top) and homogeneity (bottom). (Right, d), Reported superspreading events (SSEs; diamonds) relative to estimated reproductive number R (squares) for twelve directly transmitted infections. Crosses show the 99th-percentile proposed as threshold for SSEs. (More figure details in [Lloyd-Smith et al., 2005](https://www.nature.com/articles/nature04153))](fig/SEE-individual-reproductive-number-fig-c-d.png)
```{r,message=FALSE,warning=FALSE,echo=FALSE,eval=FALSE}
library(epiparameter)
library(superspreading)
library(tidyverse)
# list of diseases with offspring distribution
epidist_string <- epiparameter::epidist_db(
epi_dist = "offspring distribution"
) %>%
epiparameter::parameter_tbl() %>%
dplyr::select(disease) %>%
dplyr::distinct() %>%
dplyr::as_tibble()
# get percent of cases that cause percent of transmission
across_offspring <- epidist_string %>%
# add column list of epidist objects
mutate(
epidist_out =
map(
.x = disease,
.f = epiparameter::epidist_db,
epi_dist = "offspring distribution",
single_epidist = TRUE
)
) %>%
# get parameters
mutate(
epidist_params =
map(
.x = epidist_out,
.f = epiparameter::get_parameters
)
) %>%
# unnest parameters
unnest_wider(col = epidist_params) %>%
# to each disease, add sequence from 0.01 to 1 (proportion of transmission)
expand_grid(percent_transmission = seq(from = 0.01, to = 1, by = 0.01)) %>%
# estimate proportion of cases responsible of proportion of transmission (row)
mutate(
transmission_output =
pmap(
.l = dplyr::select(., R = mean, k = dispersion, percent_transmission),
.f = superspreading::proportion_transmission,
format_prop = FALSE,
simulate = TRUE # use a numerical simulation
)
) %>%
# unnest proportion of cases results
unnest_wider(col = transmission_output) %>%
# move each result to one column
rowwise() %>%
mutate(
percent_cases =
sum(
c_across(cols = starts_with("prop_")),
na.rm = TRUE
)
) %>%
dplyr::select(-starts_with("prop_")) %>%
ungroup()
# get a position to the ggplot text annotation
across_offspring_tip <- across_offspring %>%
group_by(disease) %>%
filter(percent_transmission < 0.98, percent_transmission > 0.85) %>%
slice_max(percent_transmission) %>%
ungroup() %>%
mutate(disease = case_when(
str_detect(disease, stringr::fixed("Hantavirus")) ~ "Hantavirus",
str_detect(disease, stringr::fixed("Ebola")) ~ "Ebola",
TRUE ~ disease
))
# plot x: proportion of cases, y: proportion of transmission
across_offspring %>%
ggplot() +
geom_line(
aes(
x = percent_cases,
y = percent_transmission,
color = dispersion,
group = disease
)
) +
geom_text(
data = across_offspring_tip,
aes(
x = percent_cases,
y = percent_transmission,
label = disease
),
hjust = 0.0,
vjust = 1.0,
angle = 25,
size = 3
) +
scale_y_continuous(breaks = scales::breaks_pretty(n = 5)) +
colorspace::scale_color_continuous_diverging(trans = "log10", rev = TRUE) +
labs(
x = "Proportion of infectious cases (ranked)",
y = "Expected proportion of transmission",
color = "Dispersion\nparameter (k)"
) +
# geom_hline(aes(yintercept = 0.8),lty = 3) +
geom_vline(aes(xintercept = 0.2), lty = 2) +
coord_fixed(ratio = 1)
```

@avallecam avallecam added documentation Improvements or additions to documentation priority labels Oct 8, 2024
@avallecam avallecam moved this to Todo in tutorials-planning Oct 8, 2024
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 priority
Projects
Status: Todo
Development

No branches or pull requests

1 participant