Giter Site home page Giter Site logo

Comments (4)

joshwlambert avatar joshwlambert commented on September 26, 2024 1

This looks like a good solution and doesn't add too much code to handle each of the possible inputs.

My suggestion of the argument name would be onset_to_outcome or onset_to_outcome_delay. delay_pmf might not be appropriate if the density being used internally is the PDF, but I'd have to check the code again to be sure. delay_function would be a little misleading if the argument also accepts distribution objects as well as functions.

As always, happy to discuss and if there are improvement to be made on the {epiparameter} side to make this step easier feel free to let me know or make an issue.

from cfr.

joshwlambert avatar joshwlambert commented on September 26, 2024 1

Yes, delay_dist seems like a suitable name.

from cfr.

pratikunterwegs avatar pratikunterwegs commented on September 26, 2024

Here's a proposed solution that supports <epidist>, <distribution> from {distributional}, <distcrete>, and a simple closure. I'm suggested support for {distributional} and {distcrete} as they are used in {epiparameter}, and I'm wary of making users work with closures.

I'm unsure about minor differences between epidist and distributional/dgamma, perhaps the accuracy of parameters is the issue. With distcrete, possibly to do with assumed distcrete distribution, or the interval?.

# dummy function that gets PDF/PMF at time points (x)
dens = function(f, x = seq(10)) {
  if (inherits(f, "epidist") || inherits(f, "distribution")) {
    return(stats::density(f, at = x))
  } else if (inherits(f, "distcrete")) {
    f$d(x)
  } else if (is.function(f)) {
    return(f(x))
  }
}

# epidist
epidist = epiparameter::epidist_db(
  disease = "ebola", epi_dist = "onset_to_death", single_epidist = TRUE
)
#> Using WHO-Ebola-Response-Team, Agua-Agum J, Ariyarajah A, Aylward B, Blake ...
#> _The New England Journal of Medicine_. doi:10.1056/NEJMc1414992
#> <https://doi.org/10.1056/NEJMc1414992>.. 
#> To retrieve the short citation use the 'get_citation' function
epiparameter::get_parameters(epidist)
#>    shape    scale 
#> 1.641602 4.995122

# distribution object from distributional
a = distributional::dist_gamma(shape = 1.64102, rate = 1 / 4.995122)

# distcrete object
b = distcrete::distcrete(
  "gamma", interval = 1, shape = 1.64102, scale = 4.995122, w = 0
)

# anonymous function/closure
g = \(x) stats::dgamma(x, shape = 1.64102, scale = 4.995122)

dens(f = epidist)
#>  [1] 0.06495664 0.08295091 0.08807606 0.08671117 0.08190472 0.07536471
#>  [7] 0.06810476 0.06073534 0.05361882 0.04696038
dens(f = a)
#> [[1]]
#>  [1] 0.06502352 0.08300284 0.08811042 0.08673049 0.08191234 0.07536373
#>  [7] 0.06809777 0.06072439 0.05360548 0.04694582
dens(f = b)
#>  [1] 0.07553940 0.08628361 0.08780566 0.08452294 0.07873225 0.07176041
#>  [7] 0.06440200 0.05713331 0.05023183 0.04384829
dens(f = g)
#>  [1] 0.06502352 0.08300284 0.08811042 0.08673049 0.08191234 0.07536373
#>  [7] 0.06809777 0.06072439 0.05360548 0.04694582

Created on 2023-10-13 with reprex v2.0.2

from cfr.

pratikunterwegs avatar pratikunterwegs commented on September 26, 2024

Thanks @joshwlambert. Per your suggestion also happy to support only <epidist> and closure for now. I agree with renaming the argument. The density being used is the PDF/PMF as far as I can tell. Agreed that naming needs some thought - would delay_dist be more appropriate? That way it's agnostic to object type but hopefully nudges towards <epidist>.

from cfr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.