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

Refactor internal parameter cleaning #331

Merged
merged 18 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d4a3e22
update clean_epidist_params to use switch and do.call instead of S3 d…
joshwlambert Jun 4, 2024
e27afae
updated clean_epidist_params functions documentation
joshwlambert Jun 4, 2024
981a9af
update clean_epidist_params calls in accessors and new_epidist
joshwlambert Jun 4, 2024
a715fbe
updated clean_epidist_params tests
joshwlambert Jun 4, 2024
5ad33df
add bullet point to design principles vignette on S3 dispatch vs swit…
joshwlambert Jun 4, 2024
1e2a570
add bullet point on dot prefix for internal functions to design princ…
joshwlambert Jun 4, 2024
c1a4e42
add dot prefix to clean_epidist_params and clean_epidist_params_* fun…
joshwlambert Jun 4, 2024
ca70703
update .clean_epidist_params documentation to group all .clean_epidis…
joshwlambert Jun 4, 2024
794d4fd
add probability distribution name for more informative error in .clea…
joshwlambert Jun 4, 2024
d7c5dd4
add "lambda" as possible parameterisation for poisson distribution in…
joshwlambert Jun 4, 2024
d46abae
fixed error messages from .clean_epidist_params in unit tests
joshwlambert Jun 4, 2024
cffbe5e
enforce stricter parameter matching in is_epidist_params
joshwlambert Jun 5, 2024
0c0dac7
remove .clean_epidist_params_weibull as it only has one parameterisation
joshwlambert Jun 5, 2024
4213a25
simplify .clean_epidist_params_* functions logic with after stricter …
joshwlambert Jun 5, 2024
221c7f4
fix is_epidist_params and .clean_epidist_params to work with truncate…
joshwlambert Jun 5, 2024
8542f82
only append mean to prob_dist_params if in set of dists in new_epidist
joshwlambert Jun 10, 2024
48167ac
slightly increase tolerance in expect_equal for .read.epidist_db test
joshwlambert Jun 10, 2024
5387f70
updated .clean_epidist_params documentation
joshwlambert Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ get_parameters.epidist <- function(x, ...) {
}

# convert to meanlog and sdlog names
class(params) <- family(x)
params <- clean_epidist_params(prob_dist_params = params)
params <- .clean_epidist_params(
prob_dist = family(x),
prob_dist_params = params
)
} else {
return(NA)
}
Expand Down
17 changes: 8 additions & 9 deletions R/epidist.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,17 @@ new_epidist <- function(disease = character(),
identical(names(prob_dist_params), names(uncertainty))
)

# TODO: formalise if statement below or remove
# include mean in prob_dist_params
if (!is.null(summary_stats$mean) && !is.na(summary_stats$mean)) {
prob_dist_params <- c(
prob_dist_params[!is.na(prob_dist_params)],
mean = summary_stats$mean
)
if (!is.null(summary_stats$mean) && !is.na(summary_stats$mean) &&
prob_dist %in% c("nbinom", "geom", "pois", "norm")) {
prob_dist_params["mean"] <- summary_stats$mean
}

if (is_epidist_params(prob_dist, prob_dist_params)) {
# standardise common distribution parameters
class(prob_dist_params) <- prob_dist
prob_dist_params <- clean_epidist_params(
prob_dist_params <- .clean_epidist_params(
prob_dist = prob_dist,
prob_dist_params = prob_dist_params
)
} else if (auto_calc_params) {
Expand Down Expand Up @@ -728,8 +727,8 @@ discretise.epidist <- function(x, ...) {
}

# standardise distribution parameter names
class(prob_dist_params) <- prob_dist
prob_dist_params <- clean_epidist_params(
prob_dist_params <- .clean_epidist_params(
prob_dist = prob_dist,
prob_dist_params = prob_dist_params
)

Expand Down
Loading
Loading