-
Notifications
You must be signed in to change notification settings - Fork 11
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
Update epidist_db()
to give more fine-grained control
#160
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bc02ce7
added subset and single_epidist arguments to epidist_db, WIP #91
joshwlambert cce3195
added tests for new epidist_db subset and single_epidist arguments, W…
joshwlambert 6eb6a90
cleaner printing from multiple epidist from epidist_db, WIP #163
joshwlambert 66bc8cd
epidist_db single_epidist now select on parameterisation and sample s…
joshwlambert 514f124
made is_parameterised a generic and moved to new file
joshwlambert f077210
added functional subsetting to epidist_db, WIP #163
joshwlambert 333b4a4
only subset by parameterised entries if there is at least one in epid…
joshwlambert 3dd9221
improved validate_epidist
joshwlambert 8ded277
added tests for is_parameterised
joshwlambert 3dcc49f
updated epidist_db documentation and tests, closes #163
joshwlambert 0a11238
updated epidist_db documentation, relates #163
joshwlambert 9722865
rm browser() from epidist_db
joshwlambert cbc0e98
linting
joshwlambert a053a42
fixed epidist test
joshwlambert 0ad700b
updated epidist_db documentation and added epidist validation, relate…
joshwlambert 240c42f
reduced hardcoding in checkers tests
joshwlambert 0e71b8f
fixed is_parameterised test
joshwlambert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#' Checks whether <epidist> or <epiparam> object contains a distribution and | ||
#' parameters for that distribution. | ||
#' | ||
#' @description If the <epidist> object or a row in the <epiparam> data frame | ||
#' is missing either a probability distribution or parameters for the | ||
#' probability distribution, `is_parameterised` returns `FALSE`, otherwise | ||
#' it returns `TRUE`. | ||
#' | ||
#' @param x An `epidist` or `epiparam` object. | ||
#' @param ... [`dots`] not used, extra arguments supplied will cause a warning. | ||
#' | ||
#' @return A boolean logical for <epidist> or vector of boolean for each entry | ||
#' in the <epiparam>. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' # parameterised <epidist> | ||
#' edist <- epidist( | ||
#' disease = "ebola", | ||
#' epi_dist = "incubation", | ||
#' prob_distribution = "gamma", | ||
#' prob_distribution_params = c(shape = 1, scale = 1) | ||
#' ) | ||
#' is_parameterised(edist) | ||
#' | ||
#' # unparameterised <epidist> | ||
#' edist <- epidist( | ||
#' disease = "ebola", | ||
#' epi_dist = "incubation" | ||
#' ) | ||
#' is_parameterised(edist) | ||
is_parameterised <- function(x, ...) { | ||
UseMethod("is_parameterised") | ||
} | ||
|
||
#' @export | ||
is_parameterised.epiparam <- function(x, ...) { | ||
|
||
chkDots(...) | ||
|
||
has_params <- vapply( | ||
as.data.frame(t(x)), | ||
FUN = function(y) { | ||
if (is.na(y$prob_distribution)) { | ||
return(FALSE) | ||
} | ||
if (y$prob_distribution %in% c("gamma", "weibull")) { | ||
out <- !is.na(y$shape) && !is.na(y$scale) | ||
return(out) | ||
} | ||
if (y$prob_distribution == "lnorm") { | ||
out <- !is.na(y$meanlog) && !is.na(y$sdlog) | ||
return(out) | ||
} | ||
if (y$prob_distribution == "nbinom") { | ||
out <- !is.na(y$mean) && !is.na(y$dispersion) | ||
return(out) | ||
} | ||
if (y$prob_distribution %in% c("geom", "pois")) { | ||
out <- !is.na(y$mean) | ||
return(out) | ||
} | ||
return(FALSE) | ||
}, | ||
FUN.VALUE = logical(1), | ||
USE.NAMES = FALSE | ||
) | ||
joshwlambert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# return result | ||
has_params | ||
} | ||
|
||
#' @export | ||
is_parameterised.epidist <- function(x, ...) { | ||
|
||
chkDots(...) | ||
|
||
# probability distribution object | ||
if (is.object(x$prob_dist)) { | ||
return(TRUE) | ||
} | ||
|
||
return(FALSE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is exported, would it be possible to add in the description or in the examples a typical use case for users? At the moment, I can only think about internal use cases.