epiverse-trace / episoap

[Not published - under active development] A Store of Outbreak Analytics Pipelines Provided as Rmarkdown Report Templates
https://epiverse-trace.github.io/episoap/
Other
4 stars 2 forks source link

EpiEstim rmd chunk- use of {distcrete} #127

Closed CarmenTamayo closed 3 months ago

CarmenTamayo commented 4 months ago

Hi Hugo, I was reviewing the changes in PR #100 and wanted to clarify something- on the EpiEstim chunk, there's this bit of code which used distcrete:

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 }

The description is: Function to process a distrcrete object and output si_discr argument for EpiEstim::make_config

Could you let me know what this function is meant for, and whether this functionality could be replaced by epiparameter? Thanks!

CarmenTamayo commented 4 months ago

Similarly, in the chunk for i2extras, there's part of the code where {epitrix} is used:

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

I was wondering the same question as above, also when running this I'm now getting an error message and was wondering if it might be related to how now "si" is an epidist object?

Error in mutate(): ℹ In argument: R = map(model, epitrix::lm2R0_sample, w = si, 500). Caused by error in map(): ℹ In index: 1. Caused by error in sum(): ! invalid 'type' (list) of argument Backtrace:

  1. ... %>% unnest(R)
    1. purrr::map(model, epitrix::lm2R0_sample, w = si, 500)
    2. purrr:::map_("list", .x, .f, ..., .progress = .progress)
    3. epitrix (local) .f(.x[[i]], ...)
Bisaloo commented 4 months ago

Hi Hugo, I was reviewing the changes in PR #100 and wanted to clarify something- on the EpiEstim chunk, there's this bit of code which used distcrete:

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 }

The description is: Function to process a distrcrete object and output si_discr argument for EpiEstim::make_config

Could you let me know what this function is meant for, and whether this functionality could be replaced by epiparameter? Thanks!

This is the same idea as https://github.com/epiverse-trace/episoap/commit/55d55f3b515a67f92aae614230c3bcc5cf189f8c. We discretize and format the serial interval for EpiEstim. It has a couple of extra requirements, such as the fact it needs to start with 0 and be scaled to 1.

You can re-use the code from https://github.com/epiverse-trace/episoap/commit/55d55f3b515a67f92aae614230c3bcc5cf189f8c to adapt it with epiparameter.

Bisaloo commented 4 months ago

Similarly, in the chunk for i2extras, there's part of the code where {epitrix} is used:

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

I was wondering the same question as above, also when running this I'm now getting an error message and was wondering if it might be related to how now "si" is an epidist object?

Error in mutate(): ℹ In argument: R = map(model, epitrix::lm2R0_sample, w = si, 500). Caused by error in map(): ℹ In index: 1. Caused by error in sum(): ! invalid 'type' (list) of argument Backtrace:

1. ... %>% unnest(R)

2. purrr::map(model, epitrix::lm2R0_sample, w = si, 500)

3. purrr:::map_("list", .x, .f, ..., .progress = .progress)

4. epitrix (local) .f(.x[[i]], ...)

Yes, it's caused by the conversion to epidist. epitrix::lm2R0_sample() works out of the box with distcrete but not with epidist. You will also need to discretize the epidist object and pass it as a numeric vector.

CarmenTamayo commented 4 months ago

Hi Hugo, I was reviewing the changes in PR #100 and wanted to clarify something- on the EpiEstim chunk, there's this bit of code which used distcrete: 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 } The description is: Function to process a distrcrete object and output si_discr argument for EpiEstim::make_config Could you let me know what this function is meant for, and whether this functionality could be replaced by epiparameter? Thanks!

This is the same idea as 55d55f3. We discretize and format the serial interval for EpiEstim. It has a couple of extra requirements, such as the fact it needs to start with 0 and be scaled to 1.

You can re-use the code from 55d55f3 to adapt it with epiparameter.

Hi Hugo, I've been looking into this but I'm not sure how I'd be able to reuse the code from https://github.com/epiverse-trace/episoap/commit/55d55f3b515a67f92aae614230c3bcc5cf189f8c as it's using Epinow2's generation time function? generation_time <- generation_time_opts( dist_spec(pmf = si$prob_dist$d(si_x)) Also, the si is already discretised in the skeleton of the transmissibility report

CarmenTamayo commented 4 months ago

Similarly, in the chunk for i2extras, there's part of the code where {epitrix} is used: res_R_wl <- last_trends %>% mutate(R = map(model, epitrix::lm2R0_sample, w = si, 500)) %>% dplyr::select({{ group_var }}, R) %>% unnest(R) I was wondering the same question as above, also when running this I'm now getting an error message and was wondering if it might be related to how now "si" is an epidist object? Error in mutate(): ℹ In argument: R = map(model, epitrix::lm2R0_sample, w = si, 500). Caused by error in map(): ℹ In index: 1. Caused by error in sum(): ! invalid 'type' (list) of argument Backtrace:

1. ... %>% unnest(R)

2. purrr::map(model, epitrix::lm2R0_sample, w = si, 500)

3. purrr:::map_("list", .x, .f, ..., .progress = .progress)

4. epitrix (local) .f(.x[[i]], ...)

Yes, it's caused by the conversion to epidist. epitrix::lm2R0_sample() works out of the box with distcrete but not with epidist. You will also need to discretize the epidist object and pass it as a numeric vector.

Okay, so we'd have to keep using epitrix? Re the discretisation, this is already done in the skeleton through si <- epiparameter::discretise(si_epidist)- would this not work? thanks!

Bisaloo commented 3 months ago

This was fixed by #132