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

Major refactor of {epiparameter} #197

Merged
merged 72 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
eb6084e
updated parameter library JSON to modular objects
joshwlambert Sep 29, 2023
178818d
updated data dictionary to test modular parameter library
joshwlambert Sep 29, 2023
0a6669c
added enum to validate epi distributions and updated database to be v…
joshwlambert Sep 29, 2023
ed91b52
added .format_epidist function
joshwlambert Oct 2, 2023
31e277b
added .format_params function
joshwlambert Oct 2, 2023
102ee0c
added .read_epidist_db function
joshwlambert Oct 2, 2023
9261f4b
added .is_cond_epidist function
joshwlambert Oct 2, 2023
02ae1a1
updated epidist_db to read in from JSON db and work with list instead…
joshwlambert Oct 2, 2023
2d3ce8b
updated epidist_db documentation
joshwlambert Oct 2, 2023
4bba713
added print method for multi_epidist class
joshwlambert Oct 2, 2023
74bfa11
added has_r_params function and updated epidist constructor
joshwlambert Oct 2, 2023
e8ac648
updated epidist helper functions (removed outdated nesting)
joshwlambert Oct 2, 2023
6ef3784
added median and dispersion conversion to calc_dist_params
joshwlambert Oct 2, 2023
67ab1f2
updated calc_dist_params documentation
joshwlambert Oct 2, 2023
d959b55
removed outdated percentiles formatting in get_percentiles (no longer…
joshwlambert Oct 2, 2023
83bec18
updated create_epidist_summary_stats documentation
joshwlambert Oct 2, 2023
3f33977
removed epiparam functions (constructor, validator, print, format, is…
joshwlambert Oct 2, 2023
c0aa33d
removed epiparam_fields and epiparam_col_type functions
joshwlambert Oct 2, 2023
697d0a2
removed epiparam utility functions (as_epidist, make_epidist, as_epip…
joshwlambert Oct 2, 2023
8ec2c53
removed epiparam methods ([, names, $, epiparam_reconstruct, epiparam…
joshwlambert Oct 2, 2023
7741bc8
removed bind_epiparam function
joshwlambert Oct 2, 2023
ae58204
updated multi_epidist print method
joshwlambert Oct 2, 2023
48eca71
updated epidist_db documentation
joshwlambert Oct 2, 2023
93946cc
add filter by disease to .read_epidist_db
joshwlambert Oct 2, 2023
bae37cc
removed bind_epiparam tests
joshwlambert Oct 2, 2023
ae3e61a
removed epiparam tests
joshwlambert Oct 2, 2023
a2bfa83
removed epiparam utility function tests
joshwlambert Oct 2, 2023
8a3eb52
update epidist mean method for new summary stats list
joshwlambert Oct 3, 2023
df115ca
updated get_citation methods to work with multi_epidist and not epiparam
joshwlambert Oct 4, 2023
a2925eb
updated is_parameterised methods to work with multi_epidist and not e…
joshwlambert Oct 4, 2023
95ac6f4
get_citation inherits more params from is_parameterised
joshwlambert Oct 4, 2023
0fe4527
updated is_epidist_params to include functionality of has_r_params an…
joshwlambert Oct 4, 2023
ca47c79
updated name cleaning functions
joshwlambert Oct 4, 2023
15cc66a
removed check for NAs in param cleaning functions
joshwlambert Oct 4, 2023
c7774af
check if all quantiles are NA in create_epidist_summary_stats
joshwlambert Oct 4, 2023
10a7c2d
moved epidist db filtering into .filter_epidist_db
joshwlambert Oct 4, 2023
b739895
unpack single epidist in epidist_db and updated documentation
joshwlambert Oct 4, 2023
6759ce7
updated cleaning function name in epidist format method
joshwlambert Oct 4, 2023
b8b5e05
added more checks to epidist validator
joshwlambert Oct 4, 2023
4365399
restructured epidist constructor
joshwlambert Oct 4, 2023
95bbcbf
rewrote list_distributions to work with new db and data structures, a…
joshwlambert Oct 4, 2023
59a4e1c
updated Lloyd-Smith et al entries in db to use nbinom and params as r…
joshwlambert Oct 4, 2023
fbcf4dc
updated get_percentiles documentation to use new naming convention
joshwlambert Oct 4, 2023
e4a85b4
updated calc_dist_params if statements and documentation
joshwlambert Oct 4, 2023
964646b
updated NAMESPACE
joshwlambert Oct 4, 2023
e332a5f
always use snake_case var names
joshwlambert Oct 4, 2023
5012804
fixed is_epidist_params example
joshwlambert Oct 4, 2023
3f5eefa
updated accessors tests
joshwlambert Oct 4, 2023
09408ce
fixed bug in epidist_db when single_epidist = TRUE
joshwlambert Oct 9, 2023
8338a4a
updated README
joshwlambert Oct 9, 2023
cb362b9
updated epiparameter vignette
joshwlambert Oct 9, 2023
2abbb79
updated data_protocol vignette
joshwlambert Oct 9, 2023
3069a88
fix handling of NULL mean in mean.epidist
joshwlambert Oct 9, 2023
32e6cdb
params can be match subset in is_epidist_params
joshwlambert Oct 9, 2023
c7d5584
suppress epidist_db message in list_distributions
joshwlambert Oct 9, 2023
9374b8d
updated epidist documentation
joshwlambert Oct 9, 2023
0c3339d
updated spelling and documentation
joshwlambert Oct 9, 2023
2610e3b
updated _pkgdown yaml
joshwlambert Oct 9, 2023
3e590b7
styling and linting
joshwlambert Oct 10, 2023
fd471ef
updated tests and snaps
joshwlambert Oct 10, 2023
ad59aa0
Automatic readme update
actions-user Oct 10, 2023
b74b31f
linting
joshwlambert Oct 10, 2023
d0ca999
reposition nolint flag in list_distributions
joshwlambert Oct 10, 2023
412a57a
updated snapshots
joshwlambert Oct 10, 2023
8c34eea
use checkmate to simplify if statements in calc_dist_params
joshwlambert Nov 10, 2023
5d601d8
replaced logical statements with checkmate in validate_epidist
joshwlambert Nov 13, 2023
2c6b041
updated list assertion for epidist summary stats
joshwlambert Nov 13, 2023
1582803
added american spelling for is_parameterised and discretise functions
joshwlambert Nov 13, 2023
fb6503c
remove duplicated epidist prob_dist check in validate_epidist
joshwlambert Nov 13, 2023
ed39ed9
return numeric NA in mean.epidist
joshwlambert Nov 13, 2023
065e1ba
replace test_character with test_string when scalar character
joshwlambert Nov 13, 2023
b2fea45
check for finite parameters and positive sample size in calc_dist_params
joshwlambert Nov 13, 2023
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
23 changes: 4 additions & 19 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
# Generated by roxygen2: do not edit by hand

S3method("$<-",epiparam)
S3method("[",epiparam)
S3method("names<-",epiparam)
S3method(cdf,epidist)
S3method(cdf,vb_epidist)
S3method(density,epidist)
S3method(density,vb_epidist)
S3method(discretise,default)
S3method(discretise,epidist)
S3method(dplyr::dplyr_reconstruct,epiparam)
S3method(family,epidist)
S3method(format,epidist)
S3method(format,epiparam)
S3method(format,vb_epidist)
S3method(generate,epidist)
S3method(generate,vb_epidist)
S3method(get_citation,epidist)
S3method(get_citation,epiparam)
S3method(get_citation,multi_epidist)
S3method(get_parameters,epidist)
S3method(head,epiparam)
S3method(is_parameterised,epidist)
S3method(is_parameterised,epiparam)
S3method(is_parameterised,multi_epidist)
S3method(mean,epidist)
S3method(plot,epidist)
S3method(plot,vb_epidist)
S3method(print,epidist)
S3method(print,epiparam)
S3method(print,multi_epidist)
S3method(print,vb_epidist)
S3method(quantile,epidist)
S3method(quantile,vb_epidist)
S3method(summary,epiparam)
S3method(tail,epiparam)
export(as_epidist)
export(as_epiparam)
export(bind_epiparam)
export(calc_disc_dist_quantile)
export(clean_disease)
export(clean_epidist_name)
export(clean_epi_dist)
export(convert_params_to_summary_stats)
export(convert_summary_stats_to_params)
export(create_epidist_citation)
Expand All @@ -49,13 +38,11 @@ export(create_epidist_uncertainty)
export(discretise)
export(epidist)
export(epidist_db)
export(epiparam)
export(extract_param)
export(get_citation)
export(get_parameters)
export(is_epidist)
export(is_epidist_params)
export(is_epiparam)
export(is_parameterised)
export(is_truncated)
export(is_vb_epidist)
Expand All @@ -68,5 +55,3 @@ importFrom(distributional,generate)
importFrom(stats,density)
importFrom(stats,family)
importFrom(stats,quantile)
importFrom(utils,head)
importFrom(utils,tail)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Initial release of {epiparameter}, an R package to work with epidemiological par
* The package contains a few utility functions.
* Four vignettes are included in this initial release. One as an introduction to the package (`epiparameter.Rmd`), one as an tutorial on converting and extracting parameters (`extract_convert.Rmd`), one on the protocol used to collect entries for the library of epidemiological parameters (`data_protocol.Rmd`) and a supplementary vignette which quantifies the bias from using the parameter extraction (`extract_param()`) from {epiparameter} (`extract-bias.Rmd`).
* Unit tests and documentation files.
* Continuous integration workflows for R package checks, rendering the README.md, calculating test coverage, deploying the pkgdown website, updates the package citation, and validatingt the parameter library JSON file.
* Continuous integration workflows for R package checks, rendering the README.md, calculating test coverage, deploying the pkgdown website, updates the package citation, and validating the parameter library JSON file.

## Breaking changes

Expand Down
46 changes: 13 additions & 33 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,30 @@ get_parameters.epidist <- function(x, ...) {
params
}

#' Extract citation information from `<epidist>` or `<epiparam>` objects
#' Extract citation information from `<epidist>` or list of `<epidist>` objects
#'
#' @param x An `<epidist>` or `<epiparam>` object.
#' @param ... Extra arguments to be passed to the method.
#' @inheritParams is_parameterised
#'
#' @return A single character string or list of character string citations.
#' Length of list output is equal to number of rows in the `<epiparam>` object
#' passed to the function.
#' Length of list output is equal to number of elements in the `<epidist>`
#' object passed to the function.
#' @export
#'
#' @examples
#'
#' # example with epidist
#' eparam <- epiparam()
#' edist <- as_epidist(eparam[12, ])
#' # example with <epidist>
#' edist <- epidist_db(single_epidist = TRUE)
#' get_citation(edist)
#'
#' # example with epiparam
#' eparam <- epiparam()
#' get_citation(eparam)
#' # example with list of <epidist>
#' edist <- epidist_db()
#' get_citation(edist)
get_citation <- function(x, ...) {
UseMethod("get_citation")
}

#' @export
get_citation.epidist <- function(x, ...) {
chkDots(...)
if (!inherits(x$citation, "bibentry")) {
stop("Citation should be a <bibentry>", call. = FALSE)
}
Expand All @@ -80,27 +78,9 @@ get_citation.epidist <- function(x, ...) {
}

#' @export
get_citation.epiparam <- function(x, ...) {
citation_list <- apply(x,
MARGIN = 1, FUN = function(y) {
# suppressing message as users do not need reminding of citation when
# retrieving citation
suppressMessages(
create_epidist_citation(
author = y$author,
year = y$year,
title = y$title,
journal = y$journal,
DOI = y$DOI,
PMID = y$PMID
)
)
},
simplify = FALSE
)

# remove names from list
citation_list <- unname(citation_list)
get_citation.multi_epidist <- function(x, ...) {
chkDots(...)
citation_list <- lapply(x, get_citation)

# return citation list
citation_list
Expand Down
80 changes: 0 additions & 80 deletions R/bind_epiparam.R

This file was deleted.

49 changes: 35 additions & 14 deletions R/calc_dist_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' calc_dist_params(
#' prob_dist = "gamma",
#' summary_stats = create_epidist_summary_stats(
#' quantiles = c(q_2.5 = 0.2, q_97.5 = 9.2)
#' quantiles = c("2.5" = 0.2, "97.5" = 9.2)
#' ),
#' sample_size = NA
#' )
Expand All @@ -47,26 +47,41 @@
#' sample_size = 25
#' )
#' }
calc_dist_params <- function(prob_dist,
calc_dist_params <- function(prob_dist, # nolint cyclocomp
prob_dist_params,
summary_stats,
sample_size = NA) {
# extract mean and sd to see if conversion is possible
mean_sd <- c(
mean = summary_stats$centre_spread$mean,
sd = summary_stats$centre_spread$sd
)
sample_size) {
if (is.na(prob_dist)) {
message(
"No adequate summary statistics available to calculate the parameters ",
"of the ", prob_dist, " distribution"
)
return(NA)
}

# convert percentile names to numbers
percentiles <- get_percentiles(summary_stats$quantiles)
if (!is.null(summary_stats$quantiles) &&
!all(is.na(summary_stats$quantiles))) {
# convert percentile names to numbers
percentiles <- get_percentiles(summary_stats$quantiles)
} else {
percentiles <- NA
}

# extract median and range to calculate parameters as third choice
median_range <- c(
median = summary_stats$centre_spread$median,
median = summary_stats$median,
unlist(summary_stats$range)
)

if (!anyNA(mean_sd)) {
# unlist and remove NAs
# extract dispersion
disp <- unname(prob_dist_params[names(prob_dist_params) == "dispersion"])
median_disp <- c(median = summary_stats$median, dispersion = disp)

# extract mean and sd
mean_sd <- c(summary_stats$mean, summary_stats$sd)

# convert from mean and sd
if (all(is.numeric(mean_sd)) && !anyNA(mean_sd) && length(mean_sd) == 2) {
summary_stats_ <- unlist(summary_stats)
summary_stats_ <- summary_stats_[!is.na(summary_stats_)]
# remove name prefixes from unlisting
Expand All @@ -87,6 +102,11 @@ calc_dist_params <- function(prob_dist,
convert_summary_stats_to_params,
args = args
))
} else if (all(is.numeric(median_disp) && length(median_disp) == 2)) {
med <- summary_stats$median
meanlog <- log(med / sqrt(1 + disp^2))
sdlog <- sqrt(log(1 + disp^2))
prob_dist_params <- c(meanlog = meanlog, sdlog = sdlog)
} else if (!anyNA(percentiles)) {
# calculate the parameters from the percentiles
# percentiles required to be [0, 1] so divide by 100
Expand All @@ -96,7 +116,8 @@ calc_dist_params <- function(prob_dist,
distribution = prob_dist,
percentiles = as.numeric(names(percentiles)) / 100
)
} else if (!anyNA(median_range) && !is.na(sample_size)) {
} else if (all(is.numeric(median_range)) && length(median_range) == 3 &&
!is.na(sample_size)) {
prob_dist_params <- extract_param(
type = "range",
values = median_range,
Expand Down
Loading