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

Improve access to <distribution> names #398

Merged
merged 11 commits into from
Oct 21, 2024
Merged

Improve access to <distribution> names #398

merged 11 commits into from
Oct 21, 2024

Conversation

joshwlambert
Copy link
Member

This PR improves the access to distribution names in <distribution> objects from the {distributional} package by replacing the .get_mixture_dist() function with the more general .distributional_family() and enhancing family.epiparameter().

Using the new version of the <epiparameter> family() method, calls to stats::family() have been removed from the package, and is_truncated() has been simplified (#274).

The PR improves functions that were manually extracting the information from <distribution> objects by having to subset objects several times (e.g. discretise.epiparameter()) by now calling .distributional_family().

New tests are added for family.epiparameter() and .distributional_family().

@joshwlambert joshwlambert added the enhancement New feature or request label Oct 21, 2024
@joshwlambert
Copy link
Member Author

The improvements in the PR have also fixed a previously unknown bug when discretising <epiparameter> objects with a truncated lognormal distribution (I think the bug extended to any truncated probability distribution where the class name in the <distribution> object does not match the distribution name in R).

Here is a reprex using code from the main branch.

library(epiparameter)
ep = epiparameter(
  disease = "Disease", 
  epi_name = "SI", 
  prob_distribution = create_prob_distribution(
    prob_distribution = "lnorm", 
    prob_distribution_params = c(meanlog = 2, sdlog = 2), 
    truncation = 10)
)
#> Citation cannot be created as author, year, journal or title is missing
discretise(ep)
#> Warning: Discretising a truncated continuous distribution, returning
#> non-truncated discretised distribution
#> Error: Invalid parameterisation for lognormal distribution

Created on 2024-10-21 with reprex v2.1.0

Here is a reprex using code from the get_dist_class branch.

library(epiparameter)
ep = epiparameter(
  disease = "Disease", 
  epi_name = "SI", 
  prob_distribution = create_prob_distribution(
    prob_distribution = "lnorm", 
    prob_distribution_params = c(meanlog = 2, sdlog = 2), 
    truncation = 10)
)
#> Citation cannot be created as author, year, journal or title is missing
discretise(ep)
#> Warning: Discretising a truncated continuous distribution, returning
#> non-truncated discretised distribution
#> Disease: Disease
#> Pathogen: NA
#> Epi Parameter: si
#> Study: (????). "No citation."
#> Distribution: discrete lnorm
#> Parameters:
#>   meanlog: 2.000
#>   sdlog: 2.000

Created on 2024-10-21 with reprex v2.1.0

@joshwlambert joshwlambert merged commit 91c2950 into main Oct 21, 2024
8 checks passed
@joshwlambert joshwlambert deleted the get_dist_class branch October 21, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant