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

Alternative Parameterizations #5

Open
vincenzocoia opened this issue Nov 4, 2021 · 0 comments
Open

Alternative Parameterizations #5

vincenzocoia opened this issue Nov 4, 2021 · 0 comments
Labels
future A feature to consider for future versions.

Comments

@vincenzocoia
Copy link
Collaborator

One issue that distplyr hasn't considered yet is that of alternative parameterizations of a distribution.

For example, dst_norm() accepts mean and variance as the parameters, but other parameterizations would be useful, such as specifying, say, the 0.05- and 0.95-quantiles (use case: "I'm pretty sure this expense will be between $100 and $200", just set these as lower and upper quantiles). Even mean and stdev would be useful.

I have two ideas for achieving this, but they shouldn't be implemented until after the package is submitted to CRAN.

  1. A parametric distribution is still only specified using its "canonical" parameters (mean and variance for Normal; alpha and beta for Beta; etc.), but changed downstream.

Something like:

dst_norm() %>%
    set_quantiles(0.05 ~ 100, 0.95 ~ 200)

This would operate rlang's tidy evaluation machinery, leaving unevaluated parameters as unknown variables (quosures, probably), until they are evaluated downstream. Bonus: this would also allow for scenarios like dst_unif(a, a + 1), where a is unknown.

  1. Specify parameters by name in the dst_ call.

I'm thinking along the lines of ggplot2's aes() function. The aes() function "parameterizes" a plot according to some aesthetics (see ?geom_linerange for an example of being able to parameterize in more than one way). Except having a special function like aes() might not be useful here, because the parameters can be specified right in the dst_*() call.

So, instead of:

dst_norm <- function(mean, variance) { ... }

we would have something like:

dst_norm <- function(mean, variance, ...)

akin to aes <- function(x, y, ...).

Calls would look something like:

dst_norm(0, 1)  # For mean and variance
dst_norm(0, stdev = 5) # For mean and standard deviation
dst_norm(0.05 ~ 100, 0.95 ~ 200) # For the 0.05- and 0.95-quantiles.
@vincenzocoia vincenzocoia added the future A feature to consider for future versions. label Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future A feature to consider for future versions.
Projects
None yet
Development

No branches or pull requests

1 participant