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

Rename <epidist> with <epiparameter> #360

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Imports:
distcrete,
distributional,
graphics,
lifecycle,
pillar,
rlang,
stats,
Expand All @@ -53,4 +54,4 @@ Encoding: UTF-8
Language: en-GB
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
70 changes: 36 additions & 34 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,epidist)
S3method(as.data.frame,multi_epidist)
S3method(as.function,epidist)
S3method(as_epidist,data.frame)
S3method(cdf,epidist)
S3method(as.data.frame,epiparameter)
S3method(as.data.frame,multi_epiparameter)
S3method(as.function,epiparameter)
S3method(as_epiparameter,data.frame)
S3method(cdf,epiparameter)
S3method(convert_params_to_summary_stats,character)
S3method(convert_params_to_summary_stats,epidist)
S3method(convert_params_to_summary_stats,epiparameter)
S3method(convert_summary_stats_to_params,character)
S3method(convert_summary_stats_to_params,epidist)
S3method(density,epidist)
S3method(convert_summary_stats_to_params,epiparameter)
S3method(density,epiparameter)
S3method(discretise,default)
S3method(discretise,epidist)
S3method(family,epidist)
S3method(format,epidist)
S3method(generate,epidist)
S3method(get_citation,epidist)
S3method(get_citation,multi_epidist)
S3method(get_parameters,epidist)
S3method(is_parameterised,epidist)
S3method(is_parameterised,multi_epidist)
S3method(mean,epidist)
S3method(plot,epidist)
S3method(print,epidist)
S3method(print,multi_epidist)
S3method(discretise,epiparameter)
S3method(family,epiparameter)
S3method(format,epiparameter)
S3method(generate,epiparameter)
S3method(get_citation,epiparameter)
S3method(get_citation,multi_epiparameter)
S3method(get_parameters,epiparameter)
S3method(is_parameterised,epiparameter)
S3method(is_parameterised,multi_epiparameter)
S3method(mean,epiparameter)
S3method(plot,epiparameter)
S3method(print,epiparameter)
S3method(print,multi_epiparameter)
S3method(print,parameter_tbl)
S3method(quantile,epidist)
S3method(quantile,epiparameter)
S3method(tbl_sum,p_tbl)
export(as_epidist)
export(as_epiparameter)
export(calc_disc_dist_quantile)
export(cdf)
export(convert_params_to_summary_stats)
export(convert_summary_stats_to_params)
export(create_epidist_citation)
export(create_epidist_metadata)
export(create_epidist_method_assess)
export(create_epidist_prob_dist)
export(create_epidist_region)
export(create_epidist_summary_stats)
export(create_epidist_uncertainty)
export(create_citation)
export(create_metadata)
export(create_method_assess)
export(create_prob_dist)
export(create_region)
export(create_summary_stats)
export(create_uncertainty)
export(discretise)
export(discretize)
export(epidist)
export(epidist_db)
export(epiparameter)
export(epiparameter_db)
export(extract_param)
export(generate)
export(get_citation)
export(get_parameters)
export(is_continuous)
export(is_epidist)
export(is_epidist_params)
export(is_epiparameter)
export(is_epiparameter_params)
export(is_parameterised)
export(is_parameterized)
export(is_truncated)
export(parameter_tbl)
export(validate_epidist)
export(validate_epiparameter)
importFrom(distributional,cdf)
importFrom(distributional,generate)
importFrom(lifecycle,deprecated)
importFrom(pillar,tbl_sum)
importFrom(stats,density)
importFrom(stats,family)
Expand Down
61 changes: 31 additions & 30 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ get_parameters <- function(x, ...) {
UseMethod("get_parameters")
}

#' Get parameters from an `<epidist>` object
#' Get parameters from an `<epiparameter>` object
#'
#' Extract the parameters of the distribution stored in an `<epidist>` object.
#' Extract the parameters of the distribution stored in an `<epiparameter>`
#' object.
#'
#' @details The `<epidist>` object can be unparameterised in which it lacks
#' @details The `<epiparameter>` object can be unparameterised in which it lacks
#' a probability distribution or parameters of a probability distribution,
#' in this case the `get_parameters.epidist()` method will return `NA`.
#' in this case the `get_parameters.epiparameter()` method will return `NA`.
#'
#' @inheritParams print.epidist
#' @inheritParams print.epiparameter
#' @param ... [dots] Not used, extra arguments supplied will cause a warning.
#'
#' @return A named vector of parameters or `NA` when the `<epidist>` object is
#' unparameterised.
#' @return A named vector of parameters or `NA` when the `<epiparameter>`
#' object is unparameterised.
#' @export
#'
#' @examples
#' edist <- epidist_db(
#' ep <- epiparameter_db(
#' disease = "COVID-19",
#' epi_dist = "serial interval",
#' single_epidist = TRUE
#' single_epiparameter = TRUE
#' )
#' get_parameters(edist)
get_parameters.epidist <- function(x, ...) {
#' get_parameters(ep)
get_parameters.epiparameter <- function(x, ...) {
chkDots(...)
# extract parameters depending on prob distribution class
if (inherits(x$prob_dist, "distcrete")) {
Expand All @@ -51,7 +52,7 @@ get_parameters.epidist <- function(x, ...) {
}

# convert to meanlog and sdlog names
params <- .clean_epidist_params(
params <- .clean_params(
prob_dist = family(x),
prob_dist_params = params
)
Expand All @@ -75,26 +76,26 @@ get_citation <- function(x, ...) {
UseMethod("get_citation")
}

#' Get citation from an `<epidist>` object
#' Get citation from an `<epiparameter>` object
#'
#' Extract the citation stored in an `<epidist>` object.
#' Extract the citation stored in an `<epiparameter>` object.
#'
#' @inheritParams print.epidist
#' @inheritParams print.epiparameter
#' @param ... [dots] Not used, extra arguments supplied will cause a warning.
#'
#' @return A `<bibentry>` object.
#' @export
#'
#' @examples
#' # example with <epidist>
#' edist <- epidist_db(single_epidist = TRUE)
#' get_citation(edist)
#' # example with <epiparameter>
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' get_citation(ep)
#'
#' # example returning bibtex format
#' edist <- epidist_db(disease = "COVID-19", single_epidist = TRUE)
#' cit <- get_citation(edist)
#' ep <- epiparameter_db(disease = "COVID-19", single_epiparameter = TRUE)
#' cit <- get_citation(ep)
#' format(cit, style = "bibtex")
get_citation.epidist <- function(x, ...) {
get_citation.epiparameter <- function(x, ...) {
chkDots(...)
if (!inherits(x$citation, "bibentry")) {
stop("Citation should be a <bibentry>", call. = FALSE)
Expand All @@ -104,25 +105,25 @@ get_citation.epidist <- function(x, ...) {
x$citation
}

#' Get citation from a list of `<epidist>` objects
#' Get citation from a list of `<epiparameter>` objects
#'
#' Extract the citation stored in a list of `<epidist>` objects.
#' Extract the citation stored in a list of `<epiparameter>` objects.
#'
#' @inheritParams print.epidist
#' @inheritParams print.epiparameter
#' @param ... [dots] Not used, extra arguments supplied will cause a warning.
#'
#' @return A `<bibentry>` object containing multiple references. The length of
#' output `<bibentry>` is equal to the length of the list of `<epidist>`
#' output `<bibentry>` is equal to the length of the list of `<epiparameter>`
#' objects supplied.
#' @export
#'
#' @examples
#' # example with list of <epidist>
#' edist <- epidist_db()
#' get_citation(edist)
get_citation.multi_epidist <- function(x, ...) {
#' # example with list of <epiparameter>
#' db <- epiparameter_db()
#' get_citation(db)
get_citation.multi_epiparameter <- function(x, ...) {
chkDots(...)
# dispatches to get_citation.epidist method
# dispatches to get_citation.epiparameter method
citation_list <- lapply(x, get_citation)
# dispatches to c.bibentry method
multi_bibentry <- Reduce(f = c, x = citation_list)
Expand Down
4 changes: 2 additions & 2 deletions R/calc_dist_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#' provided the lowest value is used for the calculation.
#' 3. The last method is the extraction using a median and range of the data.
#'
#' @inheritParams new_epidist
#' @inheritParams epidist
#' @inheritParams new_epiparameter
#' @inheritParams epiparameter
#' @param sample_size The sample size of the data. Only needed when falling back
#' on using the median-range extraction calculation.
#'
Expand Down
37 changes: 19 additions & 18 deletions R/checkers.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
#' Check if `<epidist>` or list of `<epidist>` objects contains a distribution
#' and distribution parameters
#' Check if `<epiparameter>` or list of `<epiparameter>` objects contains a
#' distribution and distribution parameters
#'
#' @param x An `<epidist>` or list of `<epidist>` objects.
#' @param x An `<epiparameter>` or list of `<epiparameter>` objects.
#' @param ... [dots] Extra arguments to be passed to the method.
#'
#' @return A single boolean `logical` for `<epidist>` or vector of `logical`s
#' equal in length to the list of `<epidist>` objects input. If the `<epidist>`
#' object is missing either a probability distribution or parameters for
#' the probability distribution returns `FALSE`, otherwise it returns `TRUE`.
#' @return A single boolean `logical` for `<epiparameter>` or vector of
#' `logical`s equal in length to the list of `<epiparameter>` objects input.
#' If the `<epiparameter>` object is missing either a probability distribution
#' or parameters for the probability distribution returns `FALSE`, otherwise it
#' returns `TRUE`.
#' @export
#'
#' @examples
#' # parameterised <epidist>
#' edist <- epidist(
#' # parameterised <epiparameter>
#' ep <- epiparameter(
#' disease = "ebola",
#' epi_dist = "incubation",
#' prob_distribution = "gamma",
#' prob_distribution_params = c(shape = 1, scale = 1)
#' )
#' is_parameterised(edist)
#' is_parameterised(ep)
#'
#' # unparameterised <epidist>
#' edist <- epidist(
#' # unparameterised <epiparameter>
#' ep <- epiparameter(
#' disease = "ebola",
#' epi_dist = "incubation"
#' )
#' is_parameterised(edist)
#' is_parameterised(ep)
#'
#' # list of <epidist>
#' edist <- epidist_db()
#' is_parameterised(edist)
#' # list of <epiparameter>
#' db <- epiparameter_db()
#' is_parameterised(db)
is_parameterised <- function(x, ...) {
UseMethod("is_parameterised")
}
Expand All @@ -39,14 +40,14 @@ is_parameterised <- function(x, ...) {
is_parameterized <- is_parameterised

#' @export
is_parameterised.epidist <- function(x, ...) {
is_parameterised.epiparameter <- function(x, ...) {
chkDots(...)
# probability distribution object
return(is.object(x$prob_dist))
}

#' @export
is_parameterised.multi_epidist <- function(x, ...) {
is_parameterised.multi_epiparameter <- function(x, ...) {
chkDots(...)

# return logical vector
Expand Down
Loading