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

Update {epiparameter} usage #100

Merged
merged 36 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
38a9b59
Update {epiparameter} usage
CarmenTamayo Nov 28, 2023
edd223c
fixing failing checks
CarmenTamayo Nov 28, 2023
d11e308
fixing failing checks
CarmenTamayo Nov 28, 2023
ea370b8
Changing parameter description from pathogen to disease
CarmenTamayo Nov 29, 2023
73b65ef
Updating epiparameter version in renv::use (from fd250ce to e531c09)
CarmenTamayo Nov 29, 2023
79fb42d
Using {epiparameter} instead of {epitrix} when converting summary sta…
CarmenTamayo Nov 29, 2023
fc11eb6
Fixing failing check: issue with line length (111 when it should be <80)
CarmenTamayo Nov 29, 2023
492632c
Using {epiparameter} instead of {distcrete} to discretise distributio…
CarmenTamayo Nov 29, 2023
72c6f33
Removing white space to pass checks
CarmenTamayo Nov 29, 2023
1ee43ec
Fixing line indentation lintr
CarmenTamayo Nov 30, 2023
c968def
Removing unused packages lintr
CarmenTamayo Nov 30, 2023
ecefa71
Removing author from arguments when using epiparameter_db
CarmenTamayo Dec 5, 2023
d0f8cc7
Updating epiparameter version to discretise normal distribution
CarmenTamayo Dec 5, 2023
f192409
Change use_epiparameter to use_epiparameter_database
CarmenTamayo Dec 6, 2023
027f22e
Changing hard coded gamma distribution to distribution from params list
CarmenTamayo Dec 7, 2023
8255907
Removing as.list since distcrete is no longer used
CarmenTamayo Dec 7, 2023
9642635
Changing `epiparameter_disease` to `disease_name` to create epidist o…
CarmenTamayo Dec 11, 2023
cc979ed
Changing SI object name to discretise both dist from epiparameter and…
CarmenTamayo Dec 11, 2023
624bd56
Changing si_epiparameter to si_epidist to match SI object name create…
CarmenTamayo Dec 11, 2023
06f5877
Taking only parameterised distributions from {epiparameter}
CarmenTamayo Dec 11, 2023
014a130
Updating code to use r() with an epidist object
CarmenTamayo Jan 8, 2024
53f92cd
Updating function to convert parameters with `epiparameter`
CarmenTamayo Jan 8, 2024
8febb4b
Removing `rio::` to fix lintr error
CarmenTamayo Jan 8, 2024
64dc40b
Remove `grateful::` to fix lintr error
CarmenTamayo Jan 8, 2024
beefb8c
Creating epidist for manually supplied parameters so that `epiparamet…
CarmenTamayo Jan 8, 2024
d336c04
Updating distribution mean and sd objects for plotting
CarmenTamayo Feb 9, 2024
ba3e9af
Update epiparameter use in R0 rmd chunk
CarmenTamayo Feb 9, 2024
edd2205
Updating quantile function from $q to quantile()
CarmenTamayo Feb 22, 2024
6c2e7c1
Changing get_parameters to parenthesis to extract mean and sd from ep…
CarmenTamayo Feb 26, 2024
dbb6961
Removing auto_calc_params
CarmenTamayo Feb 26, 2024
592634f
Updating authors
CarmenTamayo Feb 26, 2024
3108aaf
Removing si_cv as no longer being used
CarmenTamayo Feb 27, 2024
5b5e516
Adding ORCID
CarmenTamayo Feb 27, 2024
e58fd12
Do not explicitly namespace epiparameter
Bisaloo Feb 29, 2024
292bd20
Get EpiEstim chunk to work with SI passed as epidist
Bisaloo Feb 22, 2024
916e8e3
Get i2extras to work with SI passed as epidist
Bisaloo Feb 22, 2024
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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Authors@R: c(
person("Hugo", "Gruson", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-4094-1476")),
person("Thibaut", "Jombart", role = "aut"),
person("Carmen", "Tamayo", role = "aut", comment = c(ORCID = "0000-0003-4184-2864")),
person("data.org", role = "fnd")
)
Description: A store of outbreak analytics pipelines using different
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ library(EpiEstim)
# Function to process a distrcrete object and output `si_discr` argument for
# EpiEstim::make_config

wrap_si <- function(x) {
stopifnot(inherits(x, "distcrete"))
max_x <- x$q(0.999)
x <- si$d(seq_len(max_x))
x[1] <- 0
x <- x / sum(x)
x
wrap_si <- function(si) {
domain <- seq(1L, to = si$prob_dist$qf(0.999), by = 1L)
pmf <- si$prob_dist$d(domain)
pmf[1] <- 0
pmf <- pmf / sum(pmf)
pmf
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ library(EpiNow2)
# will use for generation_time
si_gamma <- epiparameter::extract_param(
type = "range",
values = c(median(si$r(1e3)), min(si$r(1e3)), max(si$r(1e3))),
distribution = "gamma",
values = c(median(si$prob_dist$r(1e3)),
min(si$prob_dist$r(1e3)),
max(si$prob_dist$r(1e3))),
distribution = params$si_dist,
samples = 1e3
)
si_gamma <- epiparameter::gamma_shapescale2meansd(si_gamma[[1]], si_gamma[[2]])
si_gamma <- epiparameter::convert_params_to_summary_stats(
distribution = "gamma", shape = si_gamma[[1]], scale = si_gamma[[2]])
CarmenTamayo marked this conversation as resolved.
Show resolved Hide resolved

generation_time <- list(
mean = si_gamma$mean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ library(R0)
### Results

```{r rt-wrappers-prep}
mGT <- generation.time("empirical", si$d(si_x))
mGT <- generation.time("empirical", si$prob_dist$d(si_x))

# Helper function to get R0 outputs in a tidy format, compatible with pipelines
r0_quantiles <- function(Rt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ This section contains:

```{r }
res_R_wl <- last_trends %>%
mutate(R = map(model, epitrix::lm2R0_sample, w = si, 500)) %>%
mutate(R = map(model, epitrix::lm2R0_sample, w = si$prob_dist$d(si_x))) %>%
dplyr::select({{ group_var }}, R) %>%
unnest(R)

Expand Down
71 changes: 32 additions & 39 deletions inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ params:
r_estim_window:
label: "Number of days to include to get the latest observed value of Rt."
value: 21
use_epiparameter:
use_epiparameter_database:
label: "Should the serial interval distribution be extracted directly from the epiparameter package?"
value: FALSE
epiparameter_pathogen:
label: "Name of the pathogen in the epiparameter database if `use_parameter = TRUE`."
value: "SARS_CoV_2_wildtype"
disease_name:
joshwlambert marked this conversation as resolved.
Show resolved Hide resolved
label: "Name of the disease of interest, also used to select diseases in the epiparameter database if `use_parameter_database = TRUE`."
value: "COVID-19"
si_mean:
label: "Mean of the distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter = TRUE`."
label: "Mean of the distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter_database = TRUE`."
value: 4.2
si_sd:
label: "Standard deviation of the distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter = TRUE`."
label: "Standard deviation of the distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter_database = TRUE`."
value: 4.9
si_dist:
label: "Choice of probability distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter = TRUE`."
label: "Choice of probability distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter_database = TRUE`."
value: "gamma"
choices: ["beta", "binom", "cauchy", "chisq", "exp", "f", "gamma", "geom", "hyper", "lnorm", "logis", "nbinom", "norm", "pois", "smirnov", "t", "tukey", "unif", "weibull", "wilcox"]
data_file:
Expand Down Expand Up @@ -79,7 +79,7 @@ renv::use(
"[email protected]",
"epiverse-trace/episoap", # nolint
"[email protected]",
"epiverse-trace/epiparameter@fd250ce", # nolint
"epiverse-trace/epiparameter@328706e", # nolint
"[email protected]",
"[email protected]",
"[email protected]",
Expand Down Expand Up @@ -222,8 +222,6 @@ library(linelist)
library(janitor)
library(kableExtra)
library(incidence2)
library(distcrete)
library(epitrix)
library(grateful)
library(epiparameter)

Expand Down Expand Up @@ -275,7 +273,7 @@ data_path <- params$data_file

```{r}
dat_raw <- data_path %>%
rio::import() %>%
import() %>%
tibble() %>%
# rio (via readxl) tends to use POSIXct for what is encoded as Date in the
# original data file.
Expand Down Expand Up @@ -392,46 +390,41 @@ discretized Gamma.

## Results

```{r, eval = params$use_epiparameter}
si_epiparameter <- epiparameter::epidist(
params$epiparameter_pathogen,
"serial_interval"
```{r, eval = params$use_epiparameter_database}
si_epidist <- epidist_db(
disease = params$disease_name,
epi_dist = "serial_interval",
single_epidist = TRUE,
subset = is_parameterised
CarmenTamayo marked this conversation as resolved.
Show resolved Hide resolved
)
si_params <- si_epiparameter$param
si_dist <- si_epiparameter$dist
si_mean <- si_params[[1]]
si_sd <- si_params[[2]]

si_params <- get_parameters(si_epidist)
si_dist <- family(si_epidist)
si_mean <- si_params["mean"]
si_sd <- si_params["sd"]
```

```{r, eval = !params$use_epiparameter}
```{r, eval = !params$use_epiparameter_database}
si_mean <- params$si_mean
si_sd <- params$si_sd
si_dist <- params$si_dist
si_cv <- si_sd / si_mean
si_params <- epitrix::gamma_mucv2shapescale(mu = si_mean, cv = si_cv)
si_epidist <- epidist(
disease = params$disease_name,
epi_dist = "serial_interval",
prob_distribution = params$si_dist,
summary_stats = create_epidist_summary_stats(mean = params$si_mean,
sd = params$si_sd)
)
```

```{r}
# do.call() because we want to pass `si_params` names as the name of arguments.
# This is important if params in si_params are not the first arguments of the
# q...() function. For example, if a gamma distribution is define by its shape
# and scale, instead of shape and rate.
si <- do.call(
distcrete,
c(
list(si_dist,
interval = 1,
w = 0
),
si_params
)
)
si_x <- seq(1L, to = si$q(0.999), by = 1L)
si <- discretise(si_epidist)
si_x <- seq(1L, to = quantile(si, 0.999), by = 1L)
```

```{r}
ggplot(
data.frame(delay = si_x, prob = si$d(si_x)),
data.frame(delay = si_x, prob = si$prob_dist$d(si_x)),
aes(x = delay, y = prob)
) +
geom_col(fill = green_grey) +
Expand Down Expand Up @@ -478,6 +471,6 @@ dat_i_day <- dat_raw %>%
```

```{r}
grateful::cite_packages(output = "paragraph", out.dir = ".", pkgs = "Session")
cite_packages(output = "paragraph", out.dir = ".", pkgs = "Session")
```

Loading