Skip to content

Commit

Permalink
Issue 215: Merge main to spatial (#224)
Browse files Browse the repository at this point in the history
* Adding class and methods for wwinference model fit (#58)

* Starting off refactoring (expected to fail) [skip ci]

* Adding new method

* Fixing bug in fit_model (was exploiting scoping)

* Updating docs (fixing S3 methods)

* 49 output class creation (#59)

* add a space

* add first test of first check

* add tests for all of the check/assert functions

* run precommit

* check bug in passing output of checkmate to cliabort

* initial tests of preprocess_ww_data

* add custum utils function for autoescaping brackets to pass to glue

* add a bunch of tests for preprocessing wastewater data

* add one more test of site lab indexing

* fix bugs caught in CI

* fix lab site spacing

* fix spacing in name again

* add test to hospital admissions preprocessing

* add additional test to ensure character to indexing of sites and labs

* remove bug in expected number of unique lab site indices

* add tests to make sure data is daily and test to checkers

* add a bunch of validation checks to the joint datasets and the user specifications

* replace with new way of getting stan data

* fix examples, add test, add warning

* fix examples, add test, add warning

* change from hosp -> count everywhere except stan and  vignette/examples

* add tests for pmfs

* fix bugs in documentation

* add padding value as a function arg

* change pmf size check to a warning not an error

* fix bug

* make initialization function more generic

* update changelog

* modify to test

* fix typo from merge

* fix parsing of cmdstan object

* change parsing of fit obj

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* some tweaks to checkers

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* fix documentation

* fix typo

* fix typo

* change outputs from wwinference() function

* fix typos, add documentation

* fix bug missing stan args

* exclude t columns in data join

* fix vignette bug

* add the ww_output documentation

* document ...

* fix missing comma

* move documentation of params around

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* change syntax and filenames

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/wwinference.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/wwinference.R

Co-authored-by: Dylan H. Morris <[email protected]>

* change naming and internal checking

* change syntax

* move around documentation

* fix check

* fix tests, fix documentation

* rename assert function to specify within a certain frame

* add element to text

* fix bug in function name

* tweak to inference function

* fix two bugs

* adjust tests based on updated get stan data function which breaks up generation of input data

* Update get_stan_data.R example

* update documentation after fixing example

* add example to wwinference wrapper function

* attempt to move around documentation for wwinference methods

* play around with the documentation of the default and the S3 method functions

* export S3 method function

* add back in exporting functions to get input data formatted for stan

* make first argument of function have same name as class object

* fix bug in how max generation time is found

* update vignette to explain wwinference_fit class object vs explicit function calling, add diagnostics and show both ways

* fix naming blocks adding comma when needed

* dont export autoescape brackets function

* fix same bug

* update test and preprocessing to count at LOD values at below LOD

* fix internal call to diagnostic flags function

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* implement DMs suggestions

* run pre-commit

* export default functions

* Add test-coverage.yaml from epinowcast

* remove test coverage

* remove example, function not exported

* export default function

* export both diagnostics functions

* add documentation of additional arguments

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_ww_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* manually input some suggestions

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* add more checknames

* run pre-commit locally

* fix typo

* add some very minimal tests

* fix wwinference function

* fix bug

* fix bug

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* run pre-commit locally

* fix bugs in tests

* fix error in tests

* move forecast date, calib time, horizon time to args to wrapper function

* fix hosp only example in vignette

* fix error in example

* add dont run to examples

* check -> expect in checkmate, confirm tests pass locally

---------

Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: George G. Vega Yon <[email protected]>

* Making pre-commit happy

* Reworking cross-references and print method

* Removing copy of fit_model

* Fixing function call

* Addressing PR comments

* Forgot to save some changes

* Change output names (#86)

* change names of outputs of wwinference wrapper function

* fix a few other missed replacements

* fix pre-commit

* Fixing R CMD check

* Pre-commit

* Removing diagnostics_summary

---------

Co-authored-by: George G. Vega Yon <[email protected]>

* Update vignettes/wwinference.Rmd

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Update vignettes/wwinference.Rmd

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Adding example of summary and print in the vignette. Addressing some minor comments

* fix test for expected names after changing function args

* set seed in tests

---------

Co-authored-by: Kaitlyn Johnson <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: kaitejohnson <[email protected]>

* Addressing R CMD check notes due to tidyeval syntax (#108)

* Starting to use .data and others

* Removing more warnings

* Think almost all issues are now solved

* License warning and passing params as expected

* Removing  prefix

* Fixing note on license and news file

* Using str2lang in spread_draws

* Update R/get_draws_df.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Fixing R CMD check

* fixed intercept in figures

* Update R/generate_simulated_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Apply suggestions from code review by @dylanhmorris

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/get_stan_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* remove call to utils::globalVariables()

* Update R/preprocessing.R

* Update R/generate_simulated_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/get_stan_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

---------

Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Kaitlyn Johnson <[email protected]>
Co-authored-by: kaitejohnson <[email protected]>

* update hierarchical estimate of sigma_site in `model_definition` (#120)

* add a space

* update hierarchical estimate of sigma_site

* update prior table

* run pre-commit

* update comment when transforming to site level standard deviations

* add to change log

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* update notation for mode and sd of stdevs

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* tweaks to formatting

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

---------

Co-authored-by: Dylan H. Morris <[email protected]>

* Vignette tweaks (#141)

* fix typo in indicate ww exclusions documentation

* fix typos/language in vignette

* Update R/preprocessing.R

Co-authored-by: Chirag Kumar <[email protected]>

* update docs

---------

Co-authored-by: Chirag Kumar <[email protected]>

* actually set seed

* Set seeds in test_get_stan_data (#146)

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Modify package to expect log scale concentration values and LODs (#122)

* Tweaks to model definition (#134)

* Fix check for required wastewater columns (#127)

* Switch to placing prior on and inferring `i/n` at the first observed timepoint (#85)

* update vignette to reflect default NULL seed in mcmcoptions (#125)

* Fix NEWS.md (#126)

* hot fix to readme

* Update NEWS.md

* run pre-commit

* Update NEWS.md (#144)

* run pre-commit locally

* Update NEWS.md

---------

Co-authored-by: George G. Vega Yon <[email protected]>

* Update DESCRIPTION (#156)

* Adding new class and method for get_draws (#153)

* Adding new class and method (expected to fail)

* Addressing issues with names (expected to fail)

* Adding the what parameter to the docs

* Addressing final bits. Now need the test

* Adding plot method as a wrapper

* Adding some tests

* Fixing test and setting default y=NULL in plot

* Adding some lines in the vignette to explain the plot method works on wwinference_fit_draws

* Addressing review comments

* Typo in length function

* Reverting R/sysdata.rda and ensuring tests run properly

* Reverting sysdata (again)

* Better print and fixing test

* Fixing tests

* Add contributors (#160)

* 163 expand R version  (#164)

* Add hex logo to repo (#148)

* update readme with logo

* swap to svg

* use use package

* adjust size and remove extra text

* try adding new logo

* fix title

* fix title again

* delete old logos

* Various bug fixes (#128)

* fix rendering to katex, add mathcal Rt to vignette (#169)

* Tweaks to main vignette (#170)

* Adding the post-page-artifact job (#181)

* Build link comment in PRs: update comment instead of re-creating on rebuilds (#182)

* Only run post-page-artifact job on PRs (#183)

* Fix formatting so functions link (#179)

* 174 cmdstanr sample args (#175)

* Hot fix validate pmf (#191)

* Restructure hierarchical estimation based on reference subpopulation (#158)

* update validate to warn if sum(site_pop)>total pop

* modify to center around the reference pop

* temporary change to stan file path for troubleshooting

* model compiles

* reorder pops by size, reindex subpops to sites, add switch for include_ww = 0

* wip rmd

* reindex labsites
 + other changes

* ensure the sum(sites)<total_pop case works

* workaround to handle include_ww = 0 in stan data

* add documentation, fix vignette

* fix preprocessing to order by site pop, add a test for this

* add tests for the hosp only and no aux site cases

* add a test of null data being passed in

* tweaks to print methods and get draws function

* tweak diagnostics, make sure hosp logic works as expected

* switch diagnostics, fix inits, add error message if req ww for hosp only model

* update vignette package data

* update test data

* add log shift from reference pop to central dynamic

* add m prior to params and stan data, fix inits bug

* update test data

* fix preprocessing test to order in terms of site pops

* fix model diagnostics functions

* m should be centered around 1!

* fix inits

* m is log scale, it should be centered around 0

* fix inits

* update test data

* edit subpop definition in model defn

* run pre-commit

* fix arrange

* edit model definition to explain reference subpop

* run pre-commit locally

* fix example

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* add ofsets to intercept and growth rate of unobserved infection process

* update test data running on WSL2

* Change how offsets are handled (#168)

* Update model file to handle offsets slightly differently, clarify parameter name comments

* Fix missing close paren

* Fix variable name

* Fix more variable names

* Remove separate handling of reference pop, fix a few more bugs

* Update docs

* Fix check for warning in get_stan_data test

* Better fix for test_get_stan_data

* Fail more informatively if test_ww_model fails to fit entirely

* Further customize the fitting failure message for informativeness

* Update get stan data with new variable names

* Add new variable names to example_params.toml

* Fix indexing and initialization

* Update test data

* add test of no ww model

* add conditional for inits, add test for no ww

* tweak prreprocessing to handle no wastewater case, add tests for all cases

* update testing data

* Update R/get_stan_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/get_draws.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* fix initialization

* update language around the sum(sites)>pop

* run pre-commit locally

* whoops, fix init

* aux site -> aux subpop

* add site_to_subpop map to get_subpop_data function

* create vectors to pass to stan using the subpopulation mappings

* revert to original initialization, use index explicitly in df column name

* remove old comments

* add functions for making spines in wwinference

* move spine functions to get stan data file

* update docs

* fix fxn input

* Fix typo

* refactor handling of sites, subpops, ww data indices interally, commented code, expect to fail

* include lod vals in plots

* fix get stan data to be all based on mappings

* fix tests to take in all inputs to get stan data

* fix lab_site_subpop_spine fxn

* first pass fix postprocessing

* minor tweaks

* update expected column names from get_draws

* update test data

* fix labsite to subpop spine handling, add docs for get ww indices and vals

---------

Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>

* init had wrong name... (#199)

* add multiple os to matrix strategy (#190)

* Update NEWS.md (#205)

* Update README.md (#207)

* Update DESCRIPTION (#203)

* Fix error messaging when data extends beyond forecast date (#208)

* Positive constrain mode_sigma_ww_site (#210)

* fix typo in resolving git conflicts

* change to local filepath to stan model for troubleshooting

* model compiles

* modify the non spatial component slightly

* troubleshooting simulateedd ata fxn

* add package data for both vignettes

* fix handling of subpops from merge, modify vignette temporarily

* WIP thinking through changes to spatial model with new structure

* get something to work for no hosp model with n subpops = 1

* add spatial model components to get stan data tests

* fix vignette, remove here

* update with new get draws df

* fix bug in samplign draws

* fix to remove any get_draws_df

* fix to remove any get_draws_df

* fix hosp plots

* fix all the dependencies from changing get_draws_df to get_draws

---------

Co-authored-by: George G. Vega Yon <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Chirag Kumar <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
  • Loading branch information
5 people authored Nov 4, 2024
1 parent bf49587 commit 3ed3910
Show file tree
Hide file tree
Showing 74 changed files with 3,208 additions and 1,323 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
contents: write
id-token: write
pages: write
outputs:
page_artifact_id: ${{ steps.upload-artifact.outputs.artifact_id }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -52,6 +54,7 @@ jobs:
shell: Rscript {0}

- name: Upload artifact for GH pages deployment
id: upload-artifact
uses: actions/upload-pages-artifact@v3
with:
path: "docs/"
Expand All @@ -72,3 +75,33 @@ jobs:
steps:
- name: Deploy to GitHub pages
uses: actions/deploy-pages@v4

post-page-artifact:
# only comment on PRs
if: ${{ github.event_name == 'pull_request' }}
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Your page is ready to preview

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Thank you for your contribution, @${{ github.triggering_actor }} :rocket:! Your page is ready to preview [here](https://github.com/${{github.repository}}/actions/runs/${{ github.run_id }}/artifacts/${{ needs.build.outputs.page_artifact_id }})
edit-mode: replace
10 changes: 7 additions & 3 deletions .github/workflows/r-cmd-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ on:

jobs:
check-package:
runs-on: ubuntu-latest
strategy:
matrix:
r-version: ["4.1.0", "release"]
os: [windows-latest, ubuntu-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
r-version: "release"
r-version: ${{matrix.r-version}}
use-public-rspm: true
extra-repositories: "https://mc-stan.org/r-packages/"
- name: "Set up dependencies for wwinference"
Expand All @@ -24,6 +27,7 @@ jobs:
uses: epinowcast/actions/install-cmdstan@v1
with:
cmdstan-version: "latest"
num-cores: 2
- name: "Check wwinference package"
uses: r-lib/actions/check-r-package@v2
with:
Expand Down
26 changes: 22 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wwinference
Title: Jointly infers infection dynamics from wastewater data and epidemiological indicators
Version: 0.0.0.9000
Version: 0.1.0
Authors@R: c(
person(given = "Kaitlyn",
family = "Johnson",
Expand All @@ -23,7 +23,7 @@ Authors@R: c(
email = "[email protected]"),
person(given = "George",
family = "Vega Yon",
role = c("ctb"),
role = c("aut"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-3171-0844")),
person(given = "Damon",
Expand All @@ -37,7 +37,25 @@ Authors@R: c(
person(given = "Scott",
family = "Olesen",
role = c("aut"),
email = "[email protected]")
email = "[email protected]"),
person(given = "Adam",
family = "Howes",
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-2386-4031")),
person(given = "Chirag",
family = "Kumar",
role = c("ctb"),
email = "[email protected]"),
person(given = "Alexander",
family = "Keyel",
role = c("ctb"),
email = "[email protected]",
comment = c(ORCID = "000-0001-5256-6274")),
person(given = "Hannah",
family = "Cohen",
role = c("ctb"),
email = "[email protected]")
)
Description: An implementation of a hierarchical semi-mechanistic renewal
approach jointly calibrating to multiple wastewater concentrations datasets from
Expand All @@ -54,7 +72,7 @@ License: Apache License (>= 2)
URL: https://github.com/cdcgov/ww-inference-model/, https://cdcgov.github.io/ww-inference-model/
BugReports: https://github.com/cdcgov/ww-inference-model/issues/
Depends:
R (>= 4.3.0)
R (>= 4.1.0)
SystemRequirements: CmdStan (>=2.35.0)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
18 changes: 12 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Generated by roxygen2: do not edit by hand

S3method(get_draws_df,data.frame)
S3method(get_draws_df,default)
S3method(get_draws_df,wwinference_fit)
S3method(get_draws,data.frame)
S3method(get_draws,default)
S3method(get_draws,wwinference_fit)
S3method(get_model_diagnostic_flags,default)
S3method(get_model_diagnostic_flags,wwinference_fit)
S3method(plot,wwinference_fit_draws)
S3method(print,wwinference_fit)
S3method(print,wwinference_fit_draws)
S3method(summary,wwinference_fit)
export(add_pmfs)
export(add_time_indexing)
Expand All @@ -20,10 +22,14 @@ export(generate_simulated_data)
export(get_count_data_sizes)
export(get_count_indices)
export(get_count_values)
export(get_date_time_spine)
export(get_draws)
export(get_draws_df)
export(get_ind_m)
export(get_input_count_data_for_stan)
export(get_input_ww_data_for_stan)
export(get_lab_site_site_spine)
export(get_lab_site_subpop_spine)
export(get_mcmc_options)
export(get_model_diagnostic_flags)
export(get_model_spec)
Expand All @@ -32,18 +38,18 @@ export(get_plot_forecasted_counts)
export(get_plot_global_rt)
export(get_plot_subpop_rt)
export(get_plot_ww_conc)
export(get_site_subpop_spine)
export(get_stan_data)
export(get_subpop_data)
export(get_ww_data_indices)
export(get_ww_data_sizes)
export(get_ww_values)
export(get_ww_indices_and_values)
export(independence_corr_func_r)
export(indicate_ww_exclusions)
export(parameter_diagnostics)
export(preprocess_count_data)
export(preprocess_ww_data)
export(rand_corr_matrix_func)
export(spatial_rt_process)
export(summary_diagnostics)
export(to_simplex)
export(validate_paramlist)
export(wwinference)
Expand Down
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# wwinference 0.0.1 (dev)

# wwinference 0.1.0

This is the first major release, focused on providing an initial version of the package.
Note the package is still flagged as in development, though the authors plan on using it for production work in the coming weeks.
Expand Down
89 changes: 69 additions & 20 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
#' @param date_vector vector of dates
#' @param max_date string indicating the maximum date in ISO8601 convention
#' e.g. YYYY-MM-DD
#' @param arg_dates string to print the name of the data you are checking the
#' dates for
#' @param arg_max_date string to print the name of the maximum date you are
#' checkign the data for
#' @param call Calling environment to be passed to [cli::cli_abort()] for
#' traceback.
#'
#' @return NULL, invisibly
assert_no_dates_after_max <- function(date_vector,
max_date, call = rlang::caller_env()) {
max_date,
arg_dates = "y",
arg_max_date = "x",
call = rlang::caller_env()) {
if (max(date_vector) > max_date) {
cli::cli_abort(
c(
"The data passed in has observations beyond the specified",
"maximum date. Either this is the incorrect vintaged",
"data, or the data needs to be filtered to only contain",
"observations before the maximum date"
"The {.arg_dates {arg_dates}} passed in has observations after the ",
"specified {.arg_max_date {arg_max_date}}. Check that this is the ",
"dataset you intended to use with the given ",
"{.arg_max_date {arg_max_date}}."
),
call = call,
class = "wwinference_input_data_error"
Expand Down Expand Up @@ -211,6 +218,46 @@ assert_no_repeated_elements <- function(x, arg = "x",
invisible()
}

#' Check a set of columns in a data frame uniquely identify
#' data frame rows.
#'
#' @description
#' Equivalently, this checks that when grouping by the columns in question,
#' each group has a single entry
#'
#' @param df the dataframe to check
#' @param unique_key_columns Columns that, taken together, should
#' uniquely identify a row in the data frame.
#' @param arg the name of the unique grouping to check
#' @param call Calling environment to be passed to [cli::cli_abort()] for
#' traceback.
#' @param add_err_msg string containing an additional error message,
#' default is the empty string (`""`)
#'
#' @return NULL, invisibly
assert_cols_det_unique_row <- function(df,
unique_key_columns,
arg = "x",
call = rlang::caller_env(),
add_err_msg = "") {
duplicated_rows <- df |> dplyr::filter(dplyr::n() > 1,
.by = {{ unique_key_columns }}
)

if (nrow(duplicated_rows) != 0) {
cli::cli_abort(
c("The data has more than one observation per {.arg {arg}}",
add_err_msg,
"i" = "Multiple observations in a {.arg {arg}} are not",
"currently supported."
),
call = call,
class = "wwinference_input_data_error"
)
}
invisible()
}



#' Assert that a vector is either of a vector of integers or a vector of
Expand Down Expand Up @@ -347,19 +394,15 @@ assert_req_ww_cols_present <- function(ww_data,
#' traceback.
#'
#' @return NULL, invisibly
check_req_count_cols_present <- function(count_data,
count_col_name,
pop_size_col_name,
add_req_col_names = c("date"),
call = rlang::caller_env()) {
assert_req_count_cols_present <- function(count_data,
count_col_name,
pop_size_col_name,
add_req_col_names = c("date"),
call = rlang::caller_env()) {
column_names <- colnames(count_data)
expected_col_names <- c(
{
count_col_name
},
{
pop_size_col_name
},
count_col_name,
pop_size_col_name,
add_req_col_names
)

Expand Down Expand Up @@ -491,6 +534,9 @@ assert_daily_data <- function(dates,
#' calibration time
#'
#' @param date_vector the vector of dates to check, must be of Date type
#' @param data_name What data correspond to the dates in `date_vector`.
#' Used to make the error message informative (e.g.
#' "hospital admissions data")
#' @param calibration_time integer indicating the number of days that
#' the dates must span
#' @param call Calling environment to be passed to [cli::cli_abort()] for
Expand All @@ -500,6 +546,7 @@ assert_daily_data <- function(dates,
#'
#' @return NULL invisible
assert_sufficient_days_of_data <- function(date_vector,
data_name,
calibration_time,
call = rlang::caller_env(),
add_err_msg = "") {
Expand All @@ -511,7 +558,8 @@ assert_sufficient_days_of_data <- function(date_vector,
if (!check_sufficient_data) {
cli::cli_abort(
c(
"Insufficient data for specified calibration time"
"Insufficient {.arg {data_name}} for the specified calibration time. ",
add_err_msg
),
call = call,
class = "wwinference_specification_error"
Expand Down Expand Up @@ -540,9 +588,8 @@ assert_dates_within_frame <- function(dates1,
checkmate::assert_date(dates1)
checkmate::assert_date(dates2)
check_dates2_win_frame <- min(dates1) <= max(dates2) &
min(dates2) >= min(dates1) &
max(dates2) <= max_date &
max(dates1) <= max_date
min(dates2) <= max(dates1)

if (!check_dates2_win_frame) {
cli::cli_abort(
c(
Expand All @@ -556,6 +603,8 @@ assert_dates_within_frame <- function(dates1,

invisible()
}


#' Assert that two tibbles of date and time mapping align
#'
#' @param first_data a tibble containing the columns `date` (with IS08601
Expand Down
Loading

0 comments on commit 3ed3910

Please sign in to comment.