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

EpiEstim rmd chunk- use of {distcrete} #127

Closed
CarmenTamayo opened this issue Feb 9, 2024 · 6 comments
Closed

EpiEstim rmd chunk- use of {distcrete} #127

CarmenTamayo opened this issue Feb 9, 2024 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@CarmenTamayo
Copy link
Contributor

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
Copy link
Contributor Author

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]], ...)

@CarmenTamayo CarmenTamayo added the question Further information is requested label Feb 9, 2024
@Bisaloo
Copy link
Member

Bisaloo commented Feb 12, 2024

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.

@Bisaloo
Copy link
Member

Bisaloo commented Feb 12, 2024

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
Copy link
Contributor Author

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 55d55f3 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
Copy link
Contributor Author

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
Copy link
Member

Bisaloo commented Mar 21, 2024

This was fixed by #132

@Bisaloo Bisaloo closed this as completed Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants