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

Remove downloads from {covidregionaldata} in R files #58

Merged
merged 8 commits into from
Jul 26, 2023
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
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ linters: linters_with_tags(
extraction_operator_linter = NULL,
todo_comment_linter = NULL,
function_argument_linter = NULL,
indentation_linter = NULL, # unstable as of lintr 3.1.0
# Use minimum R declared in DESCRIPTION or fall back to current R version
backport_linter(if (length(x <- etdev::extract_min_r_version())) x else getRversion())
)
27 changes: 15 additions & 12 deletions R/estimate_reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@
#' @export
#'
#' @examples
#' library(cfr)
#' library(epiparameter)
#' library(covidregionaldata)
#' # get data pre-loaded with {incidence2}
#' df_covid_uk <- incidence2::covidregionaldataUK
#'
#' df_covid_uk <- get_national_data(
#' countries = "united kingdom", source = "who", verbose = FALSE
#' # aggregate the covid data for the UK as a whole
#' df_covid_uk <- aggregate(
#' data = df_covid_uk,
#' x = cbind(cases_new, deaths_new) ~ date,
#' FUN = function(x) sum(x, na.rm = TRUE)
#' )
#'
#' # rename columns
#' colnames(df_covid_uk)[colnames(df_covid_uk) == "cases_new"] <- "cases"
#' colnames(df_covid_uk)[colnames(df_covid_uk) == "deaths_new"] <- "deaths"
#'
#' df_covid_uk_subset <- subset(df_covid_uk, date <= "2020-05-31")
#'
#' onset_to_death_covid <- epidist_db(
#' # load epidist object from {epiparameter}
#' onset_to_death_covid <- epiparameter::epidist_db(
#' disease = "COVID-19",
#' epi_dist = "onset_to_death",
#' author = "Linton_etal"
Expand Down Expand Up @@ -139,12 +143,11 @@ estimate_reporting <- function(data,
# here, the estimate called "severity_me" translates to "reporting_me"
# and the estimate "severity_hi" translates to "reporting_lo"
# TODO: check if this is correct
df_out <- data.frame(
reporting_me = df_out$severity_me,
reporting_lo = df_out$severity_hi,
reporting_hi = df_out$severity_lo
df_out <- as.data.frame(df_out,
row.names = NULL,
col.names = c("reporting_me", "reporting_hi", "reporting_lo")
)

# return data
df_out
# return data with columns in correct order
df_out[, c("reporting_me", "reporting_lo", "reporting_hi")]
}
38 changes: 27 additions & 11 deletions R/estimate_time_varying.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,48 @@
#' @export
#'
#' @examples
#' # load package data
#' data("ebola1976")
#' # get data pre-loaded with {incidence2}
#' df_covid_uk <- incidence2::covidregionaldataUK
#'
#' # get an onset to death distribution from the {epiparameter} package
#' onset_to_death_ebola <- epiparameter::epidist_db(
#' disease = "Ebola Virus Disease",
#' # aggregate the covid data for the UK as a whole
#' df_covid_uk <- aggregate(
#' data = df_covid_uk,
#' x = cbind(cases_new, deaths_new) ~ date,
#' FUN = function(x) sum(x, na.rm = TRUE)
#' )
#'
#' # rename columns
#' colnames(df_covid_uk)[colnames(df_covid_uk) == "cases_new"] <- "cases"
#' colnames(df_covid_uk)[colnames(df_covid_uk) == "deaths_new"] <- "deaths"
#'
#' df_covid_uk_subset <- subset(df_covid_uk, date <= "2020-05-31")
#'
#' # load epidist object from {epiparameter}
#' onset_to_death_covid <- epiparameter::epidist_db(
#' disease = "COVID-19",
#' epi_dist = "onset_to_death",
#' author = "Barry_etal"
#' author = "Linton_etal"
#' )
#'
#' # estimate time varying severity without correcting for delays
#' estimate_time_varying(
#' data = ebola1976,
#' cfr_time_varying <- estimate_time_varying(
#' data = df_covid_uk_subset,
#' smooth_inputs = TRUE,
#' burn_in_value = 7L,
#' correct_for_delays = FALSE
#' )
#' # View
#' tail(cfr_time_varying)
#'
#' # estimate time varying severity while correcting for delays
#' estimate_time_varying(
#' data = ebola1976,
#' epi_dist = onset_to_death_ebola,
#' cfr_time_varying <- estimate_time_varying(
#' data = df_covid_uk_subset,
#' epi_dist = onset_to_death_covid,
#' smooth_inputs = TRUE,
#' burn_in_value = 7L,
#' correct_for_delays = TRUE
#' )
#' tail(cfr_time_varying)
#'
estimate_time_varying <- function(data,
epi_dist = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/prepare_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ prepare_data <- function(data, ...) {
#' )
#'
#' # View head of prepared data
#' head(
#' tail(
#' prepare_data(
#' covid_uk_incidence,
#' cases_variable = "cases_new",
Expand Down
16 changes: 10 additions & 6 deletions man/estimate_reporting.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 27 additions & 11 deletions man/estimate_time_varying.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/prepare_data.incidence2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/estimate_reporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
Code
reporting_estimate
Output
reporting_me reporting_lo reporting_hi
73 0.014 0.014 0.56
reporting_me reporting_lo reporting_hi
1 0.014 0.014 0.56