Replies: 4 comments 3 replies
-
Quick thoughts whilst in my head. It may be that multiple approaches are needed but that the implementations of those can be standardised. 1 (or variations of it) is good for flexibility and can have a relatively straightforward pattern but you do need some validation to ensure they do what you want, e.g. do_something <- function(x, f, ...) {
if (!valid_function(f))
stop("invalid function")
out <- tryCatch(f(x, ...), error = function(e) stop("useful error message"))
if (!valid_output(out))
stop("another useful error message")
# do something useful
} 2 is good when you want to only support specific distributions do_something <- function(x, f = c("weibull", "norm"), ...) {
f <- match.arg(f)
ddist <- c(weibull = dweibull, norm = dnorm)
f <- ddist[[f]]
out <- f(x, ...)
# now do something useful
} I viewed 4 more as a catalogue where end users could extract parameters from literature and then would use in functions with interfaces 1,2, 4 (maybe). Developers may want to create methods that work with those objects for convenience but I assumed the main thrust was making known parameters easily available. I'm not familiar with 3 so would like to understand it more before I comment. |
Beta Was this translation helpful? Give feedback.
-
Also I'd be similarly wary about introducing another abstraction via a package (but ... see edit below). I know {distr6} was just given as an example but it would be a no go for me as not on CRAN (nor will it ever be AFAICT). EDIT: That said, I've now had time to look at 3 and I really like the idea here and how it allows nesting of distributions. However I'm very ignorant of the wider package ecosystem in regards to implementations like this. Are there any out there you could make use of rather than creating another? If this answer is no then this feels like something that could be a package in it's own right. So my current thinking is that there's a place for 1, 2 and 3. Functions that utilise 1 or 2 could always be replaced with generics and methods provided for 3 (and 4 for that matter) if the more custom approach makes the experience better for users. Hope this makes sense. Interested to hear what others think. |
Beta Was this translation helpful? Give feedback.
-
Thanks for raising @sbfnk. I echo much of what @TimTaylor has said. In terms of what should be accepted by functions/packages that use distributions, I think 1 is preferred, with the aim at some point for Epiverse-TRACE packages (and potentially others) to accept 4 as well. My feeling with 4 (the One possibility, building on something mentioned by Tim:
If option 3 became a standalone package, it could be utilised as the distribution infrastructure for |
Beta Was this translation helpful? Give feedback.
-
Some updates on this:
|
Beta Was this translation helpful? Give feedback.
-
Probability distributions are ubiquitous in epidemiological work and used, e.g., for specifying the number of secondary infections generated by an infectious person (the offspring distribution) or delays in the process of infection or reporting (e.g. incubation periods). At the moment we have at least 4 different ways of specifying them across our packages, which is perhaps not ideal from a user perspective:
x
, and returns a density. This was discussed in the context of the cfr package and decided on as the approach most in line with best practice in R.I don't have any immediate solution for harmonising this beyond perhaps using a more comprehensive distribution interface such as distr6 which would introduce another layer of complexity. I'd be keen to hear people's thoughts and/or suggestions for improving both interoperability and clarity to users whilst fulfilling the specific requirements in the different packages.
Beta Was this translation helpful? Give feedback.
All reactions