├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── draft-pdf.yml │ ├── pkgdown.yaml │ └── test-coverage.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── abbreviate_states.R ├── abs-helpers.R ├── abs_age_education.R ├── abs_age_work.R ├── abs_household_size_population.R ├── abs_per_capita_household_size_lga.R ├── abs_per_capita_household_size_state.R ├── add_modelling_features.R ├── add_offset.R ├── add_population_age_to.R ├── add_school_work_participation.R ├── add_symmetrical_features.R ├── adjust_household_contact_matrix.R ├── age-population.R ├── aggregate_predicted_contacts.R ├── apply_vaccination.R ├── autoplot.R ├── check_work_school_demographics.R ├── checkers.R ├── conmat-package.R ├── conmat-population.R ├── constructors.R ├── data-abs-avg-work-school.R ├── data-abs-pop-age-lga-2016.R ├── data-abs-pop-age-lga-2020.R ├── data-davies-age-extended.R ├── data_abs_education_state.R ├── data_abs_education_state_2020.R ├── data_abs_employ_age_lga.R ├── data_abs_household_lga.R ├── data_abs_lga_education.R ├── data_abs_lga_lookup.R ├── data_abs_lga_work.R ├── data_abs_state_age.R ├── data_abs_state_education.R ├── data_abs_state_work.R ├── data_age_group_lookup.R ├── data_example_vaccination_effect.R ├── data_eyre_transmission_probabilities.R ├── data_original_school_work.R ├── data_polymod_model.R ├── data_prem_contact_matrices.R ├── data_setting_weights.R ├── estimate_setting_contacts.R ├── extrapolate_polymod.R ├── fit_setting_contacts.R ├── fit_single_contact_model.R ├── generate-ngm.R ├── get-age-population-function-internals.R ├── get_abs_per_capita_household_size.R ├── get_age_population_function.R ├── get_household_size_distribution.R ├── get_polymod_contact_data.R ├── get_polymod_per_capita_household_size.R ├── get_polymod_population.R ├── get_polymod_setting_data.R ├── get_setting_transmission_matrices.R ├── matrix_to_predictions.R ├── model-tidiers.R ├── partial-prediction-helpers.R ├── per_capita_household_size.R ├── plot_matrix.R ├── plot_setting_matrices.R ├── polymod-data.R ├── predict_contacts.R ├── predict_contacts_1y.R ├── predict_setting_contacts.R ├── predictions_to_matrix.R ├── setting-prediction-matrix.R ├── setting-transmission-matrix.R ├── sysdata.rda ├── utils-pipe.R └── utils.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── codecov.yml ├── conmat.Rproj ├── cran-comments.md ├── data-raw ├── 2011_lga_state.csv ├── 2016_abs_census_labour_status.csv ├── 2016_abs_census_lga_work.csv ├── 2016_abs_lga_education.xls ├── 2016_census_education.csv ├── 31010do001_202012.xls ├── 32350DS0003_2020.xls ├── 32350ds0015_lga_2016.xls ├── ABS_C16_G43_LGA_06092021163109650.csv.zip ├── ABS_C16_T23_LGA_06092021160753604.csv ├── ABS_CENSUS2011_B30_LGA_06092021155248143.csv ├── Table 42b Number of Full-time and Part-time Students, 2006-2020.xlsx ├── abs-avg-work-school.R ├── clean-education-2020.R ├── clean-education.R ├── clean-employment.R ├── clean-household.R ├── clean-lga-lookup.R ├── clean-population-by-age-2016.R ├── clean-population-by-age-2020.R ├── clean-state-age-pop.R ├── conmat-original-school-work-demographics.R ├── create-age-lookup.R ├── create-polymod-model.R ├── data_abs_census_education_2016.R ├── data_abs_census_education_lga_2016.R ├── data_abs_census_work_2016.R ├── data_abs_census_work_lga_2016.R ├── digitise_eyre_matrix.R ├── euclidean_join.R ├── example_coverage.csv ├── example_vaccination_effect.R ├── example_vaccine_coverage_effects.csv ├── example_ves.csv ├── eyre_legend_raw.png ├── eyre_transmission_events_activities.png ├── eyre_transmission_household.png ├── eyre_transmission_household_visitor.png ├── eyre_transmission_probabilities.csv.gz ├── eyre_transmission_work_education.png ├── get_age_group_lookup.R ├── population_data.csv ├── prem │ ├── contact_all.rdata │ ├── contact_home.rdata │ ├── contact_others.rdata │ ├── contact_school.rdata │ ├── contact_work.rdata │ ├── rural │ │ ├── contact_all_rural.rdata │ │ ├── contact_home_rural.rdata │ │ ├── contact_others_rural.rdata │ │ ├── contact_school_rural.rdata │ │ └── contact_work_rural.rdata │ └── urban │ │ ├── contact_all_urban.rdata │ │ ├── contact_home_urban.rdata │ │ ├── contact_others_urban.rdata │ │ ├── contact_school_urban.rdata │ │ └── contact_work_urban.rdata ├── prem_germany_contact_matrices.R ├── read_eyre_transmission_probabilities.R ├── read_setting_weights.R ├── susceptibility_clinical_fraction.R └── use-polymod.R ├── data ├── abs_avg_school.rda ├── abs_avg_work.rda ├── abs_education_state.rda ├── abs_education_state_2020.rda ├── abs_employ_age_lga.rda ├── abs_household_lga.rda ├── abs_lga_lookup.rda ├── abs_pop_age_lga_2016.rda ├── abs_pop_age_lga_2020.rda ├── abs_state_age.rda ├── age_group_lookup.rda ├── conmat_original_school_demographics.rda ├── conmat_original_work_demographics.rda ├── data_abs_lga_education.rda ├── data_abs_lga_work.rda ├── data_abs_state_education.rda ├── data_abs_state_work.rda ├── davies_age_extended.rda ├── eyre_transmission_probabilities.rda ├── polymod.rda ├── polymod_setting_models.rda ├── prem_germany_contact_matrices.rda ├── setting_weights.rda └── vaccination_effect_example_data.rda ├── flint ├── config.yml └── rules │ └── builtin │ ├── T_and_F_symbol.yml │ ├── absolute_path.yml │ ├── any_duplicated.yml │ ├── any_is_na.yml │ ├── class_equals.yml │ ├── condition_message.yml │ ├── double_assignment.yml │ ├── duplicate_argument.yml │ ├── empty_assignment.yml │ ├── equal_assignment.yml │ ├── equals_na.yml │ ├── expect_comparison.yml │ ├── expect_identical.yml │ ├── expect_length.yml │ ├── expect_named.yml │ ├── expect_not.yml │ ├── expect_null.yml │ ├── expect_true_false.yml │ ├── expect_type.yml │ ├── for_loop_index.yml │ ├── function_return.yml │ ├── implicit_assignment.yml │ ├── is_numeric.yml │ ├── length_levels.yml │ ├── length_test.yml │ ├── lengths.yml │ ├── library_call.yml │ ├── list_comparison.yml │ ├── literal_coercion.yml │ ├── matrix_apply.yml │ ├── missing_argument.yml │ ├── nested_ifelse.yml │ ├── numeric_leading_zero.yml │ ├── outer_negation.yml │ ├── package_hooks.yml │ ├── paste.yml │ ├── redundant_equals.yml │ ├── redundant_ifelse.yml │ ├── rep_len.yml │ ├── right_assignment.yml │ ├── sample_int.yml │ ├── semicolon.yml │ ├── seq.yml │ ├── sort.yml │ ├── stopifnot_all.yml │ ├── todo_comment.yml │ ├── undesirable_function.yml │ ├── undesirable_operator.yml │ ├── unnecessary_nesting.yml │ ├── unreachable_code.yml │ └── which_grepl.yml ├── inst └── WORDLIST ├── man ├── abs-age-education.Rd ├── abs-age-work.Rd ├── abs_abbreviate_states.Rd ├── abs_age_data.Rd ├── abs_avg_school.Rd ├── abs_avg_work.Rd ├── abs_education_state.Rd ├── abs_education_state_2020.Rd ├── abs_employ_age_lga.Rd ├── abs_household_lga.Rd ├── abs_lga_lookup.Rd ├── abs_pop_age_lga_2016.Rd ├── abs_pop_age_lga_2020.Rd ├── abs_state_age.Rd ├── abs_unabbreviate_states.Rd ├── accessors.Rd ├── add_intergenerational.Rd ├── add_modelling_features.Rd ├── add_offset.Rd ├── add_population_age_to.Rd ├── add_school_work_participation.Rd ├── add_symmetrical_features.Rd ├── age_breaks.Rd ├── age_group_lookup.Rd ├── age_population.Rd ├── aggregate_predicted_contacts.Rd ├── apply_vaccination.Rd ├── as_conmat_population.Rd ├── as_setting_prediction_matrix.Rd ├── autoplot-conmat-partial.Rd ├── autoplot-conmat.Rd ├── check_dimensions.Rd ├── check_if_list.Rd ├── check_school_demographics.Rd ├── check_work_demographics.Rd ├── clean_age_population_year.Rd ├── conmat-package.Rd ├── conmat_original_school_demographics.Rd ├── conmat_original_work_demographics.Rd ├── conmat_population.Rd ├── data_abs_lga_education.Rd ├── data_abs_lga_work.Rd ├── data_abs_state_education.Rd ├── data_abs_state_work.Rd ├── davies_age_extended.Rd ├── estimate_setting_contacts.Rd ├── extrapolate_polymod.Rd ├── eyre_transmission_probabilities.Rd ├── figures │ ├── README-eyre-transmission-probabilities-1.png │ ├── README-fairfield-synth-5-plot-1.png │ ├── README-matrix-plot-1.png │ ├── README-plot-matrix-differents-1.png │ ├── README-plot-matrix-differents-2.png │ ├── README-plot-matrix-differents-3.png │ ├── README-plot-matrix-differents-4.png │ ├── README-plot-matrix-differents-5.png │ ├── README-sydney-synth-5-plot-1.png │ └── README-unnamed-chunk-4-1.png ├── fit_setting_contacts.Rd ├── fit_single_contact_model.Rd ├── formula-terms.Rd ├── generate_ngm.Rd ├── generate_ngm_oz.Rd ├── get_abs_household_size_distribution.Rd ├── get_abs_household_size_population.Rd ├── get_abs_per_capita_household_size.Rd ├── get_abs_per_capita_household_size_lga.Rd ├── get_abs_per_capita_household_size_state.Rd ├── get_age_population_function.Rd ├── get_polymod_contact_data.Rd ├── get_polymod_per_capita_household_size.Rd ├── get_polymod_population.Rd ├── get_polymod_setting_data.Rd ├── get_setting_transmission_matrices.Rd ├── matrix_to_predictions.Rd ├── new_age_matrix.Rd ├── new_conmat_population.Rd ├── new_ngm_setting_matrix.Rd ├── new_setting_data.Rd ├── partial-prediction-sum.Rd ├── partial-prediction.Rd ├── per_capita_household_size.Rd ├── pipe.Rd ├── polymod.Rd ├── polymod_setting_models.Rd ├── predict_contacts.Rd ├── predict_contacts_1y.Rd ├── predict_setting_contacts.Rd ├── predictions_to_matrix.Rd ├── prem_germany_contact_matrices.Rd ├── prepare_population_for_modelling.Rd ├── raw_eigenvalue.Rd ├── reexports.Rd ├── scaling.Rd ├── separate_age_group.Rd ├── setting_prediction_matrix.Rd ├── setting_weights.Rd ├── transmission_probability_matrix.Rd └── vaccination_effect_example_data.Rd ├── paper ├── .gitignore ├── paper.bib ├── paper.html.log ├── paper.html.md ├── paper.html.pdf.md ├── paper.md ├── paper.qmd └── paper_files │ ├── figure-html │ ├── fig-autoplot-contacts-1.png │ └── fig-show-partial-plots-1.png │ └── libs │ ├── bootstrap │ ├── bootstrap-c0367b04c37547644fece4185067e4a7.min.css │ ├── bootstrap-e19dc0c07aeef78048e587c3f1edba7a.min.css │ ├── bootstrap-icons.css │ ├── bootstrap-icons.woff │ ├── bootstrap.min.css │ └── bootstrap.min.js │ ├── clipboard │ └── clipboard.min.js │ └── quarto-html │ ├── anchor.min.js │ ├── popper.min.js │ ├── quarto-syntax-highlighting-01c78b5cd655e4cd89133cf59d535862.css │ ├── quarto-syntax-highlighting-2f5df379a58b258e96c21c0638c20c03.css │ ├── quarto-syntax-highlighting.css │ ├── quarto.js │ ├── tippy.css │ └── tippy.umd.min.js ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── _snaps │ ├── abbreviation.md │ ├── abs-age-education.md │ ├── abs-age-lga.md │ ├── abs-age-work.md │ ├── age-population.md │ ├── apply_vaccination.md │ ├── autoplot │ │ ├── autoplot-all-settinge.svg │ │ ├── autoplot-ngm.svg │ │ ├── autoplot-single-setting.svg │ │ ├── autoplot-vaccination.svg │ │ └── autoplot.svg │ ├── check-age-breaks.md │ ├── check-if-data-frame.md │ ├── check-if-data-list.md │ ├── check-lga-name.md │ ├── check-state-name.md │ ├── check_dimensions.md │ ├── conmat-population.md │ ├── estimate-setting-contacts.md │ ├── extrapolate-polymod.md │ ├── fit-single-contact-model.md │ ├── generate-ngm.md │ ├── get-abs-household-size-distribution.md │ ├── get-polymod-population.md │ ├── lga_household_works.md │ ├── matrix-to-predictions.md │ ├── models-fit-with-furrr.md │ ├── partial-prediction.md │ ├── partial-prediction │ │ ├── gg-partials-home.svg │ │ ├── gg-partials-setting.svg │ │ ├── gg-partials-sum-home.svg │ │ └── gg-partials-sum-setting.svg │ ├── predict-contacts.md │ ├── print-conmat-matrix-method.md │ ├── setting-prediction-matrix.md │ └── setting-transmission-matrix.md │ ├── test-abbreviation.R │ ├── test-abs-age-education.R │ ├── test-abs-age-lga.R │ ├── test-abs-age-work.R │ ├── test-age-population.R │ ├── test-apply_vaccination.R │ ├── test-autoplot.R │ ├── test-check-age-breaks.R │ ├── test-check-if-data-frame.R │ ├── test-check-if-data-list.R │ ├── test-check-lga-name.R │ ├── test-check-state-name.R │ ├── test-check_dimensions.R │ ├── test-conmat-population.R │ ├── test-estimate-setting-contacts.R │ ├── test-extrapolate-polymod.R │ ├── test-fit-single-contact-model.R │ ├── test-generate-ngm.R │ ├── test-get-abs-household-size-distribution.R │ ├── test-get-polymod-population.R │ ├── test-lga_household_works.R │ ├── test-matrix-to-predictions.R │ ├── test-models-fit-with-furrr.R │ ├── test-partial-prediction.R │ ├── test-per_capita_household_size.R │ ├── test-predict-contacts.R │ ├── test-print-conmat-matrix-method.R │ ├── test-setting-prediction-matrix.R │ └── test-setting-transmission-matrix.R ├── touchstone ├── .gitignore ├── config.json ├── footer.R ├── header.R ├── script.R └── touchstone-setup.R └── vignettes ├── .gitignore ├── conmat-population.Rmd ├── data-sources.Rmd ├── example-pipeline.Rmd ├── getting-started.Rmd ├── other-data-sources.Rmd ├── parallel-computing.Rmd ├── sir-model.Rmd └── visualising-conmat.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^CODE_OF_CONDUCT\.md$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^README_cache$ 6 | ^\.Rproj\.user$ 7 | ^\.github$ 8 | ^\.pre-commit-config\.yaml$ 9 | ^_pkgdown\.yml$ 10 | ^codecov\.yml$ 11 | ^data-raw$ 12 | ^docs$ 13 | ^pkgdown$ 14 | ^touchstone$ 15 | ^cran-comments\.md$ 16 | ^paper$ 17 | 18 | 19 | # flint files 20 | ^flint$ 21 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | 8 | name: R-CMD-check.yaml 9 | 10 | permissions: read-all 11 | 12 | jobs: 13 | R-CMD-check: 14 | runs-on: ${{ matrix.config.os }} 15 | 16 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 17 | 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | config: 22 | - {os: macos-latest, r: 'release'} 23 | - {os: windows-latest, r: 'release'} 24 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 25 | - {os: ubuntu-latest, r: 'release'} 26 | - {os: ubuntu-latest, r: 'oldrel-1'} 27 | 28 | env: 29 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 30 | R_KEEP_PKG_SOURCE: yes 31 | 32 | steps: 33 | - uses: actions/checkout@v4 34 | 35 | - uses: r-lib/actions/setup-pandoc@v2 36 | 37 | - uses: r-lib/actions/setup-r@v2 38 | with: 39 | r-version: ${{ matrix.config.r }} 40 | http-user-agent: ${{ matrix.config.http-user-agent }} 41 | use-public-rspm: true 42 | 43 | - uses: r-lib/actions/setup-r-dependencies@v2 44 | with: 45 | extra-packages: any::rcmdcheck 46 | needs: check 47 | 48 | - uses: r-lib/actions/check-r-package@v2 49 | with: 50 | upload-snapshots: true 51 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 52 | -------------------------------------------------------------------------------- /.github/workflows/draft-pdf.yml: -------------------------------------------------------------------------------- 1 | name: Draft PDF 2 | on: [push] 3 | 4 | jobs: 5 | paper: 6 | runs-on: ubuntu-latest 7 | name: Paper Draft 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v4 11 | - name: Build draft PDF 12 | uses: openjournals/openjournals-draft-action@master 13 | with: 14 | journal: joss 15 | # This should be the path to the paper within your repo. 16 | paper-path: paper/paper.html.md 17 | - name: Upload 18 | uses: actions/upload-artifact@v4 19 | with: 20 | name: paper 21 | # This is the output path where Pandoc will write the compiled 22 | # PDF. Note, this should be the same directory as the input 23 | # paper.md 24 | path: paper/paper.pdf -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | steps: 23 | - uses: actions/checkout@v3 24 | 25 | - uses: r-lib/actions/setup-pandoc@v2 26 | 27 | - uses: r-lib/actions/setup-r@v2 28 | with: 29 | use-public-rspm: true 30 | 31 | - uses: r-lib/actions/setup-r-dependencies@v2 32 | with: 33 | extra-packages: any::pkgdown, local::. 34 | needs: website 35 | 36 | - name: Build site 37 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 38 | shell: Rscript {0} 39 | 40 | - name: Deploy to GitHub pages 🚀 41 | if: github.event_name != 'pull_request' 42 | uses: JamesIves/github-pages-deploy-action@v4.4.1 43 | with: 44 | clean: false 45 | branch: gh-pages 46 | folder: docs 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | .DS_Store 7 | docs 8 | README_cache 9 | .Rprofile 10 | .vscode/launch.json 11 | .pre-commit-config.yaml 12 | tests/README.md 13 | paper/*.html 14 | paper/*.pdf 15 | paper/paper_cache/ 16 | chitra/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2021 2 | COPYRIGHT HOLDER: Nicholas Tierney, Nicholas Golding 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 conmat authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/abs_age_work.R: -------------------------------------------------------------------------------- 1 | #' @title Return data on employed population for a given age and state or 2 | #' lga of Australia 3 | #' @param lga target Australian local government area (LGA) name, such as 4 | #' "Fairfield (C)" or a vector with multiple lga names. See 5 | #' [abs_lga_lookup()] for list of lga names. 6 | #' @param age a numeric or numeric vector denoting ages between 0 to 115. 7 | #' The default is to return all ages. 8 | #' @return data set with information on the number of employed people belonging 9 | #' to a particular age, its total population and the corresponding proportion. 10 | #' @rdname abs-age-work 11 | #' @export 12 | #' @examples 13 | #' abs_age_work_state(state = "NSW") 14 | #' abs_age_work_state(state = c("QLD", "TAS"), age = 5) 15 | #' abs_age_work_lga(lga = "Albany (C)", age = 1:5) 16 | #' abs_age_work_lga(lga = c("Albury (C)", "Barcoo (S)"), age = 39) 17 | #' 18 | abs_age_work_lga <- function(lga = NULL, age = NULL) { 19 | check_lga_name(lga, multiple_lga = TRUE) 20 | data_subset <- data_abs_lga_work %>% dplyr::filter(lga %in% {{ lga }}) 21 | 22 | if (!is.null(age)) { 23 | data_subset <- data_subset %>% dplyr::filter(age %in% {{ age }}) 24 | } 25 | 26 | data_subset 27 | } 28 | 29 | #' @param state target Australian state name or a vector with multiple state 30 | #' names in its abbreviated form, such as "QLD", "NSW", or "TAS" 31 | #' @name abs-age-work 32 | #' @export 33 | abs_age_work_state <- function(state = NULL, age = NULL) { 34 | check_state_name(state, multiple_state = TRUE) 35 | data_subset <- data_abs_state_work %>% dplyr::filter(state %in% {{ state }}) 36 | 37 | if (!is.null(age)) { 38 | data_subset <- data_subset %>% dplyr::filter(age %in% {{ age }}) 39 | } 40 | 41 | data_subset 42 | } 43 | -------------------------------------------------------------------------------- /R/abs_per_capita_household_size_lga.R: -------------------------------------------------------------------------------- 1 | #' @title Get household size distribution based on LGA name 2 | #' @param lga target Australian local government area (LGA) name, such as "Fairfield (C)". See 3 | #' [abs_lga_lookup()] for list of lga names 4 | #' @return returns a numeric value depicting the per capita household size of the specified LGA 5 | #' @export 6 | #' @examples 7 | #' get_abs_per_capita_household_size_lga(lga = "Fairfield (C)") 8 | #' 9 | get_abs_per_capita_household_size_lga <- function(lga = NULL) { 10 | check_lga_name(lga, multiple_lga = FALSE) 11 | 12 | # given ABS data on household sizes for a *single location*, get average 13 | # household sizes *per person* from ABS - assuming a max of 8 people per 14 | # households. Note - I tried computing the mean size of the households larger 15 | # than 7, by comparing with LGA populations, but they were improbably 16 | # enormous, probably because some of the population lives in facilities, not 17 | # households. 18 | 19 | lga <- rlang::enquo(lga) 20 | 21 | household_data <- get_abs_household_size_population(lga = lga) 22 | # set up aggregation 23 | household_data <- household_data %>% 24 | dplyr::filter(lga == !!lga) %>% 25 | dplyr::group_by(lga) 26 | 27 | # aggregate and average household sizes 28 | household_data %>% 29 | per_capita_household_size() 30 | } 31 | -------------------------------------------------------------------------------- /R/abs_per_capita_household_size_state.R: -------------------------------------------------------------------------------- 1 | #' @title Get household size distribution based on state name 2 | #' @param state target Australian state name in abbreviated form, such as "QLD", "NSW", or "TAS" 3 | #' @return returns a numeric value depicting the per capita household size of the specified state 4 | #' @export 5 | #' @examples 6 | #' get_abs_per_capita_household_size_state(state = "NSW") 7 | get_abs_per_capita_household_size_state <- function(state = NULL) { 8 | check_state_name(state, multiple_state = FALSE) 9 | 10 | # given ABS data on household sizes for a *single location*, get average 11 | # household sizes *per person* from ABS - assuming a max of 8 people per 12 | # households. Note - I tried computing the mean size of the households larger 13 | # than 7, by comparing with LGA populations, but they were improbably 14 | # enormous, probably because some of the population lives in facilities, not 15 | # households. 16 | 17 | state <- rlang::enquo(state) 18 | # get state mean household sizes 19 | household_data <- get_abs_household_size_population(state = state) 20 | 21 | # set up aggregation 22 | household_data <- household_data %>% 23 | dplyr::filter(state == !!state) %>% 24 | dplyr::group_by(state) 25 | 26 | # aggregate and average household sizes 27 | household_data %>% 28 | per_capita_household_size() 29 | } 30 | -------------------------------------------------------------------------------- /R/add_symmetrical_features.R: -------------------------------------------------------------------------------- 1 | #' @title Add symmetrical, age based features 2 | #' @description This function adds 6 columns to assist with describing 3 | #' various age based interactions for model fitting. Requires that the 4 | #' age columns are called "age_from", and "age_to" 5 | #' 6 | #' @param data data.frame with columns, `age_from`, and `age_to` 7 | #' @return data.frame with 6 more columns, `gam_age_offdiag`, `gam_age_offdiag_2`, `gam_age_diag_prod`, `gam_age_diag_sum`, `gam_age_pmax`, `gam_age_pmin`, 8 | #' @examples 9 | #' vec_age <- 0:2 10 | #' dat_age <- expand.grid( 11 | #' age_from = vec_age, 12 | #' age_to = vec_age 13 | #' ) 14 | #' 15 | #' add_symmetrical_features(dat_age) 16 | #' 17 | #' @export 18 | add_symmetrical_features <- function(data) { 19 | # add terms back into the data frame 20 | data %>% 21 | dplyr::mutate( 22 | gam_age_offdiag = abs(age_from - age_to), 23 | gam_age_offdiag_2 = abs(age_from - age_to)^2, 24 | gam_age_diag_prod = abs(age_from * age_to), 25 | gam_age_diag_sum = abs(age_from + age_to), 26 | gam_age_pmax = pmax(age_from, age_to), 27 | gam_age_pmin = pmin(age_from, age_to) 28 | ) 29 | } 30 | 31 | # gam( 32 | # response ~ 33 | # s(I(abs(age_from - age_to))) + 34 | # s(I(abs(age_from - age_to)^2)) + 35 | # s(I(abs(age_from * age_to))) + 36 | # s(I(abs(age_from + age_to))) + 37 | # s(I(pmax(age_from, age_to))) + 38 | # s(I(pmin(age_from, age_to))), 39 | # family = poisson, 40 | # offset = log(participants), 41 | # data = data 42 | # ) 43 | -------------------------------------------------------------------------------- /R/data-abs-avg-work-school.R: -------------------------------------------------------------------------------- 1 | #' ABS work data for 2016 2 | #' 3 | #' An internal dataset containing Australian Bureau of Statistics work data for 4 | #' each age in 2016. The data is averaged across each state to provide an 5 | #' overall average, and is used to provide estimated work populations for 6 | #' model fitting in [add_school_work_participation()], which is used in [fit_single_contact_model()]. The data is summarised from `data_abs_state_work`, 7 | #' see `?data_abs_state_work` for more details. 8 | #' 9 | #' @format A data frame with 116 rows and 2 variables: 10 | #' \describe{ 11 | #' \item{age}{0 to 115} 12 | #' \item{work_fraction}{fraction of population working.} 13 | #' } 14 | #' @source {Census of Population and Housing, 2016, TableBuilder} 15 | "abs_avg_work" 16 | 17 | #' ABS education data for 2016 18 | #' 19 | #' An internal dataset containing Australian Bureau of Statistics education data for 20 | #' each age in 2016. The data is averaged across each state to provide an 21 | #' overall average, and is used to provide estimated education populations for 22 | #' model fitting in [add_school_work_participation()], which is used in [fit_single_contact_model()]. The data is summarised from `data_abs_state_education`, 23 | #' see `?data_abs_state_education` for more details. 24 | #' 25 | #' @format A data frame with 116 rows and 2 variables: 26 | #' \describe{ 27 | #' \item{age}{0 to 115} 28 | #' \item{school_fraction}{fraction of population at school} 29 | #' } 30 | #' @source {Census of Population and Housing, 2016, TableBuilder} 31 | "abs_avg_school" 32 | -------------------------------------------------------------------------------- /R/data-abs-pop-age-lga-2016.R: -------------------------------------------------------------------------------- 1 | #' ABS population by age for 2016 for LGAs 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics population data by 4 | #' local government area (LGA) for age for 2016 5 | #' 6 | #' @format A data frame with 9918 rows and 6 variables: 7 | #' \describe{ 8 | #' \item{year}{year - 2020} 9 | #' \item{state}{state - short state or territory name} 10 | #' \item{lga}{LGA name} 11 | #' \item{age_group}{age age band, 0-4, in 5 year increments up to 80-84, then 85+} 12 | #' \item{population}{number of people in a given lga in an age band} 13 | #' } 14 | #' @source \url{https://www.abs.gov.au/statistics/people/population/regional-population-age-and-sex} 15 | "abs_pop_age_lga_2016" 16 | -------------------------------------------------------------------------------- /R/data-abs-pop-age-lga-2020.R: -------------------------------------------------------------------------------- 1 | #' ABS population by age for 2020 for LGAs 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics population data by 4 | #' local government area (LGA) for age for 2020 5 | #' 6 | #' @format A data frame with 9900 rows and 6 variables: 7 | #' \describe{ 8 | #' \item{year}{year - 2020} 9 | #' \item{state}{state - long state or territory name} 10 | #' \item{lga}{LGA name} 11 | #' \item{age_group}{age group band, 0-4, in 5 year increments up to 80-84, then 85+} 12 | #' \item{population}{number of people in a given lga in an age band} 13 | #' } 14 | #' @source \url{https://www.abs.gov.au/statistics/people/population/regional-population-age-and-sex} 15 | "abs_pop_age_lga_2020" 16 | -------------------------------------------------------------------------------- /R/data-davies-age-extended.R: -------------------------------------------------------------------------------- 1 | #' Susceptibility and clinical fraction parameters from Davies et al. 2 | #' 3 | #' A dataset containing data from \url{https://www.nature.com/articles/s41591-020-0962-9#code-availability} 4 | #' When using this data, ensure that you cite the original authors at: 5 | #' 6 | #' "Davies, N.G., Klepac, P., Liu, Y. et al. Age-dependent effects in the transmission and control of COVID-19 epidemics. Nat Med 26, 1205–1211 (2020). https://doi.org/10.1038/s41591-020-0962-9" 7 | #' 8 | #' @format A data frame of the probability of transmission from a case to a contact. There are 101 rows and 4 variables. 9 | #' \describe{ 10 | #' \item{age}{from 0 to 100} 11 | #' \item{clinical_fraction}{Estimate of fraction with clinical symptoms, or the age-specific proportion of infections resulting in clinical symptoms inferred by applying a smoothing spline to the mean estimates from Davies et al. } 12 | #' \item{davies_original}{Age specific parameters of the relative susceptibility to 13 | #' infection inferred from a smoothing-spline estimate of the mean relative susceptibility estimate from Davies et al.} 14 | #' \item{davies_updated}{Re-estimated parameter of the susceptibility profile for under-16s that is estimated in a similar way but to the age-distribution of infections in England from the UK ONS prevalence survey rather than case counts which may undercount children} 15 | #' } 16 | "davies_age_extended" 17 | -------------------------------------------------------------------------------- /R/data_abs_education_state.R: -------------------------------------------------------------------------------- 1 | #' ABS education by state for 2006-2020 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics education data by 4 | #' state for 2006 to 2020 5 | #' 6 | #' @format A data frame with 4194 rows and 5 variables: 7 | #' \describe{ 8 | #' \item{year}{year - 2020} 9 | #' \item{state}{state - short state or territory name} 10 | #' \item{aboriginal_and_torres_strait_islander_status}{"Aboriginal and Torres Strait Islander" or "Non-Indigenous"} 11 | #' \item{age}{4 through to 21. Note that "4" is 4 or younger and "21" is actually 21+ (21 or older)} 12 | #' \item{n_full_and_part_time}{number of people full and part time} 13 | #' } 14 | #' @source \url{https://www.abs.gov.au/statistics/people/education/schools/2020#data-download} (table 42B) 15 | "abs_education_state" 16 | -------------------------------------------------------------------------------- /R/data_abs_education_state_2020.R: -------------------------------------------------------------------------------- 1 | #' @title 2020 ABS education population data, interpolated into 1 year bins, 2 | #' by state. 3 | #' 4 | #' @description A dataset containing Australian Bureau of Statistics education 5 | #' data by state for 2020. These were interpolated into 1 year age bins. 6 | #' There are still some issued with the methods used, as the interpolated 7 | #' values are sometimes higher than the population. 8 | #' 9 | #' @format A data frame with 808 rows and 6 variables: 10 | #' \describe{ 11 | #' \item{year}{year - 2020} 12 | #' \item{state}{state - short state or territory name} 13 | #' \item{age}{0 to 100} 14 | #' \item{population}{number of people full and part time} 15 | #' \item{population_interpolated}{"Government" or "Non-government"} 16 | #' \item{prop}{population / population_interpolated} 17 | #' } 18 | #' @source \url{https://www.abs.gov.au/statistics/people/education/schools/2020#data-download} (table 42B) 19 | "abs_education_state_2020" 20 | -------------------------------------------------------------------------------- /R/data_abs_employ_age_lga.R: -------------------------------------------------------------------------------- 1 | #' ABS employment by age and LGA for 2016 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics employment data by 4 | #' state for 2016 5 | #' 6 | #' @format A data frame with 5600 rows and 8 variables: 7 | #' \describe{ 8 | #' \item{year}{year - 2016} 9 | #' \item{state}{state - short state or territory name} 10 | #' \item{lga}{local government area name} 11 | #' \item{age_group}{age groups are as follows: 15-19, 20-24, 25-34, 35-44, 12 | #' 45-54, 55-64, 65-74, 75-84, 85+, total} 13 | #' \item{total_employed}{total number of people employed} 14 | #' \item{total_unemployed}{total number of people unemployed} 15 | #' \item{total_labour_force}{total number of people in the labour force} 16 | #' \item{total}{sum of these totals...or thereabouts??} 17 | #' } 18 | #' @note still need to finalise these columns 19 | #' @source ABS.stat \url{https://www.abs.gov.au/statistics} LABOUR > 20 | #' Employment and Unemployment > Labour force, Australia > 21 | #' Census 2016, G43 labour status by age and sex (LGA) 22 | "abs_employ_age_lga" 23 | -------------------------------------------------------------------------------- /R/data_abs_household_lga.R: -------------------------------------------------------------------------------- 1 | #' @title ABS household data for 2016 2 | #' 3 | #' @description A dataset containing Australian Bureau of Statistics household 4 | #' data for 2016. The data is filtered to "Total Households". Contains 5 | #' information on the number of people typically in a residence in the region 6 | #' and the number of households associated with those number of residents. 7 | #' This data is typically used to obtain the household size distributions to 8 | #' compute the per capita household size of a particular region. 9 | #' 10 | #' @format A data frame with 4986 rows and 6 variables: 11 | #' \describe{ 12 | #' \item{year}{year - 2016} 13 | #' \item{state}{state - long state or territory name} 14 | #' \item{lga}{name of LGA} 15 | #' \item{n_persons_usually_resident}{Number of people typically in residence} 16 | #' \item{n_households}{number of households with that number of people} 17 | #' } 18 | #' @note still need to clean this 19 | #' @source \url{https://www.abs.gov.au/statistics} 20 | #' (downloaded the CSV) PEOPLE > People and Communities > Household Composition > Census 2016, T23 Household Composition By Number Of Persons Usually Resident (LGA) 21 | "abs_household_lga" 22 | -------------------------------------------------------------------------------- /R/data_abs_lga_lookup.R: -------------------------------------------------------------------------------- 1 | #' ABS lookup table of states, lga code and lga name 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics official short state 4 | #' names, lga_code, and lga name. 5 | #' 6 | #' @format A data frame with 544 rows and 3 variables, arrange by state then LGA 7 | #' \describe{ 8 | #' \item{state}{state - short state or territory name} 9 | #' \item{lga_code}{official lga code} 10 | #' \item{lga}{lga name} 11 | #' } 12 | "abs_lga_lookup" 13 | -------------------------------------------------------------------------------- /R/data_abs_lga_work.R: -------------------------------------------------------------------------------- 1 | #' LGA wise ABS work population data on different ages for year 2016 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics labour force population 4 | #' data by lga for 2016. The data sourced from 2016 Census - Employment, 5 | #' Income and Education through TableBuilder have been randomly adjusted by 6 | #' the ABS to avoid the release of confidential data. As a result of this, 7 | #' there are some cases where the estimated number of people being employed 8 | #' is higher than the population of those people. Such cases have been 9 | #' flagged under the `anomaly_flag` variable. 10 | #' 11 | #' @format A data frame with 64,496 rows and 8 variables: 12 | #' \describe{ 13 | #' \item{year}{2016, as data is from 2016 Census of Population and Housing.} 14 | #' \item{state}{String denoting the abbreviated name of state or territory 15 | #' name such as 'NSW', 'VIC', 'QLD' etc.} 16 | #' \item{lga}{String denoting the official name of Local Government Area. 17 | #' For example, 'Albury (C).'} 18 | #' \item{age}{Ages from 0 to 115.} 19 | #' \item{employed_population}{Number of people employed including people 20 | #' with full-time, part-time employment status.} 21 | #' \item{total_population}{Total population of age in row.} 22 | #' \item{proportion}{The ratio of employed population and total population 23 | #' belonging to the age i.e, employed_population/ total_population.} 24 | #' \item{anomaly_flag}{Logical variable flagging abnormal observations, such 25 | #' as total population lesser than employed_population as TRUE.} 26 | #' } 27 | #' @source {Census of Population and Housing, 2016, TableBuilder} 28 | "data_abs_lga_work" 29 | -------------------------------------------------------------------------------- /R/data_abs_state_age.R: -------------------------------------------------------------------------------- 1 | #' ABS state population data for 2020 2 | #' 3 | #' Dataset containing Australian Bureau of Statistics state level population 4 | #' data for 2020 5 | #' 6 | #' @format A data frame with 168 rows and 3 variables: 7 | #' \describe{ 8 | #' \item{state}{state - short state or territory name} 9 | #' \item{age_group}{age group in five year bins from 0 to 99, then 100+} 10 | #' \item{population}{population size} 11 | #' } 12 | #' @source \url{https://www.abs.gov.au/statistics/people/population/national-state-and-territory-population/dec-2020#data-downloads-data-cubes} 13 | "abs_state_age" 14 | -------------------------------------------------------------------------------- /R/data_abs_state_education.R: -------------------------------------------------------------------------------- 1 | #' State wise ABS education population data on different ages for year 2016 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics education data by state 4 | #' for 2016. The data sourced from 2016 Census - Employment, Income and 5 | #' Education through TableBuilder have been randomly adjusted by the ABS to 6 | #' avoid the release of confidential data. 7 | #' 8 | #' @format A data frame with 1044 rows and 6 variables: 9 | #' \describe{ 10 | #' \item{year}{2016, as data is from 2016 Census of Population and Housing.} 11 | #' \item{state}{String of abbreviated name of state or territory names, e.g., 12 | #' 'NSW', 'VIC', 'QLD' and so on.} 13 | #' \item{age}{Ages from 0 to 115.} 14 | #' \item{population_educated}{Number of people educated, including students 15 | #' with full-time, part-time status, and people who mentioned only the type 16 | #' of educational institution they attend and not their student status.} 17 | #' \item{total_population}{Total population belonging to age in a row.} 18 | #' \item{proportion}{The ratio of educated population and total population 19 | #' belonging to the age i.e, population_educated / total_population} 20 | #' } 21 | #' @source {Census of Population and Housing, 2016, TableBuilder} 22 | "data_abs_state_education" 23 | -------------------------------------------------------------------------------- /R/data_abs_state_work.R: -------------------------------------------------------------------------------- 1 | #' State wise ABS work population data on different ages for year 2016 2 | #' 3 | #' A dataset containing Australian Bureau of Statistics labour force population 4 | #' data by state for 2016. The data sourced from 2016 Census - Employment, 5 | #' Income and Education through TableBuilder have been randomly adjusted by 6 | #' the ABS to avoid the release of confidential data. 7 | #' 8 | #' @format A data frame with 1044 rows and 6 variables: 9 | #' \describe{ 10 | #' \item{year}{2016, as data is from 2016 Census of Population and Housing.} 11 | #' \item{state}{String. Abbreviated name of state or territory, e.g., 'NSW', 12 | #' 'VIC', 'QLD' and so on.} 13 | #' \item{age}{Ages from 0 to 115.} 14 | #' \item{employed_population}{Number of people employed including people 15 | #' with full-time, part-time employment status.} 16 | #' \item{total_population}{Total population belonging to the age.} 17 | #' \item{proportion}{The ratio of employed population and total population 18 | #' belonging to the age i.e, employed_population/ total_population} 19 | #' } 20 | #' @source {Census of Population and Housing, 2016, TableBuilder} 21 | "data_abs_state_work" 22 | -------------------------------------------------------------------------------- /R/data_age_group_lookup.R: -------------------------------------------------------------------------------- 1 | #' Lookup table of age groups in 5 year bins 2 | #' 3 | #' A dataset containing age lower and upper levels with age group 4 | #' 5 | #' 6 | #' @format A data frame with 21 rows and 3 variables: 7 | #' \describe{ 8 | #' \item{lower}{Lower age} 9 | #' \item{upper}{upper age} 10 | #' \item{age_group}{age group as a factor} 11 | #' } 12 | "age_group_lookup" 13 | -------------------------------------------------------------------------------- /R/data_example_vaccination_effect.R: -------------------------------------------------------------------------------- 1 | #' @title Example dataset with information on age based vaccination coverage, 2 | #' acquisition and transmission 3 | #' 4 | #' @description data frame with information on vaccine coverage, efficacy of 5 | #' acquisition/susceptibility and efficacy of transmission/infectiousness 6 | #' for the ordered age groups from lowest to highest of the next generation 7 | #' matrix. 8 | #' 9 | #' @format A data frame with 17 rows and 4 variables 10 | #' \describe{ 11 | #' \item{age_band}{character. age bands: 0-4,5-11, 12-15, 16-19, 20-24, etc} 12 | #' \item{coverage}{example vaccination coverage, between 0-1} 13 | #' \item{acquisition}{example acquisition coverage, between 0-1} 14 | #' \item{transmission}{example transmission coverage, between 0-1} 15 | #' } 16 | #' 17 | "vaccination_effect_example_data" 18 | -------------------------------------------------------------------------------- /R/data_original_school_work.R: -------------------------------------------------------------------------------- 1 | #' Original school demographics for conmat 2 | #' 3 | #' An internal dataset containing the original estimates of which fraction of 4 | #' ages were attending school in Australia. These can be used inside of 5 | #' [fit_single_contact_model()] and [fit_setting_contacts()]. 6 | #' 7 | #' @format A data frame with 121 rows and 2 variables: 8 | #' \describe{ 9 | #' \item{age}{0 to 120} 10 | #' \item{school_fraction}{fraction of population at school} 11 | #' } 12 | #' @source {Census of Population and Housing, 2016, TableBuilder} 13 | "conmat_original_school_demographics" 14 | 15 | #' Original work demographics for conmat 16 | #' 17 | #' An internal dataset containing the original estimates of which fraction of 18 | #' ages were working in Australia. These can be used inside of 19 | #' [fit_single_contact_model()] and [fit_setting_contacts()]. 20 | #' 21 | #' @format A data frame with 121 rows and 2 variables: 22 | #' \describe{ 23 | #' \item{age}{0 to 120} 24 | #' \item{work_fraction}{fraction of population working.} 25 | #' } 26 | #' @source {Census of Population and Housing, 2016, TableBuilder} 27 | "conmat_original_work_demographics" 28 | -------------------------------------------------------------------------------- /R/data_polymod_model.R: -------------------------------------------------------------------------------- 1 | #' @title Polymod Settings models 2 | #' 3 | #' @description A data object containing a list of fitted gam models 4 | #' predicting the number of contacts in each of the four settings which are 5 | #' "home","work","school" and "other". For more details on model fitting, 6 | #' see [fit_setting_contacts()]. This object has been provided as data to 7 | #' avoid recomputing a relatively common type of model for use with `conmat`. 8 | #' 9 | #' @seealso [fit_setting_contacts()] 10 | #' @examples 11 | #' \dontrun{ 12 | #' # code used to produce this data 13 | #' library(conmat) 14 | #' set.seed(2022 - 08 - 26) 15 | #' polymod_contact_data <- get_polymod_setting_data() 16 | #' polymod_survey_data <- get_polymod_population() 17 | #' polymod_setting_models <- fit_setting_contacts( 18 | #' contact_data_list = polymod_contact_data, 19 | #' # population = polymod_survey_data 20 | #' ) 21 | #' } 22 | #' 23 | "polymod_setting_models" 24 | -------------------------------------------------------------------------------- /R/data_prem_contact_matrices.R: -------------------------------------------------------------------------------- 1 | #' Contact matrices as calculated by Prem. et al. 2 | #' 3 | #' Contact matrices as calculated by Prem. et al. (2021) PLoS Computational Biology. Updated to use the latest corrected matrices from their 2021 publication. 4 | #' DOI: 10.1371/journal.pcbi.1009098 5 | #' 6 | #' @format A list with 5 elements: 7 | #' \describe{ 8 | #' \item{home}{A 16x16 matrix containing the number of home contacts, by 5 9 | #' year age group} 10 | #' \item{work}{A 16x16 matrix containing the number of workplace contacts, by 11 | #' 5 year age group} 12 | #' \item{school}{A 16x16 matrix containing the number of school contacts, by 5 13 | #' year age group} 14 | #' \item{other}{A 16x16 matrix containing the number of other contacts, by 5 15 | #' year age group} 16 | #' \item{all}{A 16x16 matrix containing the number of all contacts, by 5 17 | #' year age group} 18 | #' } 19 | #' All age groups are 5 year age bands, from 0 to 80. 20 | #' 21 | #' @source \url{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1009098} 22 | #' @source \url{https://github.com/kieshaprem/synthetic-contact-matrices} 23 | "prem_germany_contact_matrices" 24 | -------------------------------------------------------------------------------- /R/data_setting_weights.R: -------------------------------------------------------------------------------- 1 | #' Setting weights computed for transmission probabilities. 2 | #' 3 | #' 4 | #' see ?get_setting_transmission_matrices for details of how to use these 5 | #' 6 | #' @format A named vector of weights relative to home, for home, work, school, 7 | #' and other 8 | "setting_weights" 9 | -------------------------------------------------------------------------------- /R/get_polymod_per_capita_household_size.R: -------------------------------------------------------------------------------- 1 | #' @title Get polymod per capita household size. 2 | #' 3 | #' @description Convenience function to help get the per capita household size. 4 | #' This is calculated as `mean(socialmixr::polymod$participants$hh_size)`. 5 | #' 6 | #' @return number, 3.248971 7 | #' @author Nicholas Tierney 8 | #' @examples 9 | #' get_polymod_per_capita_household_size() 10 | #' @export 11 | get_polymod_per_capita_household_size <- function() { 12 | mean(socialmixr::polymod$participants$hh_size) 13 | } 14 | -------------------------------------------------------------------------------- /R/get_polymod_setting_data.R: -------------------------------------------------------------------------------- 1 | #' Get polymod setting data 2 | #' 3 | #' `get_polymod_setting_data()` acts as an extension of 4 | #' `get_polymod_contact_data()`, and extracts the setting wise contact data 5 | #' on the desired country, as a list. 6 | 7 | #' @param countries countries to extract data from 8 | #' @return A list of data frames, of the polymod data. One list per setting: 9 | #' "home", "work", "school", and "other". 10 | #' @examples 11 | #' get_polymod_setting_data() 12 | #' get_polymod_setting_data("Belgium") 13 | #' @export 14 | get_polymod_setting_data <- function( 15 | countries = c( 16 | "Belgium", 17 | "Finland", 18 | "Germany", 19 | "Italy", 20 | "Luxembourg", 21 | "Netherlands", 22 | "Poland", 23 | "United Kingdom" 24 | ) 25 | ) { 26 | list( 27 | home = get_polymod_contact_data( 28 | setting = "home", 29 | countries = countries 30 | ), 31 | work = get_polymod_contact_data( 32 | setting = "work", 33 | countries = countries 34 | ), 35 | school = get_polymod_contact_data( 36 | setting = "school", 37 | countries = countries 38 | ), 39 | other = get_polymod_contact_data( 40 | setting = "other", 41 | countries = countries 42 | ) 43 | ) %>% 44 | new_setting_data() 45 | } 46 | -------------------------------------------------------------------------------- /R/matrix_to_predictions.R: -------------------------------------------------------------------------------- 1 | #' @title Convert a contact matrix as output into a long-form tibble 2 | #' 3 | #' @description This function is the opposite of [predictions_to_matrix()]. It 4 | #' converts a wide matrix into a long data frame. It is mostly used within 5 | #' plotting functions. 6 | #' 7 | #' @param contact_matrix square matrix with age group to and from information 8 | #' in the row and column names. 9 | #' 10 | #' @return data.frame with columns `age_group_to`, `age_group_from`, and 11 | #' `contacts`. 12 | #' 13 | #' @examples 14 | #' fairfield <- abs_age_lga("Fairfield (C)") 15 | #' 16 | #' # We can convert the predictions into a matrix 17 | #' 18 | #' fairfield_school_contacts <- predict_contacts( 19 | #' model = polymod_setting_models$school, 20 | #' population = fairfield, 21 | #' age_breaks = c(0, 5, 10, 15, Inf) 22 | #' ) 23 | #' 24 | #' fairfield_school_contacts 25 | #' 26 | #' fairfield_school_mat <- predictions_to_matrix(fairfield_school_contacts) 27 | #' 28 | #' fairfield_school_mat 29 | #' 30 | #' matrix_to_predictions(fairfield_school_mat) 31 | #' @export 32 | matrix_to_predictions <- function(contact_matrix) { 33 | contact_matrix %>% 34 | tibble::as_tibble( 35 | rownames = "age_group_to" 36 | ) %>% 37 | dplyr::mutate(across(!age_group_to, as.double)) %>% 38 | tidyr::pivot_longer( 39 | cols = -c(age_group_to), 40 | names_to = "age_group_from", 41 | values_to = "contacts" 42 | ) %>% 43 | dplyr::mutate( 44 | dplyr::across( 45 | dplyr::starts_with("age_group"), 46 | ~ factor(.x, levels = unique(.x)) 47 | ) 48 | ) 49 | } 50 | -------------------------------------------------------------------------------- /R/polymod-data.R: -------------------------------------------------------------------------------- 1 | #' Social contact data from 8 European countries (imported from `socialmixr`) 2 | #' 3 | #' A dataset containing social mixing diary data from 8 European countries: 4 | #' Belgium, Germany, Finland, Great Britain, Italy, Luxembourg, 5 | #' The Netherlands and Poland. 6 | #' 7 | #' This data has been sourced from the [socialmixr](https://CRAN.R-project.org/package=socialmixr) package. 8 | #' 9 | #' The Data are fully described in Mossong J, Hens N, Jit M, Beutels P, Auranen 10 | #' K, Mikolajczyk R, et al. (2008) Social Contacts and Mixing Patterns Relevant 11 | #' to the Spread of Infectious Diseases. PLoS Med 5(3): e74. 12 | #' 13 | #' @format A list of two data frames: 14 | #' \describe{ 15 | #' \item{participants}{the study participant, with age, country, year and day 16 | #' of the week (starting with 1 = Monday)} 17 | #' \item{contacts}{reported contacts of the study participants. The variable 18 | #' phys_contact has two levels (1 denotes physical contact while 2 denotes 19 | #' non-physical contact), duration_multi has five levels (1 is less than 5 20 | #' minutes while 5 is more than 4 hours, increasing in the order found in 21 | #' Figure 1 in Mossong et al.), and frequency_multi has five levels (1 is 22 | #' daily, 2 is weekly, 3 is monthly, 4 is less often, and 5 is first time)} 23 | #' All other variables are described on the Zenodo repository of the data, 24 | #' available at \doi{10.5281/zenodo.1043437} 25 | #' } 26 | #' @source \doi{10.1371/journal.pmed.0050074} 27 | #' 28 | #' @name polymod 29 | #' @export 30 | "polymod" 31 | -------------------------------------------------------------------------------- /R/predictions_to_matrix.R: -------------------------------------------------------------------------------- 1 | #' @title Convert dataframe of predicted contacts into matrix 2 | #' 3 | #' @description Helper function to convert predictions of contact rates in data 4 | #' frames to matrix format with the survey participant age groups as columns 5 | #' and contact age groups as rows. 6 | #' 7 | #' @param contact_predictions data frame with columns `age_group_from`, 8 | #' `age_group_to`, and `contacts`. 9 | #' @param ... extra arguments 10 | #' 11 | #' @return Square matrix with the unique age groups from `age_group_from/to` 12 | #' in the rows and columns and `contacts` as the values. 13 | #' 14 | #' @examples 15 | #' fairfield <- abs_age_lga("Fairfield (C)") 16 | #' 17 | #' # We can convert the predictions into a matrix 18 | #' 19 | #' fairfield_school_contacts <- predict_contacts( 20 | #' model = polymod_setting_models$school, 21 | #' population = fairfield, 22 | #' age_breaks = c(0, 5, 10, 15, Inf) 23 | #' ) 24 | #' 25 | #' fairfield_school_contacts 26 | #' 27 | #' # convert them back to a matrix 28 | #' predictions_to_matrix(fairfield_school_contacts) 29 | #' 30 | #' @export 31 | predictions_to_matrix <- function(contact_predictions, ...) { 32 | UseMethod("predictions_to_matrix") 33 | } 34 | 35 | #' @export 36 | predictions_to_matrix.predicted_contacts <- function(contact_predictions, ...) { 37 | prediction_matrix <- contact_predictions %>% 38 | tidyr::pivot_wider( 39 | names_from = age_group_from, 40 | values_from = contacts 41 | ) %>% 42 | tibble::column_to_rownames( 43 | "age_group_to" 44 | ) %>% 45 | as.matrix() %>% 46 | new_age_matrix(age_breaks = age_breaks(contact_predictions)) 47 | 48 | prediction_matrix 49 | } 50 | -------------------------------------------------------------------------------- /R/setting-transmission-matrix.R: -------------------------------------------------------------------------------- 1 | new_transmission_probability_matrix <- function( 2 | list_matrix, 3 | age_breaks = NULL 4 | ) { 5 | structure( 6 | list_matrix, 7 | age_breaks = age_breaks, 8 | class = c("transmission_probability_matrix", class(list_matrix)) 9 | ) 10 | } 11 | 12 | #' Create a setting transmission matrix 13 | #' 14 | #' Helper function to create your own setting transmission matrix, which you 15 | #' may want to use in ... or `autoplot`. This class is the 16 | #' output of functions like `...`, and ... . We recommend using this 17 | #' function is only for advanced users, who are creating their own 18 | #' transmission probability matrix. 19 | #' 20 | #' @param ... list of matrices 21 | #' @param age_breaks age breaks - numeric 22 | #' 23 | #' @return transmission probability matrix 24 | #' 25 | #' @examples 26 | #' 27 | #' age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 28 | #' one_05 <- matrix(0.05, nrow = 9, ncol = 9) 29 | #' 30 | #' x_example <- transmission_probability_matrix( 31 | #' home = one_05, 32 | #' work = one_05, 33 | #' age_breaks = age_breaks_0_80_plus 34 | #' ) 35 | #' 36 | #' x_example <- transmission_probability_matrix( 37 | #' one_05, 38 | #' one_05, 39 | #' age_breaks = age_breaks_0_80_plus 40 | #' ) 41 | #' 42 | #' x_example 43 | #' 44 | #' @export 45 | transmission_probability_matrix <- function(..., age_breaks) { 46 | list_matrix <- prepare_list_matrix(...) 47 | 48 | setting_transmission_mat <- set_age_breaks_matrices( 49 | list_matrix, 50 | age_breaks 51 | ) 52 | 53 | new_transmission_probability_matrix( 54 | list_matrix = setting_transmission_mat, 55 | age_breaks = age_breaks 56 | ) 57 | } 58 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/R/sysdata.rda -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /conmat.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 6b48146e-4332-448c-9082-a9cd977e528e 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 1 note 4 | 5 | * This is a new release. 6 | -------------------------------------------------------------------------------- /data-raw/2016_abs_lga_education.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/2016_abs_lga_education.xls -------------------------------------------------------------------------------- /data-raw/31010do001_202012.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/31010do001_202012.xls -------------------------------------------------------------------------------- /data-raw/32350DS0003_2020.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/32350DS0003_2020.xls -------------------------------------------------------------------------------- /data-raw/32350ds0015_lga_2016.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/32350ds0015_lga_2016.xls -------------------------------------------------------------------------------- /data-raw/ABS_C16_G43_LGA_06092021163109650.csv.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/ABS_C16_G43_LGA_06092021163109650.csv.zip -------------------------------------------------------------------------------- /data-raw/Table 42b Number of Full-time and Part-time Students, 2006-2020.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/Table 42b Number of Full-time and Part-time Students, 2006-2020.xlsx -------------------------------------------------------------------------------- /data-raw/abs-avg-work-school.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `abs-avg-work-school` dataset goes here 2 | library(tidyverse) 3 | abs_avg_work <- data_abs_state_work %>% 4 | group_by( 5 | age 6 | ) %>% 7 | summarise( 8 | work_fraction = mean(proportion) 9 | ) 10 | 11 | usethis::use_data(abs_avg_work, overwrite = TRUE) 12 | 13 | abs_avg_school <- data_abs_state_education %>% 14 | group_by( 15 | age 16 | ) %>% 17 | summarise( 18 | school_fraction = mean(proportion) 19 | ) 20 | 21 | usethis::use_data(abs_avg_school, overwrite = TRUE) 22 | -------------------------------------------------------------------------------- /data-raw/clean-state-age-pop.R: -------------------------------------------------------------------------------- 1 | library(readxl) 2 | library(here) 3 | abs_state_age_names <- read_excel( 4 | here("data-raw/31010do001_202012.xls"), 5 | sheet = "Table_6", 6 | skip = 4, 7 | n_max = 1, 8 | # .name_repair = janitor::make_clean_names 9 | ) %>% 10 | names() 11 | 12 | abs_state_age <- read_excel( 13 | here("data-raw/31010do001_202012.xls"), 14 | sheet = "Table_6", 15 | skip = 51, 16 | n_max = 22 17 | ) %>% 18 | stats::setNames(abs_state_age_names) %>% 19 | pivot_longer( 20 | cols = -`Age group (years)`, 21 | names_to = "state", 22 | values_to = "population" 23 | ) %>% 24 | rename( 25 | age_group = `Age group (years)` 26 | ) %>% 27 | filter( 28 | age_group != "All ages", 29 | state != "Australia" 30 | ) %>% 31 | mutate(state = abs_abbreviate_states(state)) %>% 32 | relocate( 33 | state, 34 | age_group, 35 | population 36 | ) %>% 37 | mutate( 38 | # replace emdash. 39 | age_group = str_replace_all( 40 | age_group, 41 | "–", 42 | "-" 43 | ), 44 | age_group = case_when( 45 | age_group == "100 and over" ~ "100+", 46 | TRUE ~ age_group 47 | ), 48 | age_group = factor( 49 | age_group, 50 | levels = str_sort(unique(age_group), numeric = TRUE) 51 | ) 52 | ) 53 | 54 | abs_state_age 55 | 56 | use_data(abs_state_age, overwrite = TRUE) 57 | 58 | abs_state_age %>% 59 | pull(state) %>% 60 | unique() 61 | 62 | abs_state_age %>% 63 | group_by(state) %>% 64 | summarise(pop = sum(population)) 65 | -------------------------------------------------------------------------------- /data-raw/conmat-original-school-work-demographics.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `conmat-original-school-work-demographics` dataset goes here 2 | conmat_original_school_demographics <- tibble( 3 | age = 0:120, 4 | school_fraction = 0 5 | ) %>% 6 | mutate( 7 | school_fraction = case_when( 8 | # preschool 9 | age %in% 2:4 ~ 0.5, 10 | # compulsory education 11 | age %in% 5:16 ~ 1, 12 | # voluntary education 13 | age %in% 17:18 ~ 0.5, 14 | # university 15 | age %in% 19:25 ~ 0.1, 16 | # other 17 | .default = 0.05 18 | ) 19 | ) 20 | 21 | usethis::use_data(conmat_original_school_demographics, overwrite = TRUE) 22 | 23 | conmat_original_work_demographics <- tibble( 24 | age = 0:120, 25 | work_fraction = 0 26 | ) %>% 27 | mutate( 28 | work_fraction = case_when( 29 | # child labour 30 | age %in% 12:19 ~ 0.2, 31 | # young adults (not at school) 32 | age %in% 20:24 ~ 0.7, 33 | # main workforce 34 | age %in% 25:60 ~ 1, 35 | # possibly retired 36 | age %in% 61:65 ~ 0.7, 37 | .default = 0.05 38 | ) 39 | ) 40 | 41 | usethis::use_data(conmat_original_work_demographics, overwrite = TRUE) 42 | -------------------------------------------------------------------------------- /data-raw/create-age-lookup.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(stringr) 3 | 4 | agebreaks <- seq(5, 95, by = 5) 5 | 6 | age_group_lookup <- tibble( 7 | lower = c(0, agebreaks, 100), 8 | upper = c(agebreaks - 1, 99, Inf), 9 | age_group = as.character(glue::glue("{lower}-{upper}")) 10 | ) %>% 11 | mutate( 12 | age_group = case_when( 13 | age_group == "100-Inf" ~ "100+", 14 | TRUE ~ age_group 15 | ), 16 | age_group = factor(age_group, levels = str_sort(age_group, numeric = TRUE)) 17 | ) %>% 18 | arrange(age_group) 19 | 20 | use_data(age_group_lookup, compress = "xz", overwrite = TRUE) 21 | -------------------------------------------------------------------------------- /data-raw/create-polymod-model.R: -------------------------------------------------------------------------------- 1 | library(conmat) 2 | set.seed(2025 - 01 - 28 - 1802) 3 | polymod_contact_data <- get_polymod_setting_data() 4 | polymod_survey_data <- get_polymod_population() 5 | polymod_setting_models <- fit_setting_contacts( 6 | contact_data_list = polymod_contact_data, 7 | population = polymod_survey_data 8 | ) 9 | 10 | use_data(polymod_setting_models, compress = "xz", overwrite = TRUE) 11 | -------------------------------------------------------------------------------- /data-raw/euclidean_join.R: -------------------------------------------------------------------------------- 1 | #' .. content for \description{} (no empty lines) .. 2 | #' 3 | #' .. content for \details{} .. 4 | #' 5 | #' @title 6 | #' @param matrix_vals_prob_1y 7 | #' @return 8 | #' @author Nick Golding 9 | #' @export 10 | euclidean_join <- function( 11 | .data, 12 | legend, 13 | by = intersect(names(.data), names(legend)) 14 | ) { 15 | # Do Euclidean lookup from matrix pixels to legends 16 | 17 | # get Euclidean distance matrix between data and legend 18 | distances <- rdist( 19 | .data[, by], 20 | legend[, by] 21 | ) 22 | 23 | # find the index to the nearest value in the legend 24 | row_idx <- apply(distances, 1, which.min) 25 | 26 | # get the new columns from the legend 27 | by_col_idx <- match(by, names(legend)) 28 | new_cols <- legend[, -by_col_idx] 29 | 30 | # combine them 31 | bind_cols( 32 | .data, 33 | new_cols[row_idx, ] 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /data-raw/example_coverage.csv: -------------------------------------------------------------------------------- 1 | age_band,coverage 2 | 0-4,0 3 | 5-11,0.7820889525101082 4 | 12-15,0.9971432793183274 5 | 16-19,0.9649274624586409 6 | 20-24,0.860556304374464 7 | 25-29,0.9967516379452733 8 | 30-34,0.9975895955288322 9 | 35-39,0.9984371210692248 10 | 40-44,0.998604199538779 11 | 45-49,0.9930909578749665 12 | 50-54,0.9990267815304762 13 | 55-59,0.9960085589663402 14 | 60-64,0.9981836345472709 15 | 65-69,0.9987294192387104 16 | 70-74,0.9987040527803959 17 | 75-79,0.9993632601082458 18 | 80+,0.9985574510787757 19 | -------------------------------------------------------------------------------- /data-raw/example_vaccination_effect.R: -------------------------------------------------------------------------------- 1 | vaccination_effect_example_data <- readr::read_csv( 2 | "data-raw/example_vaccine_coverage_effects.csv" 3 | ) %>% 4 | select(age_band, coverage, acquisition, transmission) %>% 5 | tibble::as_tibble() 6 | 7 | use_data(vaccination_effect_example_data, overwrite = TRUE, compress = "xz") 8 | -------------------------------------------------------------------------------- /data-raw/example_vaccine_coverage_effects.csv: -------------------------------------------------------------------------------- 1 | "","age_band","coverage","acquisition","transmission" 2 | "1","0-4",0,0,0 3 | "2","5-11",0.782088952510108,0.583348020448795,0.254242125175986 4 | "3","12-15",0.997143279318327,0.630736845626691,0.29520141450591 5 | "4","16-19",0.964927462458641,0.785726788174996,0.468501974533669 6 | "5","20-24",0.860556304374464,0.773881063416946,0.452510195523648 7 | "6","25-29",0.996751637945273,0.777635190746242,0.457516726757208 8 | "7","30-34",0.997589595528832,0.803333898902261,0.493375883728513 9 | "8","35-39",0.998437121069225,0.829452617477711,0.532999555717037 10 | "9","40-44",0.998604199538779,0.840532514470851,0.550918490243109 11 | "10","45-49",0.993090957874966,0.847130527389007,0.56193778990949 12 | "11","50-54",0.999026781530476,0.856874277192424,0.578721996223268 13 | "12","55-59",0.99600855896634,0.863707121080198,0.590879600757979 14 | "13","60-64",0.998183634547271,0.858063939913767,0.580815060813119 15 | "14","65-69",0.99872941923871,0.863811707270404,0.591068293325172 16 | "15","70-74",0.998704052780396,0.867198718902789,0.597222829401988 17 | "16","75-79",0.999363260108246,0.866019640360234,0.595070628852981 18 | "17","80+",0.998557451078776,0.843558083086652,0.555937989293065 19 | -------------------------------------------------------------------------------- /data-raw/example_ves.csv: -------------------------------------------------------------------------------- 1 | age_band,acquisition,transmission 2 | 0-4,0,0 3 | 5-11,0.5833480204487952,0.2542421251759856 4 | 12-15,0.6307368456266914,0.29520141450590953 5 | 16-19,0.7857267881749961,0.46850197453366876 6 | 20-24,0.7738810634169461,0.4525101955236475 7 | 25-29,0.7776351907462423,0.4575167267572082 8 | 30-34,0.8033338989022614,0.49337588372851343 9 | 35-39,0.8294526174777109,0.5329995557170372 10 | 40-44,0.8405325144708513,0.5509184902431087 11 | 45-49,0.8471305273890065,0.5619377899094897 12 | 50-54,0.8568742771924244,0.5787219962232681 13 | 55-59,0.8637071210801979,0.5908796007579785 14 | 60-64,0.858063939913767,0.5808150608131187 15 | 65-69,0.863811707270404,0.5910682933251719 16 | 70-74,0.867198718902789,0.5972228294019883 17 | 75-79,0.866019640360234,0.5950706288529812 18 | 80+,0.8435580830866516,0.5559379892930646 19 | -------------------------------------------------------------------------------- /data-raw/eyre_legend_raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_legend_raw.png -------------------------------------------------------------------------------- /data-raw/eyre_transmission_events_activities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_transmission_events_activities.png -------------------------------------------------------------------------------- /data-raw/eyre_transmission_household.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_transmission_household.png -------------------------------------------------------------------------------- /data-raw/eyre_transmission_household_visitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_transmission_household_visitor.png -------------------------------------------------------------------------------- /data-raw/eyre_transmission_probabilities.csv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_transmission_probabilities.csv.gz -------------------------------------------------------------------------------- /data-raw/eyre_transmission_work_education.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/eyre_transmission_work_education.png -------------------------------------------------------------------------------- /data-raw/get_age_group_lookup.R: -------------------------------------------------------------------------------- 1 | #' .. content for \description{} (no empty lines) .. 2 | #' 3 | #' .. content for \details{} .. 4 | #' 5 | #' @title 6 | #' @param age_breaks 7 | #' @param age_breaks_1y 8 | #' @return 9 | #' @author Nick Golding 10 | #' @export 11 | get_age_group_lookup <- function( 12 | age_breaks, 13 | age_breaks_1y = 0:100, 14 | label_includes_upper = FALSE 15 | ) { 16 | n_breaks <- length(age_breaks) 17 | age_group_lookup <- expand.grid( 18 | age = age_breaks_1y, 19 | index = seq_len(n_breaks - 1) 20 | ) %>% 21 | mutate( 22 | lower = age_breaks[index], 23 | upper = age_breaks[index + 1] 24 | ) %>% 25 | filter( 26 | age >= lower & age < upper 27 | ) %>% 28 | mutate( 29 | label_includes_upper = label_includes_upper, 30 | upper = ifelse(label_includes_upper, upper, upper - 1), 31 | upper = paste0("-", upper), 32 | upper = if_else(upper == "-Inf", "+", upper), 33 | age_group = paste0(lower, upper) 34 | ) %>% 35 | select( 36 | age, 37 | age_group 38 | ) 39 | } 40 | -------------------------------------------------------------------------------- /data-raw/prem/contact_all.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/contact_all.rdata -------------------------------------------------------------------------------- /data-raw/prem/contact_home.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/contact_home.rdata -------------------------------------------------------------------------------- /data-raw/prem/contact_others.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/contact_others.rdata -------------------------------------------------------------------------------- /data-raw/prem/contact_school.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/contact_school.rdata -------------------------------------------------------------------------------- /data-raw/prem/contact_work.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/contact_work.rdata -------------------------------------------------------------------------------- /data-raw/prem/rural/contact_all_rural.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/rural/contact_all_rural.rdata -------------------------------------------------------------------------------- /data-raw/prem/rural/contact_home_rural.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/rural/contact_home_rural.rdata -------------------------------------------------------------------------------- /data-raw/prem/rural/contact_others_rural.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/rural/contact_others_rural.rdata -------------------------------------------------------------------------------- /data-raw/prem/rural/contact_school_rural.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/rural/contact_school_rural.rdata -------------------------------------------------------------------------------- /data-raw/prem/rural/contact_work_rural.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/rural/contact_work_rural.rdata -------------------------------------------------------------------------------- /data-raw/prem/urban/contact_all_urban.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/urban/contact_all_urban.rdata -------------------------------------------------------------------------------- /data-raw/prem/urban/contact_home_urban.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/urban/contact_home_urban.rdata -------------------------------------------------------------------------------- /data-raw/prem/urban/contact_others_urban.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/urban/contact_others_urban.rdata -------------------------------------------------------------------------------- /data-raw/prem/urban/contact_school_urban.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/urban/contact_school_urban.rdata -------------------------------------------------------------------------------- /data-raw/prem/urban/contact_work_urban.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data-raw/prem/urban/contact_work_urban.rdata -------------------------------------------------------------------------------- /data-raw/prem_germany_contact_matrices.R: -------------------------------------------------------------------------------- 1 | # Loads in the Prem matrices for Germany, taken from the 2021 paper. 2 | 3 | load("data-raw/prem/contact_home.rdata") 4 | load("data-raw/prem/contact_work.rdata") 5 | load("data-raw/prem/contact_school.rdata") 6 | load("data-raw/prem/contact_others.rdata") 7 | load("data-raw/prem/contact_all.rdata") 8 | 9 | # ISO3 code for Germany is DEU 10 | 11 | prem_home <- contact_home[["DEU"]] %>% 12 | t() 13 | 14 | prem_work <- contact_work[["DEU"]] %>% 15 | t() 16 | 17 | prem_school <- contact_school[["DEU"]] %>% 18 | t() 19 | 20 | prem_other <- contact_others[["DEU"]] %>% 21 | t() 22 | 23 | prem_all <- contact_all[["DEU"]] %>% 24 | t() 25 | 26 | prem_germany_contact_matrices <- list( 27 | "home" = prem_home, 28 | "work" = prem_work, 29 | "school" = prem_school, 30 | "other" = prem_other, 31 | "all" = prem_all 32 | ) 33 | 34 | usethis::use_data(prem_germany_contact_matrices, overwrite = TRUE) 35 | -------------------------------------------------------------------------------- /data-raw/read_setting_weights.R: -------------------------------------------------------------------------------- 1 | setting_weights <- c( 2 | home = 0.732154285228522, 3 | school = 0.286882796193768, 4 | work = 0.286882796193768, 5 | other = 0.286882796193768 6 | ) 7 | 8 | use_data(setting_weights, compress = "xz", overwrite = TRUE) 9 | -------------------------------------------------------------------------------- /data-raw/use-polymod.R: -------------------------------------------------------------------------------- 1 | library(socialmixr) 2 | usethis::use_data(polymod, internal = TRUE, overwrite = TRUE, compress = "xz") 3 | -------------------------------------------------------------------------------- /data/abs_avg_school.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_avg_school.rda -------------------------------------------------------------------------------- /data/abs_avg_work.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_avg_work.rda -------------------------------------------------------------------------------- /data/abs_education_state.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_education_state.rda -------------------------------------------------------------------------------- /data/abs_education_state_2020.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_education_state_2020.rda -------------------------------------------------------------------------------- /data/abs_employ_age_lga.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_employ_age_lga.rda -------------------------------------------------------------------------------- /data/abs_household_lga.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_household_lga.rda -------------------------------------------------------------------------------- /data/abs_lga_lookup.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_lga_lookup.rda -------------------------------------------------------------------------------- /data/abs_pop_age_lga_2016.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_pop_age_lga_2016.rda -------------------------------------------------------------------------------- /data/abs_pop_age_lga_2020.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_pop_age_lga_2020.rda -------------------------------------------------------------------------------- /data/abs_state_age.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/abs_state_age.rda -------------------------------------------------------------------------------- /data/age_group_lookup.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/age_group_lookup.rda -------------------------------------------------------------------------------- /data/conmat_original_school_demographics.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/conmat_original_school_demographics.rda -------------------------------------------------------------------------------- /data/conmat_original_work_demographics.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/conmat_original_work_demographics.rda -------------------------------------------------------------------------------- /data/data_abs_lga_education.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/data_abs_lga_education.rda -------------------------------------------------------------------------------- /data/data_abs_lga_work.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/data_abs_lga_work.rda -------------------------------------------------------------------------------- /data/data_abs_state_education.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/data_abs_state_education.rda -------------------------------------------------------------------------------- /data/data_abs_state_work.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/data_abs_state_work.rda -------------------------------------------------------------------------------- /data/davies_age_extended.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/davies_age_extended.rda -------------------------------------------------------------------------------- /data/eyre_transmission_probabilities.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/eyre_transmission_probabilities.rda -------------------------------------------------------------------------------- /data/polymod.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/polymod.rda -------------------------------------------------------------------------------- /data/polymod_setting_models.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/polymod_setting_models.rda -------------------------------------------------------------------------------- /data/prem_germany_contact_matrices.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/prem_germany_contact_matrices.rda -------------------------------------------------------------------------------- /data/setting_weights.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/setting_weights.rda -------------------------------------------------------------------------------- /data/vaccination_effect_example_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/data/vaccination_effect_example_data.rda -------------------------------------------------------------------------------- /flint/config.yml: -------------------------------------------------------------------------------- 1 | keep: 2 | - any_duplicated 3 | - any_is_na 4 | - class_equals 5 | - condition_message 6 | - double_assignment 7 | - duplicate_argument 8 | - empty_assignment 9 | - equal_assignment 10 | - equals_na 11 | - expect_comparison 12 | - expect_identical 13 | - expect_length 14 | - expect_named 15 | - expect_not 16 | - expect_null 17 | - expect_true_false 18 | - expect_type 19 | - for_loop_index 20 | - function_return 21 | - implicit_assignment 22 | - is_numeric 23 | - length_levels 24 | - length_test 25 | - lengths 26 | - library_call 27 | - list_comparison 28 | - literal_coercion 29 | - matrix_apply 30 | - missing_argument 31 | - nested_ifelse 32 | - numeric_leading_zero 33 | - outer_negation 34 | - package_hooks 35 | - paste 36 | - redundant_equals 37 | - redundant_ifelse 38 | - rep_len 39 | - right_assignment 40 | - sample_int 41 | - semicolon 42 | - seq 43 | - sort 44 | - stopifnot_all 45 | - T_and_F_symbol 46 | - todo_comment 47 | - undesirable_function 48 | - undesirable_operator 49 | - unnecessary_nesting 50 | - unreachable_code 51 | - which_grepl 52 | -------------------------------------------------------------------------------- /flint/rules/builtin/absolute_path.yml: -------------------------------------------------------------------------------- 1 | # id: absolute_path-1 2 | # language: r 3 | # severity: warning 4 | # rule: 5 | # kind: string_content 6 | # any: 7 | # - regex: '^~[[:alpha:]]' 8 | # - regex: '^~/[[:alpha:]]' 9 | # - regex: '^[[:alpha:]]:' 10 | # - regex: '^(/|~)$' 11 | # - regex: '^/[[:alpha:]]' 12 | # - regex: '^\\' 13 | # message: Do not use absolute paths. 14 | -------------------------------------------------------------------------------- /flint/rules/builtin/any_is_na.yml: -------------------------------------------------------------------------------- 1 | id: any_na-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: any(is.na($MYVAR)) 7 | - pattern: any(na.rm = $NARM, is.na($MYVAR)) 8 | - pattern: any(is.na($MYVAR), na.rm = $NARM) 9 | fix: anyNA(~~MYVAR~~) 10 | message: anyNA(x) is better than any(is.na(x)). 11 | 12 | --- 13 | 14 | id: any_na-2 15 | language: r 16 | severity: warning 17 | rule: 18 | any: 19 | - pattern: NA %in% $ELEM 20 | - pattern: NA_real_ %in% $ELEM 21 | - pattern: NA_logical_ %in% $ELEM 22 | - pattern: NA_character_ %in% $ELEM 23 | - pattern: NA_complex_ %in% $ELEM 24 | fix: anyNA(~~ELEM~~) 25 | message: anyNA(x) is better than NA %in% x. 26 | -------------------------------------------------------------------------------- /flint/rules/builtin/class_equals.yml: -------------------------------------------------------------------------------- 1 | id: class_equals-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: class($VAR) == $CLASSNAME 7 | - pattern: $CLASSNAME == class($VAR) 8 | not: 9 | inside: 10 | kind: argument 11 | fix: inherits(~~VAR~~, ~~CLASSNAME~~) 12 | message: Instead of comparing class(x) with ==, use inherits(x, 'class-name') or is. or is(x, 'class') 13 | 14 | --- 15 | 16 | id: class_equals-2 17 | language: r 18 | severity: warning 19 | rule: 20 | any: 21 | - pattern: class($VAR) != $CLASSNAME 22 | - pattern: $CLASSNAME != class($VAR) 23 | not: 24 | inside: 25 | kind: argument 26 | fix: "!inherits(~~VAR~~, ~~CLASSNAME~~)" 27 | message: "Instead of comparing class(x) with !=, use !inherits(x, 'class-name') or is. or is(x, 'class')" 28 | 29 | --- 30 | 31 | id: class_equals-3 32 | language: r 33 | severity: warning 34 | rule: 35 | any: 36 | - pattern: $CLASSNAME %in% class($VAR) 37 | - pattern: class($VAR) %in% $CLASSNAME 38 | constraints: 39 | CLASSNAME: 40 | kind: string 41 | fix: inherits(~~VAR~~, ~~CLASSNAME~~) 42 | message: Instead of comparing class(x) with %in%, use inherits(x, 'class-name') or is. or is(x, 'class') 43 | -------------------------------------------------------------------------------- /flint/rules/builtin/condition_message.yml: -------------------------------------------------------------------------------- 1 | id: condition_message-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: $FUN($$$ paste0($$$MSG) $$$) 6 | kind: call 7 | not: 8 | any: 9 | - has: 10 | kind: extract_operator 11 | - has: 12 | stopBy: end 13 | kind: argument 14 | has: 15 | field: name 16 | regex: "^collapse|recycle0$" 17 | stopBy: end 18 | constraints: 19 | FUN: 20 | regex: "^(packageStartupMessage|stop|warning)$" 21 | fix: ~~FUN~~(~~MSG~~) 22 | message: | 23 | ~~FUN~~(paste0(...)) can be rewritten as ~~FUN~~(...). 24 | -------------------------------------------------------------------------------- /flint/rules/builtin/double_assignment.yml: -------------------------------------------------------------------------------- 1 | id: right_double_assignment 2 | language: r 3 | severity: hint 4 | rule: 5 | pattern: $RHS ->> $LHS 6 | has: 7 | field: rhs 8 | kind: identifier 9 | message: ->> can have hard-to-predict behavior; prefer assigning to a 10 | specific environment instead (with assign() or <-). 11 | 12 | --- 13 | 14 | id: left_double_assignment 15 | language: r 16 | severity: hint 17 | rule: 18 | pattern: $LHS <<- $RHS 19 | has: 20 | field: lhs 21 | kind: identifier 22 | message: <<- can have hard-to-predict behavior; prefer assigning to a 23 | specific environment instead (with assign() or <-). 24 | -------------------------------------------------------------------------------- /flint/rules/builtin/duplicate_argument.yml: -------------------------------------------------------------------------------- 1 | id: duplicate_argument-1 2 | language: r 3 | severity: warning 4 | rule: 5 | # Look for a function argument... 6 | kind: argument 7 | any: 8 | - has: 9 | kind: identifier 10 | field: name 11 | pattern: $OBJ 12 | - has: 13 | kind: string_content 14 | pattern: $OBJ 15 | stopBy: end 16 | 17 | # ... that follows other argument(s) with the same name... 18 | follows: 19 | kind: argument 20 | stopBy: end 21 | has: 22 | stopBy: end 23 | kind: identifier 24 | field: name 25 | pattern: $OBJ 26 | 27 | # ... inside a function call (or a subset environment for data.table)... 28 | inside: 29 | kind: arguments 30 | follows: 31 | any: 32 | - kind: identifier 33 | pattern: $FUN 34 | - kind: string 35 | inside: 36 | any: 37 | - kind: call 38 | - kind: subset 39 | 40 | # ... that is not a function listed below. 41 | constraints: 42 | FUN: 43 | not: 44 | regex: ^(mutate|transmute)$ 45 | 46 | message: Avoid duplicate arguments in function calls. 47 | -------------------------------------------------------------------------------- /flint/rules/builtin/empty_assignment.yml: -------------------------------------------------------------------------------- 1 | id: empty_assignment-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $OBJ <- {} 7 | - pattern: $OBJ <- {$CONTENT} 8 | - pattern: $OBJ = {} 9 | - pattern: $OBJ = {$CONTENT} 10 | constraints: 11 | CONTENT: 12 | regex: ^\s+$ 13 | message: | 14 | Assign NULL explicitly or, whenever possible, allocate the empty object with 15 | the right type and size. 16 | -------------------------------------------------------------------------------- /flint/rules/builtin/equal_assignment.yml: -------------------------------------------------------------------------------- 1 | id: equal_assignment 2 | language: r 3 | severity: hint 4 | rule: 5 | pattern: $LHS = $RHS 6 | has: 7 | field: lhs 8 | kind: identifier 9 | fix: ~~LHS~~ <- ~~RHS~~ 10 | message: Use <-, not =, for assignment. 11 | -------------------------------------------------------------------------------- /flint/rules/builtin/equals_na.yml: -------------------------------------------------------------------------------- 1 | id: equals_na 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $MYVAR == NA 7 | - pattern: $MYVAR == NA_integer_ 8 | - pattern: $MYVAR == NA_real_ 9 | - pattern: $MYVAR == NA_complex_ 10 | - pattern: $MYVAR == NA_character_ 11 | - pattern: NA == $MYVAR 12 | - pattern: NA_integer_ == $MYVAR 13 | - pattern: NA_real_ == $MYVAR 14 | - pattern: NA_complex_ == $MYVAR 15 | - pattern: NA_character_ == $MYVAR 16 | fix: is.na(~~MYVAR~~) 17 | message: Use is.na for comparisons to NA (not == or !=). 18 | 19 | --- 20 | 21 | id: equals_na-2 22 | language: r 23 | severity: warning 24 | rule: 25 | any: 26 | - pattern: $MYVAR != NA 27 | - pattern: $MYVAR != NA_integer_ 28 | - pattern: $MYVAR != NA_real_ 29 | - pattern: $MYVAR != NA_complex_ 30 | - pattern: $MYVAR != NA_character_ 31 | - pattern: NA != $MYVAR 32 | - pattern: NA_integer_ != $MYVAR 33 | - pattern: NA_real_ != $MYVAR 34 | - pattern: NA_complex_ != $MYVAR 35 | - pattern: NA_character_ != $MYVAR 36 | fix: is.na(~~MYVAR~~) 37 | message: Use is.na for comparisons to NA (not == or !=). 38 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_comparison.yml: -------------------------------------------------------------------------------- 1 | id: expect_comparison-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: expect_true($X > $Y) 6 | fix: expect_gt(~~X~~, ~~Y~~) 7 | message: expect_gt(x, y) is better than expect_true(x > y). 8 | 9 | --- 10 | 11 | id: expect_comparison-2 12 | language: r 13 | severity: warning 14 | rule: 15 | pattern: expect_true($X >= $Y) 16 | fix: expect_gte(~~X~~, ~~Y~~) 17 | message: expect_gte(x, y) is better than expect_true(x >= y). 18 | 19 | --- 20 | 21 | id: expect_comparison-3 22 | language: r 23 | severity: warning 24 | rule: 25 | pattern: expect_true($X < $Y) 26 | fix: expect_lt(~~X~~, ~~Y~~) 27 | message: expect_lt(x, y) is better than expect_true(x < y). 28 | 29 | --- 30 | 31 | id: expect_comparison-4 32 | language: r 33 | severity: warning 34 | rule: 35 | pattern: expect_true($X <= $Y) 36 | fix: expect_lte(~~X~~, ~~Y~~) 37 | message: expect_lte(x, y) is better than expect_true(x <= y). 38 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_identical.yml: -------------------------------------------------------------------------------- 1 | id: expect_identical-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: expect_true(identical($VAL1, $VAL2)) 6 | fix: expect_identical(~~VAL1~~, ~~VAL2~~) 7 | message: Use expect_identical(x, y) instead of expect_true(identical(x, y)). 8 | 9 | --- 10 | 11 | id: expect_identical-2 12 | language: r 13 | severity: warning 14 | rule: 15 | pattern: expect_equal($VAL1, $VAL2) 16 | fix: expect_identical(~~VAL1~~, ~~VAL2~~) 17 | constraints: 18 | VAL1: 19 | all: 20 | - not: 21 | has: 22 | stopBy: end 23 | kind: float 24 | regex: \. 25 | - not: 26 | regex: ^typeof 27 | - not: 28 | pattern: NULL 29 | VAL2: 30 | all: 31 | - not: 32 | has: 33 | stopBy: end 34 | kind: float 35 | regex: \. 36 | - not: 37 | regex: ^typeof 38 | - not: 39 | pattern: NULL 40 | message: | 41 | Use expect_identical(x, y) by default; resort to expect_equal() only when 42 | needed, e.g. when setting ignore_attr= or tolerance=. 43 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_length.yml: -------------------------------------------------------------------------------- 1 | id: expect_length-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $FUN(length($OBJ), $VALUE) 7 | - pattern: $FUN($VALUE, length($OBJ)) 8 | constraints: 9 | FUN: 10 | regex: ^(expect_identical|expect_equal)$ 11 | VALUE: 12 | not: 13 | regex: length\( 14 | fix: expect_length(~~OBJ~~, ~~VALUE~~) 15 | message: expect_length(x, n) is better than ~~FUN~~(length(x), n). 16 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_not.yml: -------------------------------------------------------------------------------- 1 | id: expect_not-1 2 | language: r 3 | severity: warning 4 | rule: 5 | all: 6 | - pattern: expect_true(!$COND) 7 | - not: 8 | regex: '^expect_true\(!!' 9 | fix: expect_false(~~COND~~) 10 | message: expect_false(x) is better than expect_true(!x), and vice versa. 11 | 12 | --- 13 | 14 | id: expect_not-2 15 | language: r 16 | severity: warning 17 | rule: 18 | all: 19 | - pattern: expect_false(!$COND) 20 | - not: 21 | regex: '^expect_false\(!!' 22 | fix: expect_true(~~COND~~) 23 | message: expect_false(x) is better than expect_true(!x), and vice versa. 24 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_null.yml: -------------------------------------------------------------------------------- 1 | id: expect_null-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $FUN(NULL, $VALUES) 7 | - pattern: $FUN($VALUES, NULL) 8 | constraints: 9 | FUN: 10 | regex: ^(expect_identical|expect_equal)$ 11 | fix: expect_null(~~VALUES~~) 12 | message: expect_null(x) is better than ~~FUN~~(x, NULL). 13 | 14 | --- 15 | 16 | id: expect_null-2 17 | language: r 18 | severity: warning 19 | rule: 20 | pattern: expect_true(is.null($VALUES)) 21 | fix: expect_null(~~VALUES~~) 22 | message: expect_null(x) is better than expect_true(is.null(x)). 23 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_true_false.yml: -------------------------------------------------------------------------------- 1 | id: expect_true_false-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $FUN(TRUE, $VALUES) 7 | - pattern: $FUN($VALUES, TRUE) 8 | constraints: 9 | FUN: 10 | regex: ^(expect_identical|expect_equal)$ 11 | fix: expect_true(~~VALUES~~) 12 | message: expect_true(x) is better than ~~FUN~~(x, TRUE). 13 | 14 | --- 15 | 16 | id: expect_true_false-2 17 | language: r 18 | severity: warning 19 | rule: 20 | any: 21 | - pattern: $FUN(FALSE, $VALUES) 22 | - pattern: $FUN($VALUES, FALSE) 23 | constraints: 24 | FUN: 25 | regex: ^(expect_identical|expect_equal)$ 26 | fix: expect_false(~~VALUES~~) 27 | message: expect_false(x) is better than ~~FUN~~(x, FALSE). 28 | 29 | -------------------------------------------------------------------------------- /flint/rules/builtin/expect_type.yml: -------------------------------------------------------------------------------- 1 | id: expect_type-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: 7 | context: expect_identical(typeof($OBJ), $VALUES) 8 | strictness: ast 9 | - pattern: 10 | context: expect_identical($VALUES, typeof($OBJ)) 11 | strictness: ast 12 | constraints: 13 | VALUES: 14 | not: 15 | regex: typeof 16 | fix: expect_type(~~OBJ~~, ~~VALUES~~) 17 | message: expect_type(x, t) is better than expect_identical(typeof(x), t). 18 | 19 | --- 20 | 21 | id: expect_type-2 22 | language: r 23 | severity: warning 24 | rule: 25 | any: 26 | - pattern: 27 | context: expect_equal(typeof($OBJ), $VALUES) 28 | strictness: ast 29 | - pattern: 30 | context: expect_equal($VALUES, typeof($OBJ)) 31 | strictness: ast 32 | constraints: 33 | VALUES: 34 | not: 35 | regex: typeof 36 | fix: expect_type(~~OBJ~~, ~~VALUES~~) 37 | message: expect_type(x, t) is better than expect_equal(typeof(x), t). 38 | 39 | --- 40 | 41 | id: expect_type-3 42 | language: r 43 | severity: warning 44 | rule: 45 | pattern: expect_true($FUN($OBJ)) 46 | constraints: 47 | FUN: 48 | regex: ^is\. 49 | not: 50 | regex: data\.frame$ 51 | message: expect_type(x, t) is better than expect_true(is.(x)). 52 | -------------------------------------------------------------------------------- /flint/rules/builtin/for_loop_index.yml: -------------------------------------------------------------------------------- 1 | id: for_loop_index-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: for ($IDX in $IDX) 6 | message: Don't re-use any sequence symbols as the index symbol in a for loop. 7 | 8 | --- 9 | 10 | id: for_loop_index-2 11 | language: r 12 | severity: warning 13 | rule: 14 | pattern: for ($IDX in $SEQ) 15 | constraints: 16 | SEQ: 17 | kind: call 18 | has: 19 | kind: arguments 20 | has: 21 | kind: argument 22 | stopBy: end 23 | has: 24 | kind: identifier 25 | field: value 26 | pattern: $IDX 27 | message: Don't re-use any sequence symbols as the index symbol in a for loop. 28 | -------------------------------------------------------------------------------- /flint/rules/builtin/function_return.yml: -------------------------------------------------------------------------------- 1 | id: function_return-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: return($OBJ <- $VAL) 7 | - pattern: return($OBJ <<- $VAL) 8 | - pattern: return($VAL -> $OBJ) 9 | - pattern: return($VAL ->> $OBJ) 10 | message: | 11 | Move the assignment outside of the return() clause, or skip assignment altogether. 12 | -------------------------------------------------------------------------------- /flint/rules/builtin/is_numeric.yml: -------------------------------------------------------------------------------- 1 | id: is_numeric-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: is.numeric($VAR) || is.integer($VAR) 7 | - pattern: is.integer($VAR) || is.numeric($VAR) 8 | message: is.numeric(x) || is.integer(x) can be simplified to is.numeric(x). Use 9 | is.double(x) to test for objects stored as 64-bit floating point. 10 | 11 | --- 12 | 13 | id: is_numeric-2 14 | language: r 15 | severity: warning 16 | rule: 17 | any: 18 | - pattern: 19 | context: class($VAR) %in% c("numeric", "integer") 20 | strictness: ast 21 | - pattern: 22 | context: class($VAR) %in% c("integer", "numeric") 23 | strictness: ast 24 | message: class(x) %in% c("numeric", "integer") can be simplified to is.numeric(x). Use 25 | is.double(x) to test for objects stored as 64-bit floating point. 26 | -------------------------------------------------------------------------------- /flint/rules/builtin/length_levels.yml: -------------------------------------------------------------------------------- 1 | id: length_levels-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: length(levels($VAR)) 6 | fix: nlevels(~~VAR~~) 7 | message: nlevels(x) is better than length(levels(x)). df 8 | -------------------------------------------------------------------------------- /flint/rules/builtin/length_test.yml: -------------------------------------------------------------------------------- 1 | # Strangely, having something like pattern: length($VAR $OP $VAR2) doesn't work 2 | 3 | id: length_test-1 4 | language: r 5 | severity: warning 6 | rule: 7 | pattern: length($VAR == $VAR2) 8 | fix: length(~~VAR~~) == ~~VAR2~~ 9 | message: Checking the length of a logical vector is likely a mistake. 10 | 11 | --- 12 | 13 | id: length_test-2 14 | language: r 15 | severity: warning 16 | rule: 17 | pattern: length($VAR != $VAR2) 18 | fix: length(~~VAR~~) != ~~VAR2~~ 19 | message: Checking the length of a logical vector is likely a mistake. 20 | 21 | --- 22 | 23 | id: length_test-3 24 | language: r 25 | severity: warning 26 | rule: 27 | pattern: length($VAR > $VAR2) 28 | fix: length(~~VAR~~) > ~~VAR2~~ 29 | message: Checking the length of a logical vector is likely a mistake. 30 | 31 | --- 32 | 33 | id: length_test-4 34 | language: r 35 | severity: warning 36 | rule: 37 | pattern: length($VAR >= $VAR2) 38 | fix: length(~~VAR~~) >= ~~VAR2~~ 39 | message: Checking the length of a logical vector is likely a mistake. 40 | 41 | --- 42 | 43 | id: length_test-5 44 | language: r 45 | severity: warning 46 | rule: 47 | pattern: length($VAR < $VAR2) 48 | fix: length(~~VAR~~) < ~~VAR2~~ 49 | message: Checking the length of a logical vector is likely a mistake. 50 | 51 | --- 52 | 53 | id: length_test-6 54 | language: r 55 | severity: warning 56 | rule: 57 | pattern: length($VAR <= $VAR2) 58 | fix: length(~~VAR~~) <= ~~VAR2~~ 59 | message: Checking the length of a logical vector is likely a mistake. 60 | -------------------------------------------------------------------------------- /flint/rules/builtin/library_call.yml: -------------------------------------------------------------------------------- 1 | id: library_call 2 | language: r 3 | severity: warning 4 | rule: 5 | kind: call 6 | has: 7 | regex: ^library|require$ 8 | kind: identifier 9 | follows: 10 | not: 11 | any: 12 | - kind: call 13 | has: 14 | regex: ^library|require$ 15 | kind: identifier 16 | - kind: comment 17 | not: 18 | inside: 19 | stopBy: end 20 | any: 21 | - kind: function_definition 22 | - kind: call 23 | has: 24 | pattern: suppressPackageStartupMessages 25 | kind: identifier 26 | message: Move all library/require calls to the top of the script. 27 | -------------------------------------------------------------------------------- /flint/rules/builtin/list_comparison.yml: -------------------------------------------------------------------------------- 1 | id: list_comparison-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $FUN($$$) > $$$ 7 | - pattern: $FUN($$$) >= $$$ 8 | - pattern: $FUN($$$) < $$$ 9 | - pattern: $FUN($$$) <= $$$ 10 | - pattern: $FUN($$$) == $$$ 11 | - pattern: $FUN($$$) != $$$ 12 | constraints: 13 | FUN: 14 | regex: ^(lapply|map|Map|\.mapply)$ 15 | message: | 16 | The output of ~~FUN~~(), a list, is being coerced for comparison. 17 | Instead, use a mapper that generates a vector with the correct type directly, 18 | for example vapply(x, FUN, character(1L)) if the output is a string. 19 | -------------------------------------------------------------------------------- /flint/rules/builtin/missing_argument.yml: -------------------------------------------------------------------------------- 1 | id: missing_argument-1 2 | language: r 3 | severity: warning 4 | rule: 5 | kind: arguments 6 | has: 7 | kind: comma 8 | any: 9 | - precedes: 10 | stopBy: neighbor 11 | any: 12 | - regex: '^\)$' 13 | - kind: comma 14 | - follows: 15 | any: 16 | - regex: '^\($' 17 | - kind: argument 18 | regex: '=$' 19 | follows: 20 | kind: identifier 21 | not: 22 | regex: '^(quote|switch|alist)$' 23 | inside: 24 | kind: call 25 | message: Missing argument in function call. 26 | 27 | --- 28 | 29 | id: missing_argument-2 30 | language: r 31 | severity: warning 32 | rule: 33 | kind: arguments 34 | regex: '=(\s+|)\)$' 35 | follows: 36 | any: 37 | - kind: identifier 38 | - kind: extract_operator 39 | - kind: namespace_operator 40 | not: 41 | regex: '^(quote|switch|alist)$' 42 | inside: 43 | kind: call 44 | message: Missing argument in function call. 45 | -------------------------------------------------------------------------------- /flint/rules/builtin/nested_ifelse.yml: -------------------------------------------------------------------------------- 1 | id: nested_ifelse-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: $FUN($COND, $TRUE, $FALSE) 6 | constraints: 7 | FALSE: 8 | regex: ^(ifelse|if_else|fifelse) 9 | FUN: 10 | regex: ^(ifelse|if_else|fifelse) 11 | message: | 12 | Don't use nested ~~FUN~~() calls; instead, try (1) data.table::fcase; 13 | (2) dplyr::case_when; or (3) using a lookup table. 14 | 15 | --- 16 | 17 | id: nested_ifelse-2 18 | language: r 19 | severity: warning 20 | rule: 21 | pattern: $FUN($COND, $TRUE, $FALSE) 22 | constraints: 23 | TRUE: 24 | regex: ^(ifelse|if_else|fifelse) 25 | FUN: 26 | regex: ^(ifelse|if_else|fifelse) 27 | message: | 28 | Don't use nested ~~FUN~~() calls; instead, try (1) data.table::fcase; 29 | (2) dplyr::case_when; or (3) using a lookup table. 30 | -------------------------------------------------------------------------------- /flint/rules/builtin/numeric_leading_zero.yml: -------------------------------------------------------------------------------- 1 | id: numeric_leading_zero-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: $VALUE 6 | any: 7 | - kind: float 8 | - kind: identifier 9 | regex: ^\.[0-9] 10 | fix: 0~~VALUE~~ 11 | message: Include the leading zero for fractional numeric constants. 12 | -------------------------------------------------------------------------------- /flint/rules/builtin/outer_negation.yml: -------------------------------------------------------------------------------- 1 | id: outer_negation-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: all(!$VAR) 6 | constraints: 7 | VAR: 8 | not: 9 | regex: '^!' 10 | fix: '!any(~~VAR~~)' 11 | message: | 12 | !any(x) is better than all(!x). The former applies negation only once after 13 | aggregation instead of many times for each element of x. 14 | 15 | --- 16 | 17 | id: outer_negation-2 18 | language: r 19 | severity: warning 20 | rule: 21 | pattern: any(! $VAR) 22 | constraints: 23 | VAR: 24 | not: 25 | regex: '^!' 26 | fix: '!all(~~VAR~~)' 27 | message: | 28 | !all(x) is better than any(!x). The former applies negation only once after 29 | aggregation instead of many times for each element of x. 30 | -------------------------------------------------------------------------------- /flint/rules/builtin/redundant_equals.yml: -------------------------------------------------------------------------------- 1 | id: redundant_equals-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $VAR == TRUE 7 | - pattern: TRUE == $VAR 8 | - pattern: $VAR == FALSE 9 | - pattern: FALSE == $VAR 10 | message: | 11 | Using == on a logical vector is redundant. Well-named logical vectors can be 12 | used directly in filtering. For data.table's `i` argument, wrap the column 13 | name in (), like `DT[(is_treatment)]`. 14 | 15 | --- 16 | 17 | id: redundant_equals-2 18 | language: r 19 | severity: warning 20 | rule: 21 | any: 22 | - pattern: $VAR != TRUE 23 | - pattern: TRUE != $VAR 24 | - pattern: $VAR != FALSE 25 | - pattern: FALSE != $VAR 26 | message: | 27 | Using != on a logical vector is redundant. Well-named logical vectors can be 28 | used directly in filtering. For data.table's `i` argument, wrap the column 29 | name in (), like `DT[(is_treatment)]`. 30 | -------------------------------------------------------------------------------- /flint/rules/builtin/redundant_ifelse.yml: -------------------------------------------------------------------------------- 1 | id: redundant_ifelse-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: $FUN($COND, $VAL1, $VAL2) 6 | constraints: 7 | VAL1: 8 | regex: ^TRUE$ 9 | VAL2: 10 | regex: ^FALSE$ 11 | FUN: 12 | regex: ^(ifelse|fifelse|if_else)$ 13 | fix: ~~COND~~ 14 | message: | 15 | Use ~~COND~~ directly instead of calling ~~FUN~~(~~COND~~, TRUE, FALSE). 16 | 17 | --- 18 | 19 | id: redundant_ifelse-2 20 | language: r 21 | severity: warning 22 | rule: 23 | pattern: $FUN($COND, $VAL1, $VAL2) 24 | constraints: 25 | VAL1: 26 | regex: ^FALSE$ 27 | VAL2: 28 | regex: ^TRUE$ 29 | FUN: 30 | regex: ^(ifelse|fifelse|if_else)$ 31 | fix: '!(~~COND~~)' 32 | message: | 33 | Use !(~~COND~~) directly instead of calling ~~FUN~~(~~COND~~, FALSE, TRUE). 34 | 35 | --- 36 | 37 | id: redundant_ifelse-3 38 | language: r 39 | severity: warning 40 | rule: 41 | pattern: $FUN($COND, $VAL1, $VAL2) 42 | constraints: 43 | VAL1: 44 | regex: ^(1|1L)$ 45 | VAL2: 46 | regex: ^(0|0L)$ 47 | FUN: 48 | regex: ^(ifelse|fifelse|if_else)$ 49 | fix: as.integer(~~COND~~) 50 | message: Prefer as.integer(~~COND~~) to ~~FUN~~(~~COND~~, ~~VAL1~~, ~~VAL2~~). 51 | 52 | --- 53 | 54 | id: redundant_ifelse-4 55 | language: r 56 | severity: warning 57 | rule: 58 | pattern: $FUN($COND, $VAL1, $VAL2) 59 | constraints: 60 | VAL1: 61 | regex: ^(0|0L)$ 62 | VAL2: 63 | regex: ^(1|1L)$ 64 | FUN: 65 | regex: ^(ifelse|fifelse|if_else)$ 66 | fix: as.integer(!(~~COND~~)) 67 | message: Prefer as.integer(!(~~COND~~)) to ~~FUN~~(~~COND~~, ~~VAL1~~, ~~VAL2~~). 68 | -------------------------------------------------------------------------------- /flint/rules/builtin/rep_len.yml: -------------------------------------------------------------------------------- 1 | id: rep_len-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: rep($OBJ, length.out = $LEN) 6 | fix: rep_len(~~OBJ~~, ~~LEN~~) 7 | message: Use rep_len(x, n) instead of rep(x, length.out = n). 8 | -------------------------------------------------------------------------------- /flint/rules/builtin/right_assignment.yml: -------------------------------------------------------------------------------- 1 | id: right_assignment 2 | language: r 3 | severity: hint 4 | rule: 5 | pattern: $RHS -> $LHS 6 | has: 7 | field: rhs 8 | kind: identifier 9 | fix: ~~LHS~~<- ~~RHS~~ 10 | message: Use <-, not ->, for assignment. 11 | -------------------------------------------------------------------------------- /flint/rules/builtin/sample_int.yml: -------------------------------------------------------------------------------- 1 | id: sample_int-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: sample(1:$N, $$$OTHER) 7 | - pattern: sample(1L:$N, $$$OTHER) 8 | fix: sample.int(~~N~~, ~~OTHER~~) 9 | message: sample.int(n, m, ...) is preferable to sample(1:n, m, ...). 10 | 11 | --- 12 | 13 | id: sample_int-2 14 | language: r 15 | severity: warning 16 | rule: 17 | pattern: sample(seq($N), $$$OTHER) 18 | fix: sample.int(~~N~~, ~~OTHER~~) 19 | message: sample.int(n, m, ...) is preferable to sample(seq(n), m, ...). 20 | 21 | --- 22 | 23 | id: sample_int-3 24 | language: r 25 | severity: warning 26 | rule: 27 | pattern: sample(seq_len($N), $$$OTHER) 28 | fix: sample.int(~~N~~, ~~OTHER~~) 29 | message: sample.int(n, m, ...) is preferable to sample(seq_len(n), m, ...). 30 | 31 | --- 32 | 33 | # Strangely this panicks if I rename FIRST to N 34 | id: sample_int-4 35 | language: r 36 | severity: warning 37 | rule: 38 | pattern: sample($FIRST, $$$OTHER) 39 | constraints: 40 | FIRST: 41 | regex: ^\d+(L|)$ 42 | fix: sample.int(~~N~~, ~~OTHER~~) 43 | message: sample.int(n, m, ...) is preferable to sample(n, m, ...). 44 | -------------------------------------------------------------------------------- /flint/rules/builtin/semicolon.yml: -------------------------------------------------------------------------------- 1 | id: semicolon-1 2 | language: r 3 | severity: warning 4 | rule: 5 | regex: ;\s+$ 6 | not: 7 | inside: 8 | kind: string 9 | stopBy: end 10 | message: Trailing semicolons are not needed. 11 | -------------------------------------------------------------------------------- /flint/rules/builtin/stopifnot_all.yml: -------------------------------------------------------------------------------- 1 | id: stopifnot_all-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: stopifnot(all($$$CODE)) 6 | fix: stopifnot(~~CODE~~) 7 | message: | 8 | Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under 9 | the hood' and provides a better error message in case of failure. 10 | 11 | --- 12 | 13 | id: stopifnot_all-2 14 | language: r 15 | severity: warning 16 | rule: 17 | pattern: stopifnot(exprs = { all($$$CODE) }) 18 | fix: | 19 | stopifnot(exprs = { 20 | ~~CODE~~ 21 | }) 22 | message: | 23 | Use stopifnot(x) instead of stopifnot(all(x)). stopifnot(x) runs all() 'under 24 | the hood' and provides a better error message in case of failure. 25 | -------------------------------------------------------------------------------- /flint/rules/builtin/todo_comment.yml: -------------------------------------------------------------------------------- 1 | id: todo_comment-1 2 | language: r 3 | severity: warning 4 | rule: 5 | kind: comment 6 | regex: '(?i)#(|\s+)\b(todo|fixme)\b' 7 | message: Remove TODO comments. 8 | -------------------------------------------------------------------------------- /flint/rules/builtin/undesirable_function.yml: -------------------------------------------------------------------------------- 1 | id: undesirable_function-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: $FUN 6 | kind: identifier 7 | not: 8 | inside: 9 | kind: argument 10 | constraints: 11 | FUN: 12 | regex: ^(\.libPaths|attach|browser|debug|debugcall|debugonce|detach|par|setwd|Sys\.setenv|Sys\.setlocale|trace|undebug|untrace)$ 13 | message: Function "~~FUN~~()" is undesirable. 14 | -------------------------------------------------------------------------------- /flint/rules/builtin/undesirable_operator.yml: -------------------------------------------------------------------------------- 1 | id: undesirable_operator-1 2 | language: r 3 | severity: warning 4 | rule: 5 | any: 6 | - pattern: $X <<- $Y 7 | - pattern: $X ->> $Y 8 | message: | 9 | Avoid undesirable operators `<<-` and `->>`. They assign outside the current 10 | environment in a way that can be hard to reason about. Prefer fully-encapsulated 11 | functions wherever possible, or, if necessary, assign to a specific environment 12 | with assign(). Recall that you can create an environment at the desired scope 13 | with new.env(). 14 | 15 | --- 16 | 17 | id: undesirable_operator-2 18 | language: r 19 | severity: warning 20 | rule: 21 | kind: namespace_operator 22 | has: 23 | pattern: ':::' 24 | message: | 25 | Operator `:::` is undesirable. It accesses non-exported functions inside 26 | packages. Code relying on these is likely to break in future versions of the 27 | package because the functions are not part of the public interface and may be 28 | changed or removed by the maintainers without notice. Use public functions 29 | via :: instead. 30 | -------------------------------------------------------------------------------- /flint/rules/builtin/unnecessary_nesting.yml: -------------------------------------------------------------------------------- 1 | id: unnecessary_nesting-1 2 | language: r 3 | severity: warning 4 | rule: 5 | kind: if_statement 6 | any: 7 | - has: 8 | kind: 'braced_expression' 9 | field: consequence 10 | has: 11 | kind: if_statement 12 | stopBy: neighbor 13 | not: 14 | has: 15 | kind: 'braced_expression' 16 | field: alternative 17 | stopBy: end 18 | not: 19 | any: 20 | - has: 21 | nthChild: 2 22 | - precedes: 23 | regex: "^else$" 24 | - has: 25 | kind: if_statement 26 | field: consequence 27 | stopBy: neighbor 28 | # Can be in if(), but not else if() 29 | not: 30 | inside: 31 | field: alternative 32 | kind: if_statement 33 | message: | 34 | Don't use nested `if` statements, where a single `if` with the combined 35 | conditional expression will do. For example, instead of `if (x) { if (y) { ... }}`, 36 | use `if (x && y) { ... }`. 37 | -------------------------------------------------------------------------------- /flint/rules/builtin/unreachable_code.yml: -------------------------------------------------------------------------------- 1 | id: unreachable_code-1 2 | language: r 3 | severity: warning 4 | rule: 5 | regex: '[^}]+' 6 | not: 7 | regex: 'else' 8 | follows: 9 | any: 10 | - pattern: return($$$A) 11 | - pattern: stop($$$A) 12 | not: 13 | precedes: 14 | regex: 'else' 15 | stopBy: end 16 | message: Code and comments coming after a return() or stop() should be removed. 17 | 18 | --- 19 | 20 | id: unreachable_code-2 21 | language: r 22 | severity: warning 23 | rule: 24 | regex: '[^}]+' 25 | not: 26 | regex: 'else' 27 | follows: 28 | any: 29 | - pattern: next 30 | - pattern: break 31 | stopBy: end 32 | message: Remove code and comments coming after `next` or `break` 33 | 34 | --- 35 | 36 | id: unreachable_code-3 37 | language: r 38 | severity: warning 39 | rule: 40 | inside: 41 | any: 42 | - kind: if_statement 43 | pattern: if (FALSE) 44 | - kind: while_statement 45 | pattern: while (FALSE) 46 | stopBy: end 47 | message: Remove code inside a conditional loop with a deterministically false condition. 48 | 49 | --- 50 | 51 | id: unreachable_code-4 52 | language: r 53 | severity: warning 54 | rule: 55 | inside: 56 | any: 57 | - kind: if_statement 58 | pattern: if (TRUE) 59 | - kind: while_statement 60 | pattern: while (TRUE) 61 | stopBy: end 62 | message: | 63 | One branch has a a deterministically true condition. The other branches can 64 | be removed. 65 | -------------------------------------------------------------------------------- /flint/rules/builtin/which_grepl.yml: -------------------------------------------------------------------------------- 1 | id: which_grepl-1 2 | language: r 3 | severity: warning 4 | rule: 5 | pattern: which(grepl($$$ARGS)) 6 | fix: grep(~~ARGS~~) 7 | message: grep(pattern, x) is better than which(grepl(pattern, x)). 8 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Albury 2 | Auranen 3 | BGM 4 | Beutels 5 | CMD 6 | COVID 7 | CoV 8 | Codecov 9 | DOI 10 | Diekmann 11 | FTE 12 | Fairfield 13 | Generalised 14 | Heesterbrook 15 | Jit 16 | Klepac 17 | Koen 18 | LABOUR 19 | LGA 20 | LGAs 21 | Labour 22 | Liu 23 | Mikolajczyk 24 | Mossong 25 | NGM 26 | NGMs 27 | NSW 28 | ONS 29 | ORCID 30 | PLoS 31 | POLYMOD 32 | Peto 33 | Polymod 34 | Pouwels 35 | Prem 36 | Preprint 37 | Purver 38 | QLD 39 | TAS 40 | TableBuilder 41 | Un 42 | Visualisation 43 | Zenodo 44 | al 45 | assortativity 46 | asymptomatics 47 | autoplot 48 | behaviour 49 | centred 50 | cohorting 51 | davies 52 | deSolve 53 | digitise 54 | digitised 55 | doi 56 | ecovered 57 | eigen 58 | eigvenvalue 59 | embarrasingly 60 | emoved 61 | et 62 | eyre 63 | fairfield 64 | finalise 65 | focussed 66 | focusses 67 | gam 68 | generalised 69 | ggplot 70 | helpfile 71 | helpfiles 72 | https 73 | intergenerational 74 | ish 75 | labour 76 | lga 77 | magrittr 78 | modelled 79 | modellers 80 | modelling 81 | multisession 82 | nfected 83 | ngm 84 | njtierney 85 | parallelisable 86 | parallelisation 87 | parallelise 88 | pcbi 89 | polymod 90 | pre 91 | probabilists 92 | regularised 93 | sizeable 94 | socialmixr 95 | summarise 96 | summarised 97 | symptomatics 98 | th 99 | tibble 100 | tibbles 101 | transmissibility 102 | undercount 103 | unscaled 104 | unvaccinated 105 | upweighted 106 | usceptible 107 | visualisation 108 | visualisations 109 | visualise 110 | visualising 111 | wpp 112 | -------------------------------------------------------------------------------- /man/abs-age-education.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs_age_education.R 3 | \name{abs_age_education_state} 4 | \alias{abs_age_education_state} 5 | \alias{abs-age-education} 6 | \alias{abs_age_education_lga} 7 | \title{Return data on educated population for a given age and state or 8 | lga of Australia.} 9 | \usage{ 10 | abs_age_education_state(state = NULL, age = NULL) 11 | 12 | abs_age_education_lga(lga = NULL, age = NULL) 13 | } 14 | \arguments{ 15 | \item{state}{target Australian state name or a vector with multiple state 16 | names in its abbreviated form, such as "QLD", "NSW", or "TAS"} 17 | 18 | \item{age}{a numeric or numeric vector denoting ages between 0 to 115. The 19 | default is to return all ages.} 20 | 21 | \item{lga}{target Australian local government area (LGA) name, such as 22 | "Fairfield (C)" or a vector with multiple lga names. See 23 | \code{\link[=abs_lga_lookup]{abs_lga_lookup()}} for list of lga names.} 24 | } 25 | \value{ 26 | dataset with information on the number of educated people belonging 27 | to a particular age, its total population and the corresponding proportion. 28 | } 29 | \description{ 30 | Return data on educated population for a given age and state or 31 | lga of Australia. 32 | } 33 | \examples{ 34 | abs_age_education_state(state = "VIC") 35 | abs_age_education_state(state = "WA", age = 1:5) 36 | abs_age_education_state(state = c("QLD", "TAS"), age = 5) 37 | abs_age_education_lga(lga = c("Albury (C)", "Barcoo (S)"), age = 10) 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/abs-age-work.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs_age_work.R 3 | \name{abs_age_work_lga} 4 | \alias{abs_age_work_lga} 5 | \alias{abs-age-work} 6 | \alias{abs_age_work_state} 7 | \title{Return data on employed population for a given age and state or 8 | lga of Australia} 9 | \usage{ 10 | abs_age_work_lga(lga = NULL, age = NULL) 11 | 12 | abs_age_work_state(state = NULL, age = NULL) 13 | } 14 | \arguments{ 15 | \item{lga}{target Australian local government area (LGA) name, such as 16 | "Fairfield (C)" or a vector with multiple lga names. See 17 | \code{\link[=abs_lga_lookup]{abs_lga_lookup()}} for list of lga names.} 18 | 19 | \item{age}{a numeric or numeric vector denoting ages between 0 to 115. 20 | The default is to return all ages.} 21 | 22 | \item{state}{target Australian state name or a vector with multiple state 23 | names in its abbreviated form, such as "QLD", "NSW", or "TAS"} 24 | } 25 | \value{ 26 | data set with information on the number of employed people belonging 27 | to a particular age, its total population and the corresponding proportion. 28 | } 29 | \description{ 30 | Return data on employed population for a given age and state or 31 | lga of Australia 32 | } 33 | \examples{ 34 | abs_age_work_state(state = "NSW") 35 | abs_age_work_state(state = c("QLD", "TAS"), age = 5) 36 | abs_age_work_lga(lga = "Albany (C)", age = 1:5) 37 | abs_age_work_lga(lga = c("Albury (C)", "Barcoo (S)"), age = 39) 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/abs_abbreviate_states.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abbreviate_states.R 3 | \name{abs_abbreviate_states} 4 | \alias{abs_abbreviate_states} 5 | \title{Abbreviate Australian State Names} 6 | \usage{ 7 | abs_abbreviate_states(state_names) 8 | } 9 | \arguments{ 10 | \item{state_names}{vector of state names in long form} 11 | } 12 | \value{ 13 | shortened state names 14 | } 15 | \description{ 16 | Given a full name (Title Case) of an Australian State or Territory, produces 17 | the abbreviated state name. 18 | } 19 | \examples{ 20 | abs_abbreviate_states("Victoria") 21 | abs_abbreviate_states(c("Victoria", "Queensland")) 22 | } 23 | \seealso{ 24 | \code{\link[=abs_unabbreviate_states]{abs_unabbreviate_states()}} 25 | } 26 | -------------------------------------------------------------------------------- /man/abs_age_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs-helpers.R 3 | \name{abs_age_data} 4 | \alias{abs_age_data} 5 | \alias{abs_age_lga} 6 | \alias{abs_age_state} 7 | \title{Return Australian Bureau of Statistics (ABS) age population data for a 8 | given Local Government Area (LGA) or state} 9 | \usage{ 10 | abs_age_lga(lga_name) 11 | 12 | abs_age_state(state_name) 13 | } 14 | \arguments{ 15 | \item{lga_name}{lga name - can be a partial match, e.g., although the official name might be "Albury (C)", "Albury" is fine.} 16 | 17 | \item{state_name}{shortened state name} 18 | } 19 | \value{ 20 | a \code{conmat_population} dataset containing: \code{lga} (or \code{state}), 21 | \code{lower.age.limit}, \code{year}, and \code{population}. 22 | } 23 | \description{ 24 | Return Australian Bureau of Statistics (ABS) age population data for a 25 | given Local Government Area (LGA) or state 26 | } 27 | \examples{ 28 | abs_age_lga(c("Albury (C)", "Fairfield (C)")) 29 | abs_age_state(c("NSW", "VIC")) 30 | } 31 | -------------------------------------------------------------------------------- /man/abs_avg_school.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-abs-avg-work-school.R 3 | \docType{data} 4 | \name{abs_avg_school} 5 | \alias{abs_avg_school} 6 | \title{ABS education data for 2016} 7 | \format{ 8 | A data frame with 116 rows and 2 variables: 9 | \describe{ 10 | \item{age}{0 to 115} 11 | \item{school_fraction}{fraction of population at school} 12 | } 13 | } 14 | \source{ 15 | {Census of Population and Housing, 2016, TableBuilder} 16 | } 17 | \usage{ 18 | abs_avg_school 19 | } 20 | \description{ 21 | An internal dataset containing Australian Bureau of Statistics education data for 22 | each age in 2016. The data is averaged across each state to provide an 23 | overall average, and is used to provide estimated education populations for 24 | model fitting in \code{\link[=add_school_work_participation]{add_school_work_participation()}}, which is used in \code{\link[=fit_single_contact_model]{fit_single_contact_model()}}. The data is summarised from \code{data_abs_state_education}, 25 | see \code{?data_abs_state_education} for more details. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/abs_avg_work.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-abs-avg-work-school.R 3 | \docType{data} 4 | \name{abs_avg_work} 5 | \alias{abs_avg_work} 6 | \title{ABS work data for 2016} 7 | \format{ 8 | A data frame with 116 rows and 2 variables: 9 | \describe{ 10 | \item{age}{0 to 115} 11 | \item{work_fraction}{fraction of population working.} 12 | } 13 | } 14 | \source{ 15 | {Census of Population and Housing, 2016, TableBuilder} 16 | } 17 | \usage{ 18 | abs_avg_work 19 | } 20 | \description{ 21 | An internal dataset containing Australian Bureau of Statistics work data for 22 | each age in 2016. The data is averaged across each state to provide an 23 | overall average, and is used to provide estimated work populations for 24 | model fitting in \code{\link[=add_school_work_participation]{add_school_work_participation()}}, which is used in \code{\link[=fit_single_contact_model]{fit_single_contact_model()}}. The data is summarised from \code{data_abs_state_work}, 25 | see \code{?data_abs_state_work} for more details. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/abs_education_state.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_education_state.R 3 | \docType{data} 4 | \name{abs_education_state} 5 | \alias{abs_education_state} 6 | \title{ABS education by state for 2006-2020} 7 | \format{ 8 | A data frame with 4194 rows and 5 variables: 9 | \describe{ 10 | \item{year}{year - 2020} 11 | \item{state}{state - short state or territory name} 12 | \item{aboriginal_and_torres_strait_islander_status}{"Aboriginal and Torres Strait Islander" or "Non-Indigenous"} 13 | \item{age}{4 through to 21. Note that "4" is 4 or younger and "21" is actually 21+ (21 or older)} 14 | \item{n_full_and_part_time}{number of people full and part time} 15 | } 16 | } 17 | \source{ 18 | \url{https://www.abs.gov.au/statistics/people/education/schools/2020#data-download} (table 42B) 19 | } 20 | \usage{ 21 | abs_education_state 22 | } 23 | \description{ 24 | A dataset containing Australian Bureau of Statistics education data by 25 | state for 2006 to 2020 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/abs_education_state_2020.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_education_state_2020.R 3 | \docType{data} 4 | \name{abs_education_state_2020} 5 | \alias{abs_education_state_2020} 6 | \title{2020 ABS education population data, interpolated into 1 year bins, 7 | by state.} 8 | \format{ 9 | A data frame with 808 rows and 6 variables: 10 | \describe{ 11 | \item{year}{year - 2020} 12 | \item{state}{state - short state or territory name} 13 | \item{age}{0 to 100} 14 | \item{population}{number of people full and part time} 15 | \item{population_interpolated}{"Government" or "Non-government"} 16 | \item{prop}{population / population_interpolated} 17 | } 18 | } 19 | \source{ 20 | \url{https://www.abs.gov.au/statistics/people/education/schools/2020#data-download} (table 42B) 21 | } 22 | \usage{ 23 | abs_education_state_2020 24 | } 25 | \description{ 26 | A dataset containing Australian Bureau of Statistics education 27 | data by state for 2020. These were interpolated into 1 year age bins. 28 | There are still some issued with the methods used, as the interpolated 29 | values are sometimes higher than the population. 30 | } 31 | \keyword{datasets} 32 | -------------------------------------------------------------------------------- /man/abs_employ_age_lga.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_employ_age_lga.R 3 | \docType{data} 4 | \name{abs_employ_age_lga} 5 | \alias{abs_employ_age_lga} 6 | \title{ABS employment by age and LGA for 2016} 7 | \format{ 8 | A data frame with 5600 rows and 8 variables: 9 | \describe{ 10 | \item{year}{year - 2016} 11 | \item{state}{state - short state or territory name} 12 | \item{lga}{local government area name} 13 | \item{age_group}{age groups are as follows: 15-19, 20-24, 25-34, 35-44, 14 | 45-54, 55-64, 65-74, 75-84, 85+, total} 15 | \item{total_employed}{total number of people employed} 16 | \item{total_unemployed}{total number of people unemployed} 17 | \item{total_labour_force}{total number of people in the labour force} 18 | \item{total}{sum of these totals...or thereabouts??} 19 | } 20 | } 21 | \source{ 22 | ABS.stat \url{https://www.abs.gov.au/statistics} LABOUR > 23 | Employment and Unemployment > Labour force, Australia > 24 | Census 2016, G43 labour status by age and sex (LGA) 25 | } 26 | \usage{ 27 | abs_employ_age_lga 28 | } 29 | \description{ 30 | A dataset containing Australian Bureau of Statistics employment data by 31 | state for 2016 32 | } 33 | \note{ 34 | still need to finalise these columns 35 | } 36 | \keyword{datasets} 37 | -------------------------------------------------------------------------------- /man/abs_household_lga.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_household_lga.R 3 | \docType{data} 4 | \name{abs_household_lga} 5 | \alias{abs_household_lga} 6 | \title{ABS household data for 2016} 7 | \format{ 8 | A data frame with 4986 rows and 6 variables: 9 | \describe{ 10 | \item{year}{year - 2016} 11 | \item{state}{state - long state or territory name} 12 | \item{lga}{name of LGA} 13 | \item{n_persons_usually_resident}{Number of people typically in residence} 14 | \item{n_households}{number of households with that number of people} 15 | } 16 | } 17 | \source{ 18 | \url{https://www.abs.gov.au/statistics} 19 | (downloaded the CSV) PEOPLE > People and Communities > Household Composition > Census 2016, T23 Household Composition By Number Of Persons Usually Resident (LGA) 20 | } 21 | \usage{ 22 | abs_household_lga 23 | } 24 | \description{ 25 | A dataset containing Australian Bureau of Statistics household 26 | data for 2016. The data is filtered to "Total Households". Contains 27 | information on the number of people typically in a residence in the region 28 | and the number of households associated with those number of residents. 29 | This data is typically used to obtain the household size distributions to 30 | compute the per capita household size of a particular region. 31 | } 32 | \note{ 33 | still need to clean this 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/abs_lga_lookup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_lga_lookup.R 3 | \docType{data} 4 | \name{abs_lga_lookup} 5 | \alias{abs_lga_lookup} 6 | \title{ABS lookup table of states, lga code and lga name} 7 | \format{ 8 | A data frame with 544 rows and 3 variables, arrange by state then LGA 9 | \describe{ 10 | \item{state}{state - short state or territory name} 11 | \item{lga_code}{official lga code} 12 | \item{lga}{lga name} 13 | } 14 | } 15 | \usage{ 16 | abs_lga_lookup 17 | } 18 | \description{ 19 | A dataset containing Australian Bureau of Statistics official short state 20 | names, lga_code, and lga name. 21 | } 22 | \keyword{datasets} 23 | -------------------------------------------------------------------------------- /man/abs_pop_age_lga_2016.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-abs-pop-age-lga-2016.R 3 | \docType{data} 4 | \name{abs_pop_age_lga_2016} 5 | \alias{abs_pop_age_lga_2016} 6 | \title{ABS population by age for 2016 for LGAs} 7 | \format{ 8 | A data frame with 9918 rows and 6 variables: 9 | \describe{ 10 | \item{year}{year - 2020} 11 | \item{state}{state - short state or territory name} 12 | \item{lga}{LGA name} 13 | \item{age_group}{age age band, 0-4, in 5 year increments up to 80-84, then 85+} 14 | \item{population}{number of people in a given lga in an age band} 15 | } 16 | } 17 | \source{ 18 | \url{https://www.abs.gov.au/statistics/people/population/regional-population-age-and-sex} 19 | } 20 | \usage{ 21 | abs_pop_age_lga_2016 22 | } 23 | \description{ 24 | A dataset containing Australian Bureau of Statistics population data by 25 | local government area (LGA) for age for 2016 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/abs_pop_age_lga_2020.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-abs-pop-age-lga-2020.R 3 | \docType{data} 4 | \name{abs_pop_age_lga_2020} 5 | \alias{abs_pop_age_lga_2020} 6 | \title{ABS population by age for 2020 for LGAs} 7 | \format{ 8 | A data frame with 9900 rows and 6 variables: 9 | \describe{ 10 | \item{year}{year - 2020} 11 | \item{state}{state - long state or territory name} 12 | \item{lga}{LGA name} 13 | \item{age_group}{age group band, 0-4, in 5 year increments up to 80-84, then 85+} 14 | \item{population}{number of people in a given lga in an age band} 15 | } 16 | } 17 | \source{ 18 | \url{https://www.abs.gov.au/statistics/people/population/regional-population-age-and-sex} 19 | } 20 | \usage{ 21 | abs_pop_age_lga_2020 22 | } 23 | \description{ 24 | A dataset containing Australian Bureau of Statistics population data by 25 | local government area (LGA) for age for 2020 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/abs_state_age.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_state_age.R 3 | \docType{data} 4 | \name{abs_state_age} 5 | \alias{abs_state_age} 6 | \title{ABS state population data for 2020} 7 | \format{ 8 | A data frame with 168 rows and 3 variables: 9 | \describe{ 10 | \item{state}{state - short state or territory name} 11 | \item{age_group}{age group in five year bins from 0 to 99, then 100+} 12 | \item{population}{population size} 13 | } 14 | } 15 | \source{ 16 | \url{https://www.abs.gov.au/statistics/people/population/national-state-and-territory-population/dec-2020#data-downloads-data-cubes} 17 | } 18 | \usage{ 19 | abs_state_age 20 | } 21 | \description{ 22 | Dataset containing Australian Bureau of Statistics state level population 23 | data for 2020 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/abs_unabbreviate_states.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abbreviate_states.R 3 | \name{abs_unabbreviate_states} 4 | \alias{abs_unabbreviate_states} 5 | \title{Un-abbreviate Australian state names} 6 | \usage{ 7 | abs_unabbreviate_states(state_names) 8 | } 9 | \arguments{ 10 | \item{state_names}{vector of state names in short form} 11 | } 12 | \value{ 13 | Longer state names 14 | } 15 | \description{ 16 | Un-abbreviate Australian state names 17 | } 18 | \examples{ 19 | abs_unabbreviate_states("VIC") 20 | abs_unabbreviate_states(c("VIC", "QLD")) 21 | } 22 | \seealso{ 23 | \code{\link[=abs_abbreviate_states]{abs_abbreviate_states()}} 24 | } 25 | -------------------------------------------------------------------------------- /man/accessors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-population.R 3 | \name{age} 4 | \alias{age} 5 | \alias{age_label} 6 | \alias{age_label.default} 7 | \alias{age_label.conmat_population} 8 | \alias{population_label} 9 | \alias{population_label.default} 10 | \alias{population_label.conmat_population} 11 | \alias{population} 12 | \title{Accessing conmat attributes} 13 | \usage{ 14 | age(x) 15 | 16 | age_label(x) 17 | 18 | \method{age_label}{default}(x) 19 | 20 | \method{age_label}{conmat_population}(x) 21 | 22 | population_label(x) 23 | 24 | \method{population_label}{default}(x) 25 | 26 | \method{population_label}{conmat_population}(x) 27 | 28 | population(x) 29 | } 30 | \arguments{ 31 | \item{x}{conmat_population data frame} 32 | } 33 | \value{ 34 | age or population symbol or label 35 | } 36 | \description{ 37 | Accessing conmat attributes 38 | } 39 | \examples{ 40 | \dontrun{ 41 | perth <- abs_age_lga("Perth (C)") 42 | age(perth) 43 | age_label(perth) 44 | population(perth) 45 | population_label(perth) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /man/add_intergenerational.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_modelling_features.R 3 | \name{add_intergenerational} 4 | \alias{add_intergenerational} 5 | \title{Add column, "intergenerational"} 6 | \usage{ 7 | add_intergenerational(data) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame with columns \code{age_from}, and \code{age_to}} 11 | } 12 | \value{ 13 | data.frame with extra column, \code{intergenerational} 14 | } 15 | \description{ 16 | For modelling purposes it is useful to have a feature that is the absolute 17 | difference between \code{age_from} and \code{age_to} columns. 18 | } 19 | \examples{ 20 | 21 | polymod_contact <- get_polymod_contact_data() 22 | 23 | polymod_contact \%>\% add_intergenerational() 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/add_symmetrical_features.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_symmetrical_features.R 3 | \name{add_symmetrical_features} 4 | \alias{add_symmetrical_features} 5 | \title{Add symmetrical, age based features} 6 | \usage{ 7 | add_symmetrical_features(data) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame with columns, \code{age_from}, and \code{age_to}} 11 | } 12 | \value{ 13 | data.frame with 6 more columns, \code{gam_age_offdiag}, \code{gam_age_offdiag_2}, \code{gam_age_diag_prod}, \code{gam_age_diag_sum}, \code{gam_age_pmax}, \code{gam_age_pmin}, 14 | } 15 | \description{ 16 | This function adds 6 columns to assist with describing 17 | various age based interactions for model fitting. Requires that the 18 | age columns are called "age_from", and "age_to" 19 | } 20 | \examples{ 21 | vec_age <- 0:2 22 | dat_age <- expand.grid( 23 | age_from = vec_age, 24 | age_to = vec_age 25 | ) 26 | 27 | add_symmetrical_features(dat_age) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/age_group_lookup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_age_group_lookup.R 3 | \docType{data} 4 | \name{age_group_lookup} 5 | \alias{age_group_lookup} 6 | \title{Lookup table of age groups in 5 year bins} 7 | \format{ 8 | A data frame with 21 rows and 3 variables: 9 | \describe{ 10 | \item{lower}{Lower age} 11 | \item{upper}{upper age} 12 | \item{age_group}{age group as a factor} 13 | } 14 | } 15 | \usage{ 16 | age_group_lookup 17 | } 18 | \description{ 19 | A dataset containing age lower and upper levels with age group 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/as_conmat_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-population.R 3 | \name{as_conmat_population} 4 | \alias{as_conmat_population} 5 | \alias{as_conmat_population.default} 6 | \alias{as_conmat_population.data.frame} 7 | \alias{as_conmat_population.list} 8 | \alias{as_conmat_population.grouped_df} 9 | \title{Convert to conmat population} 10 | \usage{ 11 | as_conmat_population(data, ...) 12 | 13 | \method{as_conmat_population}{default}(data, ...) 14 | 15 | \method{as_conmat_population}{data.frame}(data, age, population, ...) 16 | 17 | \method{as_conmat_population}{list}(data, age, population, ...) 18 | 19 | \method{as_conmat_population}{grouped_df}(data, age, population, ...) 20 | } 21 | \arguments{ 22 | \item{data}{data.frame} 23 | 24 | \item{...}{extra arguments} 25 | 26 | \item{age}{age column - an unquoted variable of numeric integer ages} 27 | 28 | \item{population}{population column - an unquoted variable, numeric value} 29 | } 30 | \description{ 31 | Convert to conmat population 32 | } 33 | \examples{ 34 | some_age_pop <- data.frame( 35 | age = 1:10, 36 | pop = 101:110 37 | ) 38 | 39 | some_age_pop 40 | 41 | as_conmat_population( 42 | some_age_pop, 43 | age = age, 44 | population = pop 45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /man/as_setting_prediction_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setting-prediction-matrix.R 3 | \name{as_setting_prediction_matrix} 4 | \alias{as_setting_prediction_matrix} 5 | \title{Coerce object to a setting prediction matrix} 6 | \usage{ 7 | as_setting_prediction_matrix(list_matrix, age_breaks, ...) 8 | } 9 | \arguments{ 10 | \item{list_matrix}{list of matrices} 11 | 12 | \item{age_breaks}{numeric vector of ages} 13 | 14 | \item{...}{extra arguments (currently not used)} 15 | } 16 | \value{ 17 | object of class setting prediction matrix 18 | } 19 | \description{ 20 | This will also calculate an \code{all} matrix, if \code{all} is not specified. This 21 | is the sum of all other matrices. 22 | } 23 | \examples{ 24 | 25 | age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 26 | one_by_nine <- matrix(1, nrow = 9, ncol = 9) 27 | 28 | mat_list <- list( 29 | home = one_by_nine, 30 | work = one_by_nine 31 | ) 32 | 33 | mat_list 34 | 35 | mat_set <- as_setting_prediction_matrix( 36 | mat_list, 37 | age_breaks = age_breaks_0_80_plus 38 | ) 39 | 40 | mat_set 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/autoplot-conmat-partial.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/partial-prediction-helpers.R 3 | \name{autoplot.partial_predictions_sum} 4 | \alias{autoplot.partial_predictions_sum} 5 | \alias{autoplot.setting_partial_predictions_sum} 6 | \alias{autoplot-conmat-partial} 7 | \alias{autoplot.partial_predictions} 8 | \alias{autoplot.setting_partial_predictions} 9 | \title{Plot partial predictive plots using ggplot2} 10 | \usage{ 11 | \method{autoplot}{partial_predictions_sum}(object, ...) 12 | 13 | \method{autoplot}{setting_partial_predictions_sum}(object, ...) 14 | 15 | \method{autoplot}{partial_predictions}(object, ...) 16 | 17 | \method{autoplot}{setting_partial_predictions}(object, ...) 18 | } 19 | \arguments{ 20 | \item{object}{An object with partial predictions from \code{\link[=partial_effects]{partial_effects()}}.} 21 | 22 | \item{...}{Other arguments passed on. Currently not used.} 23 | } 24 | \value{ 25 | a ggplot visualisation of partial effects 26 | } 27 | \description{ 28 | Plot partial predictive plots using ggplot2 29 | } 30 | -------------------------------------------------------------------------------- /man/check_dimensions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkers.R 3 | \name{check_dimensions} 4 | \alias{check_dimensions} 5 | \title{Check dimensions} 6 | \usage{ 7 | check_dimensions(ngm, data) 8 | } 9 | \arguments{ 10 | \item{ngm}{list with next generation matrices at different settings} 11 | 12 | \item{data}{data frame} 13 | } 14 | \description{ 15 | An internal function used within \code{\link[=apply_vaccination]{apply_vaccination()}} to warn users of incompatible dimensions of 16 | data and the next generation matrices 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/check_if_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkers.R 3 | \name{check_if_list} 4 | \alias{check_if_list} 5 | \title{Check if data is a list} 6 | \usage{ 7 | check_if_list(contact_data) 8 | } 9 | \arguments{ 10 | \item{contact_data}{data on the contacts between two ages at different settings} 11 | } 12 | \description{ 13 | Check if data is a list 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/check_school_demographics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_work_school_demographics.R 3 | \name{check_school_demographics} 4 | \alias{check_school_demographics} 5 | \title{Check School Demographics} 6 | \usage{ 7 | check_school_demographics(school_demographics) 8 | } 9 | \arguments{ 10 | \item{school_demographics}{school data} 11 | } 12 | \description{ 13 | Check School Demographics 14 | } 15 | \author{ 16 | njtierney 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/check_work_demographics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_work_school_demographics.R 3 | \name{check_work_demographics} 4 | \alias{check_work_demographics} 5 | \title{Check Work Demographics} 6 | \usage{ 7 | check_work_demographics(work_demographics) 8 | } 9 | \arguments{ 10 | \item{work_demographics}{work data} 11 | } 12 | \description{ 13 | Check Work Demographics 14 | } 15 | \author{ 16 | njtierney 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/clean_age_population_year.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{clean_age_population_year} 4 | \alias{clean_age_population_year} 5 | \title{Prepare age population data} 6 | \usage{ 7 | clean_age_population_year( 8 | data, 9 | location_col = NULL, 10 | location = NULL, 11 | age_col, 12 | year_col = NULL, 13 | year = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{data.frame} 18 | 19 | \item{location_col}{bare unquoted variable referring to location column} 20 | 21 | \item{location}{location name to filter to. If not specified gives all locations.} 22 | 23 | \item{age_col}{bare unquoted variable referring to age column} 24 | 25 | \item{year_col}{bare unquoted variable referring to year column} 26 | 27 | \item{year}{year to filter to. If not specified, gives all years.} 28 | } 29 | \value{ 30 | data frame with \code{lower.age.limit} and \code{upper.age.limit} and 31 | optionally filtered down to specific location or year. 32 | } 33 | \description{ 34 | Internally used function within \code{\link[=age_population]{age_population()}} to separate age groups 35 | into its lower & upper limit and then filter the data passed to the desired 36 | year and location. 37 | } 38 | \keyword{internal} 39 | -------------------------------------------------------------------------------- /man/conmat-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-package.R 3 | \docType{package} 4 | \name{conmat-package} 5 | \alias{conmat} 6 | \alias{conmat-package} 7 | \title{conmat: Builds Contact Matrices using GAMs and Population Data} 8 | \description{ 9 | Builds contact matrices using GAMs and population data. This package incorporates data that is copyright Commonwealth of Australia (Australian Electoral Commission and Australian Bureau of Statistics) 2020. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://github.com/idem-lab/conmat} 15 | \item Report bugs at \url{https://github.com/idem-lab/conmat/issues} 16 | } 17 | 18 | } 19 | \author{ 20 | \strong{Maintainer}: Nicholas Tierney \email{nicholas.tierney@gmail.com} (\href{https://orcid.org/0000-0003-1460-8722}{ORCID}) [copyright holder] 21 | 22 | Authors: 23 | \itemize{ 24 | \item Nick Golding \email{nick.golding.research@gmail.com} (\href{https://orcid.org/0000-0001-8916-5570}{ORCID}) 25 | \item Aarathy Babu \email{aarathybabu907@gmail.com} (\href{https://orcid.org/0000-0002-6982-5989}{ORCID}) 26 | \item Chitra Saraswati \email{chitra.saraswati@telethonkids.org.au} (\href{https://orcid.org/0000-0002-8159-0414}{ORCID}) 27 | \item Michael Lydeamore \email{michael.lydeamore@monash.edu} (\href{https://orcid.org/0000-0001-6515-827X}{ORCID}) 28 | } 29 | 30 | Other contributors: 31 | \itemize{ 32 | \item Commonwealth of Australia AEC [copyright holder] 33 | \item Australian Bureau of Statistics ABS [copyright holder] 34 | } 35 | 36 | } 37 | \keyword{internal} 38 | -------------------------------------------------------------------------------- /man/conmat_original_school_demographics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_original_school_work.R 3 | \docType{data} 4 | \name{conmat_original_school_demographics} 5 | \alias{conmat_original_school_demographics} 6 | \title{Original school demographics for conmat} 7 | \format{ 8 | A data frame with 121 rows and 2 variables: 9 | \describe{ 10 | \item{age}{0 to 120} 11 | \item{school_fraction}{fraction of population at school} 12 | } 13 | } 14 | \source{ 15 | {Census of Population and Housing, 2016, TableBuilder} 16 | } 17 | \usage{ 18 | conmat_original_school_demographics 19 | } 20 | \description{ 21 | An internal dataset containing the original estimates of which fraction of 22 | ages were attending school in Australia. These can be used inside of 23 | \code{\link[=fit_single_contact_model]{fit_single_contact_model()}} and \code{\link[=fit_setting_contacts]{fit_setting_contacts()}}. 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/conmat_original_work_demographics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_original_school_work.R 3 | \docType{data} 4 | \name{conmat_original_work_demographics} 5 | \alias{conmat_original_work_demographics} 6 | \title{Original work demographics for conmat} 7 | \format{ 8 | A data frame with 121 rows and 2 variables: 9 | \describe{ 10 | \item{age}{0 to 120} 11 | \item{work_fraction}{fraction of population working.} 12 | } 13 | } 14 | \source{ 15 | {Census of Population and Housing, 2016, TableBuilder} 16 | } 17 | \usage{ 18 | conmat_original_work_demographics 19 | } 20 | \description{ 21 | An internal dataset containing the original estimates of which fraction of 22 | ages were working in Australia. These can be used inside of 23 | \code{\link[=fit_single_contact_model]{fit_single_contact_model()}} and \code{\link[=fit_setting_contacts]{fit_setting_contacts()}}. 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/conmat_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-population.R 3 | \name{conmat_population} 4 | \alias{conmat_population} 5 | \title{Define a conmat population} 6 | \usage{ 7 | conmat_population(data, age, population) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{age}{bare name representing the age column} 13 | 14 | \item{population}{bare name representing the population column} 15 | } 16 | \value{ 17 | a data frame with age and population attributes 18 | } 19 | \description{ 20 | A conmat population is a dataframe that stores which columns represent the 21 | age and population information. This is useful as it means we can refer 22 | to this information throughout other functions in the conmat package 23 | without needing to specify or hard code which columns represent the age 24 | and population information. 25 | } 26 | \examples{ 27 | perth <- abs_age_lga("Perth (C)") 28 | } 29 | -------------------------------------------------------------------------------- /man/data_abs_state_education.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_state_education.R 3 | \docType{data} 4 | \name{data_abs_state_education} 5 | \alias{data_abs_state_education} 6 | \title{State wise ABS education population data on different ages for year 2016} 7 | \format{ 8 | A data frame with 1044 rows and 6 variables: 9 | \describe{ 10 | \item{year}{2016, as data is from 2016 Census of Population and Housing.} 11 | \item{state}{String of abbreviated name of state or territory names, e.g., 12 | 'NSW', 'VIC', 'QLD' and so on.} 13 | \item{age}{Ages from 0 to 115.} 14 | \item{population_educated}{Number of people educated, including students 15 | with full-time, part-time status, and people who mentioned only the type 16 | of educational institution they attend and not their student status.} 17 | \item{total_population}{Total population belonging to age in a row.} 18 | \item{proportion}{The ratio of educated population and total population 19 | belonging to the age i.e, population_educated / total_population} 20 | } 21 | } 22 | \source{ 23 | {Census of Population and Housing, 2016, TableBuilder} 24 | } 25 | \usage{ 26 | data_abs_state_education 27 | } 28 | \description{ 29 | A dataset containing Australian Bureau of Statistics education data by state 30 | for 2016. The data sourced from 2016 Census - Employment, Income and 31 | Education through TableBuilder have been randomly adjusted by the ABS to 32 | avoid the release of confidential data. 33 | } 34 | \keyword{datasets} 35 | -------------------------------------------------------------------------------- /man/data_abs_state_work.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_abs_state_work.R 3 | \docType{data} 4 | \name{data_abs_state_work} 5 | \alias{data_abs_state_work} 6 | \title{State wise ABS work population data on different ages for year 2016} 7 | \format{ 8 | A data frame with 1044 rows and 6 variables: 9 | \describe{ 10 | \item{year}{2016, as data is from 2016 Census of Population and Housing.} 11 | \item{state}{String. Abbreviated name of state or territory, e.g., 'NSW', 12 | 'VIC', 'QLD' and so on.} 13 | \item{age}{Ages from 0 to 115.} 14 | \item{employed_population}{Number of people employed including people 15 | with full-time, part-time employment status.} 16 | \item{total_population}{Total population belonging to the age.} 17 | \item{proportion}{The ratio of employed population and total population 18 | belonging to the age i.e, employed_population/ total_population} 19 | } 20 | } 21 | \source{ 22 | {Census of Population and Housing, 2016, TableBuilder} 23 | } 24 | \usage{ 25 | data_abs_state_work 26 | } 27 | \description{ 28 | A dataset containing Australian Bureau of Statistics labour force population 29 | data by state for 2016. The data sourced from 2016 Census - Employment, 30 | Income and Education through TableBuilder have been randomly adjusted by 31 | the ABS to avoid the release of confidential data. 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/davies_age_extended.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data-davies-age-extended.R 3 | \docType{data} 4 | \name{davies_age_extended} 5 | \alias{davies_age_extended} 6 | \title{Susceptibility and clinical fraction parameters from Davies et al.} 7 | \format{ 8 | A data frame of the probability of transmission from a case to a contact. There are 101 rows and 4 variables. 9 | \describe{ 10 | \item{age}{from 0 to 100} 11 | \item{clinical_fraction}{Estimate of fraction with clinical symptoms, or the age-specific proportion of infections resulting in clinical symptoms inferred by applying a smoothing spline to the mean estimates from Davies et al. } 12 | \item{davies_original}{Age specific parameters of the relative susceptibility to 13 | infection inferred from a smoothing-spline estimate of the mean relative susceptibility estimate from Davies et al.} 14 | \item{davies_updated}{Re-estimated parameter of the susceptibility profile for under-16s that is estimated in a similar way but to the age-distribution of infections in England from the UK ONS prevalence survey rather than case counts which may undercount children} 15 | } 16 | } 17 | \usage{ 18 | davies_age_extended 19 | } 20 | \description{ 21 | A dataset containing data from \url{https://www.nature.com/articles/s41591-020-0962-9#code-availability} 22 | When using this data, ensure that you cite the original authors at: 23 | } 24 | \details{ 25 | "Davies, N.G., Klepac, P., Liu, Y. et al. Age-dependent effects in the transmission and control of COVID-19 epidemics. Nat Med 26, 1205–1211 (2020). https://doi.org/10.1038/s41591-020-0962-9" 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/figures/README-eyre-transmission-probabilities-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-eyre-transmission-probabilities-1.png -------------------------------------------------------------------------------- /man/figures/README-fairfield-synth-5-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-fairfield-synth-5-plot-1.png -------------------------------------------------------------------------------- /man/figures/README-matrix-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-matrix-plot-1.png -------------------------------------------------------------------------------- /man/figures/README-plot-matrix-differents-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-plot-matrix-differents-1.png -------------------------------------------------------------------------------- /man/figures/README-plot-matrix-differents-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-plot-matrix-differents-2.png -------------------------------------------------------------------------------- /man/figures/README-plot-matrix-differents-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-plot-matrix-differents-3.png -------------------------------------------------------------------------------- /man/figures/README-plot-matrix-differents-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-plot-matrix-differents-4.png -------------------------------------------------------------------------------- /man/figures/README-plot-matrix-differents-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-plot-matrix-differents-5.png -------------------------------------------------------------------------------- /man/figures/README-sydney-synth-5-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-sydney-synth-5-plot-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/man/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /man/formula-terms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model-tidiers.R 3 | \name{formula-terms} 4 | \alias{formula-terms} 5 | \alias{get_formulas_terms} 6 | \title{Extract out formula terms} 7 | \usage{ 8 | get_formulas_terms(model) 9 | } 10 | \arguments{ 11 | \item{model}{model object} 12 | } 13 | \description{ 14 | Extract out formula terms 15 | } 16 | \examples{ 17 | \dontrun{ 18 | formula_terms <- get_formulas_terms(sim_m) 19 | formula_terms 20 | } 21 | 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/get_abs_household_size_distribution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_household_size_distribution.R 3 | \name{get_abs_household_size_distribution} 4 | \alias{get_abs_household_size_distribution} 5 | \title{Get household size distribution based on state or LGA name} 6 | \usage{ 7 | get_abs_household_size_distribution(state = NULL, lga = NULL) 8 | } 9 | \arguments{ 10 | \item{state}{target Australian state name in abbreviated form, such as "QLD", "NSW", or "TAS"} 11 | 12 | \item{lga}{target Australian local government area (LGA) name, such as "Fairfield (C)". See 13 | \code{\link[=abs_lga_lookup]{abs_lga_lookup()}} for list of lga names} 14 | } 15 | \value{ 16 | returns a data frame with household size distributions of a specific state or LGA 17 | } 18 | \description{ 19 | Get household size distribution based on state or LGA name 20 | } 21 | \examples{ 22 | get_abs_household_size_distribution(lga = "Fairfield (C)") 23 | get_abs_household_size_distribution(state = "NSW") 24 | \dontrun{ 25 | # cannot specify both state and LGA 26 | get_abs_household_size_distribution(state = "NSW", lga = "Fairfield (C)") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /man/get_abs_household_size_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs_household_size_population.R 3 | \name{get_abs_household_size_population} 4 | \alias{get_abs_household_size_population} 5 | \title{Get population associated with each household size in an LGA or a state} 6 | \usage{ 7 | get_abs_household_size_population(state = NULL, lga = NULL) 8 | } 9 | \arguments{ 10 | \item{state}{target Australian state name in abbreviated form, such as "QLD", "NSW", or "TAS"} 11 | 12 | \item{lga}{target Australian local government area (LGA) name, such as "Fairfield (C)". See 13 | \code{\link[=abs_lga_lookup]{abs_lga_lookup()}} for list of lga names} 14 | } 15 | \value{ 16 | returns a data frame with household size and the population associated with it in each LGA or state. 17 | } 18 | \description{ 19 | Get population associated with each household size in an LGA or a state 20 | } 21 | \examples{ 22 | get_abs_household_size_population(state = "NSW") 23 | } 24 | -------------------------------------------------------------------------------- /man/get_abs_per_capita_household_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_abs_per_capita_household_size.R 3 | \name{get_abs_per_capita_household_size} 4 | \alias{get_abs_per_capita_household_size} 5 | \title{Get per capita household size based on state or LGA name} 6 | \usage{ 7 | get_abs_per_capita_household_size(state = NULL, lga = NULL) 8 | } 9 | \arguments{ 10 | \item{state}{state name} 11 | 12 | \item{lga}{lga name} 13 | } 14 | \value{ 15 | Numeric of length 1 - the per capita household size for a given state 16 | or LGA. 17 | } 18 | \description{ 19 | Get per capita household size based on state or LGA name 20 | } 21 | \examples{ 22 | get_abs_per_capita_household_size(lga = "Fairfield (C)") 23 | get_abs_per_capita_household_size(state = "NSW") 24 | \dontrun{ 25 | # cannot specify both state and LGA 26 | get_abs_per_capita_household_size(state = "NSW", lga = "Fairfield (C)") 27 | } 28 | } 29 | \author{ 30 | Nick Golding 31 | } 32 | -------------------------------------------------------------------------------- /man/get_abs_per_capita_household_size_lga.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs_per_capita_household_size_lga.R 3 | \name{get_abs_per_capita_household_size_lga} 4 | \alias{get_abs_per_capita_household_size_lga} 5 | \title{Get household size distribution based on LGA name} 6 | \usage{ 7 | get_abs_per_capita_household_size_lga(lga = NULL) 8 | } 9 | \arguments{ 10 | \item{lga}{target Australian local government area (LGA) name, such as "Fairfield (C)". See 11 | \code{\link[=abs_lga_lookup]{abs_lga_lookup()}} for list of lga names} 12 | } 13 | \value{ 14 | returns a numeric value depicting the per capita household size of the specified LGA 15 | } 16 | \description{ 17 | Get household size distribution based on LGA name 18 | } 19 | \examples{ 20 | get_abs_per_capita_household_size_lga(lga = "Fairfield (C)") 21 | 22 | } 23 | -------------------------------------------------------------------------------- /man/get_abs_per_capita_household_size_state.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/abs_per_capita_household_size_state.R 3 | \name{get_abs_per_capita_household_size_state} 4 | \alias{get_abs_per_capita_household_size_state} 5 | \title{Get household size distribution based on state name} 6 | \usage{ 7 | get_abs_per_capita_household_size_state(state = NULL) 8 | } 9 | \arguments{ 10 | \item{state}{target Australian state name in abbreviated form, such as "QLD", "NSW", or "TAS"} 11 | } 12 | \value{ 13 | returns a numeric value depicting the per capita household size of the specified state 14 | } 15 | \description{ 16 | Get household size distribution based on state name 17 | } 18 | \examples{ 19 | get_abs_per_capita_household_size_state(state = "NSW") 20 | } 21 | -------------------------------------------------------------------------------- /man/get_polymod_per_capita_household_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_polymod_per_capita_household_size.R 3 | \name{get_polymod_per_capita_household_size} 4 | \alias{get_polymod_per_capita_household_size} 5 | \title{Get polymod per capita household size.} 6 | \usage{ 7 | get_polymod_per_capita_household_size() 8 | } 9 | \value{ 10 | number, 3.248971 11 | } 12 | \description{ 13 | Convenience function to help get the per capita household size. 14 | This is calculated as \code{mean(socialmixr::polymod$participants$hh_size)}. 15 | } 16 | \examples{ 17 | get_polymod_per_capita_household_size() 18 | } 19 | \author{ 20 | Nicholas Tierney 21 | } 22 | -------------------------------------------------------------------------------- /man/get_polymod_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_polymod_population.R 3 | \name{get_polymod_population} 4 | \alias{get_polymod_population} 5 | \title{Return the polymod-average population age distribution in 5y} 6 | \usage{ 7 | get_polymod_population( 8 | countries = c("Belgium", "Finland", "Germany", "Italy", "Luxembourg", "Netherlands", 9 | "Poland", "United Kingdom") 10 | ) 11 | } 12 | \arguments{ 13 | \item{countries}{countries to extract data from. Default is to get: Belgium, 14 | Finland, Germany, Italy, Luxembourg, Netherlands, Poland, and 15 | United Kingdom.} 16 | } 17 | \value{ 18 | A \code{conmat_population} data frame with two columns: \code{lower.age.limit} 19 | and \code{population} 20 | } 21 | \description{ 22 | returns the polymod-average population age distribution in 23 | 5y increments (weight country population distributions by number of 24 | participants). Note that we don't want to weight by survey age 25 | distributions for this, since the total number of \emph{participants} 26 | represents the sampling. It uses the participant data from the polymod 27 | survey as well as the age specific population data from \code{socialmixr} 28 | R package to return the age specific average population of different, 29 | countries weighted by the number of participants from those countries who 30 | participated in the polymod survey. 31 | } 32 | \examples{ 33 | get_polymod_population() 34 | get_polymod_population("Belgium") 35 | get_polymod_population("United Kingdom") 36 | get_polymod_population("Italy") 37 | } 38 | -------------------------------------------------------------------------------- /man/get_polymod_setting_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_polymod_setting_data.R 3 | \name{get_polymod_setting_data} 4 | \alias{get_polymod_setting_data} 5 | \title{Get polymod setting data} 6 | \usage{ 7 | get_polymod_setting_data( 8 | countries = c("Belgium", "Finland", "Germany", "Italy", "Luxembourg", "Netherlands", 9 | "Poland", "United Kingdom") 10 | ) 11 | } 12 | \arguments{ 13 | \item{countries}{countries to extract data from} 14 | } 15 | \value{ 16 | A list of data frames, of the polymod data. One list per setting: 17 | "home", "work", "school", and "other". 18 | } 19 | \description{ 20 | \code{get_polymod_setting_data()} acts as an extension of 21 | \code{get_polymod_contact_data()}, and extracts the setting wise contact data 22 | on the desired country, as a list. 23 | } 24 | \examples{ 25 | get_polymod_setting_data() 26 | get_polymod_setting_data("Belgium") 27 | } 28 | -------------------------------------------------------------------------------- /man/matrix_to_predictions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/matrix_to_predictions.R 3 | \name{matrix_to_predictions} 4 | \alias{matrix_to_predictions} 5 | \title{Convert a contact matrix as output into a long-form tibble} 6 | \usage{ 7 | matrix_to_predictions(contact_matrix) 8 | } 9 | \arguments{ 10 | \item{contact_matrix}{square matrix with age group to and from information 11 | in the row and column names.} 12 | } 13 | \value{ 14 | data.frame with columns \code{age_group_to}, \code{age_group_from}, and 15 | \code{contacts}. 16 | } 17 | \description{ 18 | This function is the opposite of \code{\link[=predictions_to_matrix]{predictions_to_matrix()}}. It 19 | converts a wide matrix into a long data frame. It is mostly used within 20 | plotting functions. 21 | } 22 | \examples{ 23 | fairfield <- abs_age_lga("Fairfield (C)") 24 | 25 | # We can convert the predictions into a matrix 26 | 27 | fairfield_school_contacts <- predict_contacts( 28 | model = polymod_setting_models$school, 29 | population = fairfield, 30 | age_breaks = c(0, 5, 10, 15, Inf) 31 | ) 32 | 33 | fairfield_school_contacts 34 | 35 | fairfield_school_mat <- predictions_to_matrix(fairfield_school_contacts) 36 | 37 | fairfield_school_mat 38 | 39 | matrix_to_predictions(fairfield_school_mat) 40 | } 41 | -------------------------------------------------------------------------------- /man/new_age_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{new_age_matrix} 4 | \alias{new_age_matrix} 5 | \title{Build new age matrix} 6 | \usage{ 7 | new_age_matrix(matrix, age_breaks) 8 | } 9 | \arguments{ 10 | \item{matrix}{numeric matrix} 11 | 12 | \item{age_breaks}{character vector of age breaks, by default the rownames.} 13 | } 14 | \value{ 15 | matrix with age breaks attribute 16 | } 17 | \description{ 18 | A matrix that knows about its age breaks - which are by default provided as 19 | its rownames. Mostly intended for internal use. 20 | } 21 | \examples{ 22 | age_break_names <- c("[0,5)", "[5,10)", "[10, 15)") 23 | age_mat <- matrix( 24 | runif(9), 25 | nrow = 3, 26 | ncol = 3, 27 | dimnames = list( 28 | age_break_names, 29 | age_break_names 30 | ) 31 | ) 32 | 33 | new_age_matrix( 34 | age_mat, 35 | age_breaks = age_break_names 36 | ) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/new_conmat_population.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-population.R 3 | \name{new_conmat_population} 4 | \alias{new_conmat_population} 5 | \title{Create a new \code{conmat_population} class object} 6 | \usage{ 7 | new_conmat_population(data, age, population) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame} 11 | 12 | \item{age}{bare column name of numeric data on age} 13 | 14 | \item{population}{bare column name of numeric data on population} 15 | } 16 | \value{ 17 | object with class \code{conmat_population} 18 | } 19 | \description{ 20 | Create a new \code{conmat_population} class object 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/new_ngm_setting_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{new_ngm_setting_matrix} 4 | \alias{new_ngm_setting_matrix} 5 | \title{Establish new BGM setting data} 6 | \usage{ 7 | new_ngm_setting_matrix(list_matrix, raw_eigenvalue, scaling, age_breaks) 8 | } 9 | \arguments{ 10 | \item{list_matrix}{list of matrices} 11 | 12 | \item{raw_eigenvalue}{the raw eigenvalue} 13 | 14 | \item{scaling}{scaling factor} 15 | 16 | \item{age_breaks}{vector of age breaks} 17 | } 18 | \value{ 19 | object with additional (primary) class "ngm_setting_matrix", and attributes for "age_breaks", "scaling", and "raw_eigenvalue". 20 | } 21 | \description{ 22 | Establish new BGM setting data 23 | } 24 | -------------------------------------------------------------------------------- /man/new_setting_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{new_setting_data} 4 | \alias{new_setting_data} 5 | \title{Establish new setting data} 6 | \usage{ 7 | new_setting_data(list_df) 8 | } 9 | \arguments{ 10 | \item{list_df}{list of data frames} 11 | } 12 | \value{ 13 | object with additional (primary) class "setting data" and an "age_breaks attribute. 14 | } 15 | \description{ 16 | Establish new setting data 17 | } 18 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling \code{rhs(lhs)}. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/polymod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/polymod-data.R 3 | \docType{data} 4 | \name{polymod} 5 | \alias{polymod} 6 | \title{Social contact data from 8 European countries (imported from \code{socialmixr})} 7 | \format{ 8 | A list of two data frames: 9 | \describe{ 10 | \item{participants}{the study participant, with age, country, year and day 11 | of the week (starting with 1 = Monday)} 12 | \item{contacts}{reported contacts of the study participants. The variable 13 | phys_contact has two levels (1 denotes physical contact while 2 denotes 14 | non-physical contact), duration_multi has five levels (1 is less than 5 15 | minutes while 5 is more than 4 hours, increasing in the order found in 16 | Figure 1 in Mossong et al.), and frequency_multi has five levels (1 is 17 | daily, 2 is weekly, 3 is monthly, 4 is less often, and 5 is first time)} 18 | All other variables are described on the Zenodo repository of the data, 19 | available at \doi{10.5281/zenodo.1043437} 20 | } 21 | } 22 | \source{ 23 | \doi{10.1371/journal.pmed.0050074} 24 | } 25 | \usage{ 26 | polymod 27 | } 28 | \description{ 29 | A dataset containing social mixing diary data from 8 European countries: 30 | Belgium, Germany, Finland, Great Britain, Italy, Luxembourg, 31 | The Netherlands and Poland. 32 | } 33 | \details{ 34 | This data has been sourced from the \href{https://CRAN.R-project.org/package=socialmixr}{socialmixr} package. 35 | 36 | The Data are fully described in Mossong J, Hens N, Jit M, Beutels P, Auranen 37 | K, Mikolajczyk R, et al. (2008) Social Contacts and Mixing Patterns Relevant 38 | to the Spread of Infectious Diseases. PLoS Med 5(3): e74. 39 | } 40 | \keyword{datasets} 41 | -------------------------------------------------------------------------------- /man/polymod_setting_models.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_polymod_model.R 3 | \docType{data} 4 | \name{polymod_setting_models} 5 | \alias{polymod_setting_models} 6 | \title{Polymod Settings models} 7 | \format{ 8 | An object of class \code{setting_contact_model} (inherits from \code{list}) of length 4. 9 | } 10 | \usage{ 11 | polymod_setting_models 12 | } 13 | \description{ 14 | A data object containing a list of fitted gam models 15 | predicting the number of contacts in each of the four settings which are 16 | "home","work","school" and "other". For more details on model fitting, 17 | see \code{\link[=fit_setting_contacts]{fit_setting_contacts()}}. This object has been provided as data to 18 | avoid recomputing a relatively common type of model for use with \code{conmat}. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | # code used to produce this data 23 | library(conmat) 24 | set.seed(2022 - 08 - 26) 25 | polymod_contact_data <- get_polymod_setting_data() 26 | polymod_survey_data <- get_polymod_population() 27 | polymod_setting_models <- fit_setting_contacts( 28 | contact_data_list = polymod_contact_data, 29 | # population = polymod_survey_data 30 | ) 31 | } 32 | 33 | } 34 | \seealso{ 35 | \code{\link[=fit_setting_contacts]{fit_setting_contacts()}} 36 | } 37 | \keyword{datasets} 38 | -------------------------------------------------------------------------------- /man/predictions_to_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predictions_to_matrix.R 3 | \name{predictions_to_matrix} 4 | \alias{predictions_to_matrix} 5 | \title{Convert dataframe of predicted contacts into matrix} 6 | \usage{ 7 | predictions_to_matrix(contact_predictions, ...) 8 | } 9 | \arguments{ 10 | \item{contact_predictions}{data frame with columns \code{age_group_from}, 11 | \code{age_group_to}, and \code{contacts}.} 12 | 13 | \item{...}{extra arguments} 14 | } 15 | \value{ 16 | Square matrix with the unique age groups from \code{age_group_from/to} 17 | in the rows and columns and \code{contacts} as the values. 18 | } 19 | \description{ 20 | Helper function to convert predictions of contact rates in data 21 | frames to matrix format with the survey participant age groups as columns 22 | and contact age groups as rows. 23 | } 24 | \examples{ 25 | fairfield <- abs_age_lga("Fairfield (C)") 26 | 27 | # We can convert the predictions into a matrix 28 | 29 | fairfield_school_contacts <- predict_contacts( 30 | model = polymod_setting_models$school, 31 | population = fairfield, 32 | age_breaks = c(0, 5, 10, 15, Inf) 33 | ) 34 | 35 | fairfield_school_contacts 36 | 37 | # convert them back to a matrix 38 | predictions_to_matrix(fairfield_school_contacts) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/prem_germany_contact_matrices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_prem_contact_matrices.R 3 | \docType{data} 4 | \name{prem_germany_contact_matrices} 5 | \alias{prem_germany_contact_matrices} 6 | \title{Contact matrices as calculated by Prem. et al.} 7 | \format{ 8 | A list with 5 elements: 9 | \describe{ 10 | \item{home}{A 16x16 matrix containing the number of home contacts, by 5 11 | year age group} 12 | \item{work}{A 16x16 matrix containing the number of workplace contacts, by 13 | 5 year age group} 14 | \item{school}{A 16x16 matrix containing the number of school contacts, by 5 15 | year age group} 16 | \item{other}{A 16x16 matrix containing the number of other contacts, by 5 17 | year age group} 18 | \item{all}{A 16x16 matrix containing the number of all contacts, by 5 19 | year age group} 20 | } 21 | All age groups are 5 year age bands, from 0 to 80. 22 | } 23 | \source{ 24 | \url{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1009098} 25 | 26 | \url{https://github.com/kieshaprem/synthetic-contact-matrices} 27 | } 28 | \usage{ 29 | prem_germany_contact_matrices 30 | } 31 | \description{ 32 | Contact matrices as calculated by Prem. et al. (2021) PLoS Computational Biology. Updated to use the latest corrected matrices from their 2021 publication. 33 | DOI: 10.1371/journal.pcbi.1009098 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/prepare_population_for_modelling.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get-age-population-function-internals.R 3 | \name{prepare_population_for_modelling} 4 | \alias{prepare_population_for_modelling} 5 | \alias{prepare_population_for_modelling.conmat_population} 6 | \alias{prepare_population_for_modelling.data.frame} 7 | \title{Prepare population data for generating an age population function} 8 | \usage{ 9 | prepare_population_for_modelling(data, ...) 10 | 11 | \method{prepare_population_for_modelling}{conmat_population}(data, ...) 12 | 13 | \method{prepare_population_for_modelling}{data.frame}( 14 | data = data, 15 | age_col = age_col, 16 | pop_col = pop_col, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{data}{data.frame} 22 | 23 | \item{...}{extra arguments} 24 | 25 | \item{age_col}{column of ages} 26 | 27 | \item{pop_col}{column of population,} 28 | } 29 | \value{ 30 | list of objects, \code{max_bound} \code{pop_model_bounded} \code{bounded_pop} \code{unbounded_pop} for use in \code{\link[=get_age_population_function]{get_age_population_function()}} 31 | } 32 | \description{ 33 | Prepares objects for use in \code{\link[=get_age_population_function]{get_age_population_function()}}. 34 | } 35 | \examples{ 36 | prepare_population_for_modelling(get_polymod_population()) 37 | 38 | } 39 | \author{ 40 | njtierney 41 | } 42 | \keyword{internal} 43 | -------------------------------------------------------------------------------- /man/raw_eigenvalue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{raw_eigenvalue} 4 | \alias{raw_eigenvalue} 5 | \title{Get raw eigvenvalue from NGM matrix} 6 | \usage{ 7 | raw_eigenvalue(list_matrix) 8 | } 9 | \arguments{ 10 | \item{list_matrix}{object of class \code{ngm_setting_matrix}} 11 | } 12 | \value{ 13 | raw eigenvalue 14 | } 15 | \description{ 16 | Get raw eigvenvalue from NGM matrix 17 | } 18 | \examples{ 19 | # examples not run as they take a long time 20 | \dontrun{ 21 | perth <- abs_age_lga("Perth (C)") 22 | perth_contact <- extrapolate_polymod(perth) 23 | perth_ngm <- generate_ngm( 24 | perth_contact, 25 | age_breaks = c(seq(0, 85, by = 5), Inf) 26 | ) 27 | raw_eigenvalue(perth_ngm) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/conmat-package.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{autoplot} 7 | \title{Objects exported from other packages} 8 | \keyword{internal} 9 | \description{ 10 | These objects are imported from other packages. Follow the links 11 | below to see their documentation. 12 | 13 | \describe{ 14 | \item{ggplot2}{\code{\link[ggplot2]{autoplot}}} 15 | }} 16 | 17 | -------------------------------------------------------------------------------- /man/scaling.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{scaling} 4 | \alias{scaling} 5 | \title{Get the scaling from NGM matrix} 6 | \usage{ 7 | scaling(list_matrix) 8 | } 9 | \arguments{ 10 | \item{list_matrix}{object of class \code{ngm_setting_matrix}} 11 | } 12 | \value{ 13 | scaling 14 | } 15 | \description{ 16 | This value is \code{scaling <- R_target / R_raw}, where \code{R_target} is the target 17 | R value provided to the NGM, and \code{R_raw} is the raw eigenvalue. 18 | } 19 | \examples{ 20 | # examples not run as they take a long time 21 | \dontrun{ 22 | perth <- abs_age_lga("Perth (C)") 23 | perth_contact <- extrapolate_polymod(perth) 24 | perth_ngm <- generate_ngm( 25 | perth_contact, 26 | age_breaks = c(seq(0, 85, by = 5), Inf) 27 | ) 28 | raw_eigenvalue(perth_ngm) 29 | scaling(perth_ngm) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /man/separate_age_group.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{separate_age_group} 4 | \alias{separate_age_group} 5 | \title{Separate age groups} 6 | \usage{ 7 | separate_age_group(data, age_col) 8 | } 9 | \arguments{ 10 | \item{data}{data frame} 11 | 12 | \item{age_col}{bare unquoted column referring to age column} 13 | } 14 | \value{ 15 | data frame with two extra columns, \code{lower.age.limit} and 16 | \code{upper.age.limit} 17 | } 18 | \description{ 19 | An internal function used within \code{\link[=clean_age_population_year]{clean_age_population_year()}} to 20 | separate age groups in a data set into two variables, \code{lower.age.limit}, 21 | and \code{upper.age.limit} 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /man/setting_prediction_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setting-prediction-matrix.R 3 | \name{setting_prediction_matrix} 4 | \alias{setting_prediction_matrix} 5 | \title{Create a setting prediction matrix} 6 | \usage{ 7 | setting_prediction_matrix(..., age_breaks) 8 | } 9 | \arguments{ 10 | \item{...}{list of matrices} 11 | 12 | \item{age_breaks}{age breaks - numeric} 13 | } 14 | \value{ 15 | setting prediction matrix 16 | } 17 | \description{ 18 | Helper function to create your own setting prediction matrix, which you 19 | may want to use in \code{generate_ngm}, or \code{autoplot}. This class is the 20 | output of functions like \code{extrapolate_polymod}, and 21 | \code{predict_setting_contacts}. We recommend using this function is only for 22 | advanced users, who are creating their own setting prediction matrix. 23 | } 24 | \examples{ 25 | 26 | age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 27 | one_by_nine <- matrix(1, nrow = 9, ncol = 9) 28 | 29 | x_example <- setting_prediction_matrix( 30 | home = one_by_nine, 31 | work = one_by_nine, 32 | age_breaks = age_breaks_0_80_plus 33 | ) 34 | 35 | x_example <- setting_prediction_matrix( 36 | one_by_nine, 37 | one_by_nine, 38 | age_breaks = age_breaks_0_80_plus 39 | ) 40 | 41 | x_example 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/setting_weights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_setting_weights.R 3 | \docType{data} 4 | \name{setting_weights} 5 | \alias{setting_weights} 6 | \title{Setting weights computed for transmission probabilities.} 7 | \format{ 8 | A named vector of weights relative to home, for home, work, school, 9 | and other 10 | } 11 | \usage{ 12 | setting_weights 13 | } 14 | \description{ 15 | see ?get_setting_transmission_matrices for details of how to use these 16 | } 17 | \keyword{datasets} 18 | -------------------------------------------------------------------------------- /man/transmission_probability_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setting-transmission-matrix.R 3 | \name{transmission_probability_matrix} 4 | \alias{transmission_probability_matrix} 5 | \title{Create a setting transmission matrix} 6 | \usage{ 7 | transmission_probability_matrix(..., age_breaks) 8 | } 9 | \arguments{ 10 | \item{...}{list of matrices} 11 | 12 | \item{age_breaks}{age breaks - numeric} 13 | } 14 | \value{ 15 | transmission probability matrix 16 | } 17 | \description{ 18 | Helper function to create your own setting transmission matrix, which you 19 | may want to use in ... or \code{autoplot}. This class is the 20 | output of functions like \code{...}, and ... . We recommend using this 21 | function is only for advanced users, who are creating their own 22 | transmission probability matrix. 23 | } 24 | \examples{ 25 | 26 | age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 27 | one_05 <- matrix(0.05, nrow = 9, ncol = 9) 28 | 29 | x_example <- transmission_probability_matrix( 30 | home = one_05, 31 | work = one_05, 32 | age_breaks = age_breaks_0_80_plus 33 | ) 34 | 35 | x_example <- transmission_probability_matrix( 36 | one_05, 37 | one_05, 38 | age_breaks = age_breaks_0_80_plus 39 | ) 40 | 41 | x_example 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/vaccination_effect_example_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_example_vaccination_effect.R 3 | \docType{data} 4 | \name{vaccination_effect_example_data} 5 | \alias{vaccination_effect_example_data} 6 | \title{Example dataset with information on age based vaccination coverage, 7 | acquisition and transmission} 8 | \format{ 9 | A data frame with 17 rows and 4 variables 10 | \describe{ 11 | \item{age_band}{character. age bands: 0-4,5-11, 12-15, 16-19, 20-24, etc} 12 | \item{coverage}{example vaccination coverage, between 0-1} 13 | \item{acquisition}{example acquisition coverage, between 0-1} 14 | \item{transmission}{example transmission coverage, between 0-1} 15 | } 16 | } 17 | \usage{ 18 | vaccination_effect_example_data 19 | } 20 | \description{ 21 | data frame with information on vaccine coverage, efficacy of 22 | acquisition/susceptibility and efficacy of transmission/infectiousness 23 | for the ordered age groups from lowest to highest of the next generation 24 | matrix. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /paper/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.bcf 3 | *.tex 4 | /.quarto/ 5 | -------------------------------------------------------------------------------- /paper/paper_files/figure-html/fig-autoplot-contacts-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/paper/paper_files/figure-html/fig-autoplot-contacts-1.png -------------------------------------------------------------------------------- /paper/paper_files/figure-html/fig-show-partial-plots-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/paper/paper_files/figure-html/fig-show-partial-plots-1.png -------------------------------------------------------------------------------- /paper/paper_files/libs/bootstrap/bootstrap-icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/idem-lab/conmat/271b82c31a3e45a490384781bf82bdcebaacce85/paper/paper_files/libs/bootstrap/bootstrap-icons.woff -------------------------------------------------------------------------------- /paper/paper_files/libs/quarto-html/tippy.css: -------------------------------------------------------------------------------- 1 | .tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{width:16px;height:16px;color:#333}.tippy-arrow:before{content:"";position:absolute;border-color:transparent;border-style:solid}.tippy-content{position:relative;padding:5px 9px;z-index:1} -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test( 3 | vignettes = TRUE, 4 | error = FALSE, 5 | skip_on_cran = TRUE 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(conmat) 3 | 4 | test_check("conmat") 5 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/abbreviation.md: -------------------------------------------------------------------------------- 1 | # abs_abbreviate_states() works 2 | 3 | Code 4 | abs_abbreviate_states("New South Wales") 5 | Output 6 | [1] "NSW" 7 | 8 | # abs_unabbreviate_states() works 9 | 10 | Code 11 | abs_unabbreviate_states("NSW") 12 | Output 13 | [1] "New South Wales" 14 | 15 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/abs-age-lga.md: -------------------------------------------------------------------------------- 1 | # abs_age_lga() returns the right shape works 2 | 3 | Code 4 | abs_age_lga("Albury (C)") 5 | Output 6 | # A tibble: 18 x 4 (conmat_population) 7 | - age: lower.age.limit 8 | - population: population 9 | lga lower.age.limit year population 10 | 11 | 1 Albury (C) 0 2020 3764 12 | 2 Albury (C) 5 2020 3614 13 | 3 Albury (C) 10 2020 3369 14 | 4 Albury (C) 15 2020 3334 15 | 5 Albury (C) 20 2020 3603 16 | 6 Albury (C) 25 2020 3736 17 | 7 Albury (C) 30 2020 3443 18 | 8 Albury (C) 35 2020 3371 19 | 9 Albury (C) 40 2020 3187 20 | 10 Albury (C) 45 2020 3449 21 | 11 Albury (C) 50 2020 3297 22 | 12 Albury (C) 55 2020 3412 23 | 13 Albury (C) 60 2020 3368 24 | 14 Albury (C) 65 2020 2967 25 | 15 Albury (C) 70 2020 2602 26 | 16 Albury (C) 75 2020 1966 27 | 17 Albury (C) 80 2020 1254 28 | 18 Albury (C) 85 2020 1319 29 | 30 | # abs_age_lga() returns the right shape errors 31 | 32 | The LGA name provided does not match LGAs in Australia 33 | x The lga name 'Imaginary World' did not match (it probably needs 'Imaginary World (C)' or similar) 34 | i See `abs_lga_lookup` for a list of all LGAs 35 | 36 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/apply_vaccination.md: -------------------------------------------------------------------------------- 1 | # apply_vaccination() errors when there's an incorrect variable name 2 | 3 | i In argument: `acquisition_multiplier = 1 - acquisition_column * coverage`. 4 | Caused by error: 5 | ! object 'acquisition_column' not found 6 | 7 | # apply_vaccination() produces expected output 8 | 9 | Code 10 | ngm_VIC_vacc 11 | Message 12 | 13 | -- Vaccination Setting Matrices ------------------------------------------------ 14 | Output 15 | 16 | Message 17 | A list of matrices, each containing the adjusted number of newly 18 | infected individuals for age groups. These numbers have been adjusted based on 19 | proposed vaccination rates in age groups 20 | Output 21 | 22 | Message 23 | There are 17 age breaks, ranging 0-80+ years, with a regular 5 year interval 24 | Output 25 | 26 | Message 27 | * home: a 17x17 28 | * school: a 17x17 29 | * work: a 17x17 30 | * other: a 17x17 31 | * all: a 17x17 32 | i Access each with `x$name` 33 | i e.g., `x$home` 34 | 35 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check-age-breaks.md: -------------------------------------------------------------------------------- 1 | # check_age_breaks works 2 | 3 | Code 4 | check_age_breaks(age_one, age_one) 5 | 6 | --- 7 | 8 | Code 9 | check_age_breaks(age_one, age_two) 10 | Condition 11 | Error in `check_age_breaks()`: 12 | ! Age breaks must be the same, but they are different: 13 | `old`: 1 2 3 Inf 14 | `new`: 1 2 3 15 | i You can check the age breaks using `age_breaks()` 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check-if-data-frame.md: -------------------------------------------------------------------------------- 1 | # check_if_data_frame works 2 | 3 | Code 4 | check_if_data_frame(mtcars) 5 | 6 | --- 7 | 8 | Code 9 | check_if_data_frame(volcano) 10 | Condition 11 | Error: 12 | ! `volcano` must be a 13 | i `volcano` is 14 | 15 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check-if-data-list.md: -------------------------------------------------------------------------------- 1 | # check_if_list() returns error when argument class is not a list 2 | 3 | i Function expects `contact_data` to be of class 4 | x We see `contact_data` is of class . 5 | 6 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check-lga-name.md: -------------------------------------------------------------------------------- 1 | # check_lga_name() errors when there's an incorrect name 2 | 3 | Code 4 | check_lga_name("Imaginary World") 5 | Condition 6 | Error in `check_lga_name()`: 7 | ! The LGA name provided does not match LGAs in Australia 8 | x The lga name 'Imaginary World' did not match (it probably needs 'Imaginary World (C)' or similar) 9 | i See `abs_lga_lookup` for a list of all LGAs 10 | 11 | # check_lga_name() errors when the name is ambiguous 12 | 13 | Code 14 | check_lga_name("Sydney") 15 | Condition 16 | Error in `check_lga_name()`: 17 | ! The LGA name provided does not match LGAs in Australia 18 | x The lga name 'Sydney' did not match (it probably needs 'Sydney (C)' or similar) 19 | i See `abs_lga_lookup` for a list of all LGAs 20 | 21 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check-state-name.md: -------------------------------------------------------------------------------- 1 | # abs_age_state() returns the right shape 2 | 3 | Code 4 | abs_age_state("NSW") 5 | Output 6 | # A tibble: 18 x 4 (conmat_population) 7 | - age: lower.age.limit 8 | - population: population 9 | year state lower.age.limit population 10 | 11 | 1 2020 NSW 0 495091 12 | 2 2020 NSW 5 512778 13 | 3 2020 NSW 10 500881 14 | 4 2020 NSW 15 468550 15 | 5 2020 NSW 20 540233 16 | 6 2020 NSW 25 607891 17 | 7 2020 NSW 30 611590 18 | 8 2020 NSW 35 582824 19 | 9 2020 NSW 40 512803 20 | 10 2020 NSW 45 527098 21 | 11 2020 NSW 50 484708 22 | 12 2020 NSW 55 495116 23 | 13 2020 NSW 60 461329 24 | 14 2020 NSW 65 404034 25 | 15 2020 NSW 70 355280 26 | 16 2020 NSW 75 253241 27 | 17 2020 NSW 80 174990 28 | 18 2020 NSW 85 179095 29 | 30 | # abs_age_state() returns an error 31 | 32 | Code 33 | abs_age_state("Imaginary World") 34 | Condition 35 | Error in `check_state_name()`: 36 | ! The state name provided does not match states in Australia 37 | x The state name 'Imaginary World' did not match 38 | i See `abs_lga_lookup` for a list of all states 39 | 40 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/check_dimensions.md: -------------------------------------------------------------------------------- 1 | # check_dimensions() returns error 2 | 3 | Non-conformable arrays present. 4 | i The number of columns in `ngm` must match the number of rows in `data`. 5 | x Number of columns in `ngm` for the settings: matrix_a and matrix_b are 2 and 2 respectively. 6 | x Number of rows in `data` is 6. 7 | 8 | # apply_vaccination gives error when incompatible dimensions present 9 | 10 | Non-conformable arrays present. 11 | i The number of columns in `ngm` must match the number of rows in `data`. 12 | x Number of columns in `ngm` for the settings: home, school, work, other, and all are 4, 4, 4, 4, and 4 respectively. 13 | x Number of rows in `data` is 17. 14 | 15 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/extrapolate-polymod.md: -------------------------------------------------------------------------------- 1 | # Matrix is named appropriately 2 | 3 | Code 4 | names(synthetic_settings_5y_polymod) 5 | Output 6 | [1] "home" "work" "school" "other" "all" 7 | 8 | # Matrix dimensions are kept 9 | 10 | Code 11 | purrr::map(synthetic_settings_5y_polymod, dim) 12 | Output 13 | $home 14 | [1] 16 16 15 | 16 | $work 17 | [1] 16 16 18 | 19 | $school 20 | [1] 16 16 21 | 22 | $other 23 | [1] 16 16 24 | 25 | $all 26 | [1] 16 16 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/lga_household_works.md: -------------------------------------------------------------------------------- 1 | # get_abs_per_capita_household_size errors for some lgas 2 | 3 | i In index: 130. 4 | Caused by error in `check_lga_name()`: 5 | ! The LGA name provided does not match LGAs in Australia 6 | x The lga name 'Migratory - Offshore - Shipping (NSW)' did not match (it probably needs 'Migratory - Offshore - Shipping (NSW) (C)' or similar) 7 | i See `abs_lga_lookup` for a list of all LGAs 8 | 9 | # check_lga_name errors for some lgas 10 | 11 | i In index: 130. 12 | Caused by error in `check_lga_name()`: 13 | ! The LGA name provided does not match LGAs in Australia 14 | x The lga name 'Migratory - Offshore - Shipping (NSW)' did not match (it probably needs 'Migratory - Offshore - Shipping (NSW) (C)' or similar) 15 | i See `abs_lga_lookup` for a list of all LGAs 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/matrix-to-predictions.md: -------------------------------------------------------------------------------- 1 | # matrix_to_predictions works 2 | 3 | Code 4 | matrix_to_predictions(fairfield_school_mat) 5 | Output 6 | # A tibble: 16 x 3 7 | age_group_to age_group_from contacts 8 | 9 | 1 [0,5) [0,5) 1.29 10 | 2 [0,5) [5,10) 0.340 11 | 3 [0,5) [10,15) 0.0350 12 | 4 [0,5) [15,Inf) 0.0463 13 | 5 [5,10) [0,5) 0.358 14 | 6 [5,10) [5,10) 4.28 15 | 7 [5,10) [10,15) 0.389 16 | 8 [5,10) [15,Inf) 0.0913 17 | 9 [10,15) [0,5) 0.0390 18 | 10 [10,15) [5,10) 0.406 19 | 11 [10,15) [10,15) 6.89 20 | 12 [10,15) [15,Inf) 0.142 21 | 13 [15,Inf) [0,5) 0.651 22 | 14 [15,Inf) [5,10) 1.21 23 | 15 [15,Inf) [10,15) 1.79 24 | 16 [15,Inf) [15,Inf) 1.03 25 | 26 | # predictions_to_matrix works 27 | 28 | Code 29 | predictions_to_matrix(fairfield_school_contacts) 30 | Output 31 | [0,5) [5,10) [10,15) [15,Inf) 32 | [0,5) 1.2943919 0.3399276 0.03498491 0.04632389 33 | [5,10) 0.3575674 4.2793707 0.38857887 0.09134242 34 | [10,15) 0.0389501 0.4063799 6.89347560 0.14196259 35 | [15,Inf) 0.6506417 1.2132657 1.78676032 1.03167455 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/predict-contacts.md: -------------------------------------------------------------------------------- 1 | # predict_contacts() works 2 | 3 | Code 4 | names(synthetic_pred) 5 | Output 6 | [1] "age_group_from" "age_group_to" "contacts" 7 | 8 | --- 9 | 10 | Code 11 | dim(synthetic_pred) 12 | Output 13 | [1] 9 3 14 | 15 | --- 16 | 17 | Code 18 | synthetic_pred$age_group_from 19 | Output 20 | [1] [0,5) [0,5) [0,5) [5,10) [5,10) [5,10) [10,Inf) [10,Inf) 21 | [9] [10,Inf) 22 | Levels: [0,5) [5,10) [10,Inf) 23 | 24 | --- 25 | 26 | Code 27 | synthetic_pred$age_group_to 28 | Output 29 | [1] [0,5) [5,10) [10,Inf) [0,5) [5,10) [10,Inf) [0,5) [5,10) 30 | [9] [10,Inf) 31 | Levels: [0,5) [5,10) [10,Inf) 32 | 33 | # predictions_to_matrix() works 34 | 35 | Code 36 | dim(synthetic_all_5y) 37 | Output 38 | [1] 3 3 39 | 40 | --- 41 | 42 | Code 43 | rownames(synthetic_all_5y) 44 | Output 45 | [1] "[0,5)" "[5,10)" "[10,Inf)" 46 | 47 | --- 48 | 49 | Code 50 | colnames(synthetic_all_5y) 51 | Output 52 | [1] "[0,5)" "[5,10)" "[10,Inf)" 53 | 54 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/setting-transmission-matrix.md: -------------------------------------------------------------------------------- 1 | # transmission_probability_matrix works 2 | 3 | Code 4 | transmission_probability_matrix(home = one_05, work = one_05, age_breaks = age_breaks_0_80_plus) 5 | Message 6 | 7 | -- Transmission Probability Matrices ------------------------------------------- 8 | Output 9 | 10 | Message 11 | A list of matrices, each containing the relative probability of 12 | individuals in a given age group infecting an individual in another age group, 13 | for that setting. 14 | Output 15 | 16 | Message 17 | There are 9 age breaks, ranging 0-80+ years, with a regular 10 year interval 18 | Output 19 | 20 | Message 21 | * home: a 9x9 22 | * work: a 9x9 23 | i Access each with `x$name` 24 | i e.g., `x$home` 25 | 26 | --- 27 | 28 | Code 29 | transmission_probability_matrix(one_05, one_05, age_breaks = age_breaks_0_80_plus) 30 | Message 31 | 32 | -- Transmission Probability Matrices ------------------------------------------- 33 | Output 34 | 35 | Message 36 | A list of matrices, each containing the relative probability of 37 | individuals in a given age group infecting an individual in another age group, 38 | for that setting. 39 | Output 40 | 41 | Message 42 | There are 9 age breaks, ranging 0-80+ years, with a regular 10 year interval 43 | Output 44 | 45 | Message 46 | * one: a 9x9 47 | * two: a 9x9 48 | i Access each with `x$name` 49 | i e.g., `x$one` 50 | 51 | -------------------------------------------------------------------------------- /tests/testthat/test-abbreviation.R: -------------------------------------------------------------------------------- 1 | test_that("abs_abbreviate_states() works", { 2 | expect_snapshot(abs_abbreviate_states("New South Wales")) 3 | }) 4 | 5 | test_that("abs_unabbreviate_states() works", { 6 | expect_snapshot(abs_unabbreviate_states("NSW")) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-abs-age-education.R: -------------------------------------------------------------------------------- 1 | test_that("abs_age_education_state works", { 2 | expect_snapshot( 3 | abs_age_education_state(state = "VIC") 4 | ) 5 | expect_snapshot( 6 | abs_age_education_state(state = "WA", age = 1:5) 7 | ) 8 | expect_snapshot( 9 | abs_age_education_state(state = c("QLD", "TAS"), age = 5) 10 | ) 11 | }) 12 | 13 | test_that("abs_age_education_state works", { 14 | expect_snapshot( 15 | abs_age_education_lga(lga = "Albury (C)") 16 | ) 17 | expect_snapshot( 18 | abs_age_education_lga(lga = "Albury (C)", age = 1:5) 19 | ) 20 | expect_snapshot( 21 | abs_age_education_lga(lga = c("Albury (C)", "Barcoo (S)"), age = 10) 22 | ) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-abs-age-lga.R: -------------------------------------------------------------------------------- 1 | test_that("abs_age_lga() returns the right shape works", { 2 | expect_snapshot(abs_age_lga("Albury (C)")) 3 | }) 4 | 5 | test_that("abs_age_lga() returns the right shape errors", { 6 | expect_snapshot_error( 7 | abs_age_lga("Imaginary World") 8 | ) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-abs-age-work.R: -------------------------------------------------------------------------------- 1 | test_that("abs_age_work_state works", { 2 | expect_snapshot( 3 | abs_age_work_state(state = "NSW") 4 | ) 5 | expect_snapshot( 6 | abs_age_work_state(state = c("QLD", "TAS"), age = 5) 7 | ) 8 | }) 9 | 10 | test_that("abs_age_work_lga works", { 11 | expect_snapshot( 12 | abs_age_work_lga(lga = "Albany (C)", age = 1:5) 13 | ) 14 | expect_snapshot( 15 | abs_age_work_lga(lga = c("Albury (C)", "Barcoo (S)"), age = 39) 16 | ) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-age-population.R: -------------------------------------------------------------------------------- 1 | world_data <- socialmixr::wpp_age() 2 | 3 | test_that("age_population works", { 4 | expect_snapshot( 5 | # Tidy data for multiple locations across different years 6 | age_population( 7 | data = world_data, 8 | location_col = country, 9 | location = c("Asia", "Afghanistan"), 10 | age_col = lower.age.limit, 11 | year_col = year, 12 | year = c(2010:2020) 13 | ) 14 | ) 15 | 16 | expect_snapshot( 17 | # Tidy data for a given location irrespective of year 18 | age_population( 19 | data = world_data, 20 | location_col = country, 21 | location = "Afghanistan", 22 | age_col = lower.age.limit 23 | ) 24 | ) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-apply_vaccination.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | set.seed(2022) 3 | 4 | ngm_VIC <- generate_ngm_oz( 5 | state_name = "VIC", 6 | age_breaks = c(seq(0, 80, by = 5), Inf), 7 | R_target = 1.5 8 | ) 9 | 10 | ngm_VIC_vacc <- apply_vaccination( 11 | ngm = ngm_VIC, 12 | data = vaccination_effect_example_data, 13 | coverage_col = coverage, 14 | acquisition_col = acquisition, 15 | transmission_col = transmission 16 | ) 17 | 18 | 19 | test_that("apply_vaccination() returns expected matrices", { 20 | expect_true( 21 | purrr::map2_lgl( 22 | .x = ngm_VIC_vacc, 23 | .y = ngm_VIC, 24 | .f = function(.x, .y) { 25 | all(.x <= .y) 26 | } 27 | ) %>% 28 | all() 29 | ) 30 | }) 31 | 32 | test_that("apply_vaccination() errors when there's an incorrect variable name", { 33 | expect_snapshot_error( 34 | apply_vaccination( 35 | ngm = ngm_VIC, 36 | data = vaccination_effect_example_data, 37 | coverage_col = coverage, 38 | acquisition_col = acquisition_column, 39 | transmission_col = transmission 40 | ) 41 | ) 42 | }) 43 | 44 | test_that("apply_vaccination() produces expected output", { 45 | expect_snapshot( 46 | ngm_VIC_vacc 47 | ) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-check-age-breaks.R: -------------------------------------------------------------------------------- 1 | age_one <- c(1, 2, 3, Inf) 2 | age_two <- c(1, 2, 3) 3 | 4 | test_that("check_age_breaks works", { 5 | expect_snapshot( 6 | check_age_breaks(age_one, age_one) 7 | ) 8 | 9 | expect_snapshot( 10 | error = TRUE, 11 | check_age_breaks(age_one, age_two) 12 | ) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-check-if-data-frame.R: -------------------------------------------------------------------------------- 1 | test_that("check_if_data_frame works", { 2 | expect_snapshot( 3 | check_if_data_frame(mtcars) 4 | ) 5 | expect_snapshot( 6 | error = TRUE, 7 | check_if_data_frame(volcano) 8 | ) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-check-if-data-list.R: -------------------------------------------------------------------------------- 1 | test_that("check_if_list() returns error when argument class is not a list", { 2 | set.seed(2021 - 10 - 4) 3 | polymod_setting_data <- get_polymod_setting_data() 4 | expect_snapshot_error(check_if_list(polymod_setting_data$home)) 5 | }) 6 | 7 | test_that("check_if_list() returns nothing when argument class is a list", { 8 | set.seed(2021 - 10 - 4) 9 | polymod_setting_data <- get_polymod_setting_data() 10 | expect_silent(check_if_list(polymod_setting_data)) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-check-lga-name.R: -------------------------------------------------------------------------------- 1 | test_that("check_lga_name() returns the right shape", { 2 | expect_silent(check_lga_name("Albury (C)")) 3 | }) 4 | 5 | test_that("check_lga_name() errors when there's an incorrect name", { 6 | expect_snapshot( 7 | error = TRUE, 8 | check_lga_name("Imaginary World") 9 | ) 10 | }) 11 | 12 | test_that("check_lga_name() errors when the name is ambiguous", { 13 | expect_snapshot( 14 | error = TRUE, 15 | check_lga_name("Sydney") 16 | ) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-check-state-name.R: -------------------------------------------------------------------------------- 1 | test_that("abs_age_state() returns the right shape", { 2 | expect_snapshot(abs_age_state("NSW")) 3 | }) 4 | 5 | test_that("abs_age_state() returns an error", { 6 | expect_snapshot( 7 | error = TRUE, 8 | abs_age_state("Imaginary World") 9 | ) 10 | }) 11 | -------------------------------------------------------------------------------- /tests/testthat/test-check_dimensions.R: -------------------------------------------------------------------------------- 1 | test_that("check_dimensions() returns nothing when compatible dimensions", { 2 | demo_matrix <- list( 3 | matrix(1:6, nrow = 3, ncol = 2), 4 | matrix(1:6, nrow = 3, ncol = 2) 5 | ) 6 | 7 | names(demo_matrix) <- c("matrix_a", "matrix_b") 8 | 9 | demo_data <- tibble::tibble(x = 1:2, y = 2 * x) 10 | 11 | expect_silent(check_dimensions( 12 | demo_matrix, 13 | demo_data 14 | )) 15 | }) 16 | 17 | 18 | test_that("check_dimensions() returns error", { 19 | demo_matrix <- list( 20 | matrix(1:6, nrow = 3, ncol = 2), 21 | matrix(1:6, nrow = 3, ncol = 2) 22 | ) 23 | 24 | names(demo_matrix) <- c("matrix_a", "matrix_b") 25 | 26 | demo_data <- tibble::tibble(x = 1:6, y = 2 * x) 27 | expect_snapshot_error(check_dimensions( 28 | demo_matrix, 29 | demo_data 30 | )) 31 | }) 32 | 33 | test_that("apply_vaccination gives error when incompatible dimensions present", { 34 | demo_matrix <- matrix( 35 | 1:16, 36 | nrow = 4, 37 | ncol = 4, 38 | dimnames = list( 39 | c("[0,5)", "[5,10)", "[10,15)", "[15,Inf)"), 40 | c("[0,5)", "[5,10)", "[10,15)", "[15,Inf)") 41 | ) 42 | ) 43 | 44 | demo_matrix <- replicate(5, demo_matrix, simplify = FALSE) 45 | 46 | names(demo_matrix) <- c("home", "school", "work", "other", "all") 47 | 48 | expect_snapshot_error( 49 | apply_vaccination( 50 | ngm = demo_matrix, 51 | data = vaccination_effect_example_data, 52 | coverage_col = coverage, 53 | acquisition_col = acquisition, 54 | transmission_col = transmission 55 | ) 56 | ) 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/test-conmat-population.R: -------------------------------------------------------------------------------- 1 | # need to remove the conmat_population class 2 | fairfield <- as.data.frame(abs_age_lga("Fairfield (C)")) 3 | 4 | test_that("conmat_population works", { 5 | expect_snapshot( 6 | conmat_population( 7 | data = fairfield, 8 | age = lower.age.limit, 9 | population = population 10 | ) 11 | ) 12 | }) 13 | 14 | test_that("as_conmat_population works", { 15 | expect_snapshot( 16 | as_conmat_population( 17 | data = fairfield, 18 | age = lower.age.limit, 19 | population = population 20 | ) 21 | ) 22 | }) 23 | 24 | # TODO 25 | # Need to add some defensive programming stuff 26 | # Need to detect when you try and input a conmat population again 27 | -------------------------------------------------------------------------------- /tests/testthat/test-estimate-setting-contacts.R: -------------------------------------------------------------------------------- 1 | polymod_contacts <- get_polymod_setting_data() 2 | 3 | filter_age <- function(df, age) { 4 | df %>% 5 | dplyr::filter(age_from <= age, age_to <= age) 6 | } 7 | 8 | filter_setting_age <- function(list_df, age) { 9 | lapply( 10 | list_df, 11 | filter_age, 12 | age 13 | ) %>% 14 | new_setting_data() 15 | } 16 | 17 | contact_data_cut <- filter_setting_age(polymod_contacts, 10) 18 | 19 | test_that("estimate_setting_contacts works", { 20 | skip_on_ci() 21 | skip_on_cran() 22 | expect_snapshot( 23 | estimate_setting_contacts( 24 | contact_data_list = contact_data_cut, 25 | survey_population = get_polymod_population(), 26 | prediction_population = get_polymod_population(), 27 | age_breaks = c(seq(0, 10, by = 5), Inf), 28 | per_capita_household_size = NULL 29 | ) 30 | ) 31 | }) 32 | 33 | test_that("estimate_setting_contacts works with different demographic data", { 34 | skip_on_ci() 35 | skip_on_cran() 36 | expect_snapshot( 37 | estimate_setting_contacts( 38 | contact_data_list = contact_data_cut, 39 | survey_population = get_polymod_population(), 40 | prediction_population = get_polymod_population(), 41 | age_breaks = c(seq(0, 10, by = 5), Inf), 42 | school_demographics = conmat_original_school_demographics, 43 | work_demographics = conmat_original_work_demographics 44 | ) 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-extrapolate-polymod.R: -------------------------------------------------------------------------------- 1 | polymod_population <- get_polymod_population() 2 | 3 | synthetic_settings_5y_polymod <- extrapolate_polymod( 4 | population = polymod_population 5 | ) 6 | 7 | test_that("Matrix is named appropriately", { 8 | expect_snapshot(names(synthetic_settings_5y_polymod)) 9 | }) 10 | 11 | test_that("Matrix dimensions are kept", { 12 | expect_snapshot(purrr::map(synthetic_settings_5y_polymod, dim)) 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-fit-single-contact-model.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | contact_data <- get_polymod_contact_data("all") %>% 3 | filter( 4 | age_from <= 20, 5 | age_to <= 20 6 | ) 7 | 8 | population <- get_polymod_population() %>% 9 | filter(lower.age.limit <= 20) 10 | 11 | m_all <- fit_single_contact_model( 12 | contact_data = contact_data, 13 | population = population 14 | ) 15 | 16 | m_all_not_sym <- fit_single_contact_model( 17 | contact_data = contact_data, 18 | population = population, 19 | symmetrical = FALSE 20 | ) 21 | 22 | test_that("Model returns bam model", { 23 | expect_s3_class(m_all, "bam") 24 | expect_s3_class(m_all_not_sym, "bam") 25 | }) 26 | 27 | test_that("Model coefficients are the same", { 28 | expect_snapshot(names(m_all$coefficients)) 29 | expect_snapshot(names(m_all_not_sym$coefficients)) 30 | }) 31 | 32 | test_that("Model fits", { 33 | expect_no_warning( 34 | fit_single_contact_model( 35 | contact_data = contact_data, 36 | population = population, 37 | symmetrical = FALSE 38 | ) 39 | ) 40 | expect_no_warning( 41 | fit_single_contact_model( 42 | contact_data = contact_data, 43 | population = population 44 | ) 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-generate-ngm.R: -------------------------------------------------------------------------------- 1 | perth <- abs_age_lga("Perth (C)") 2 | perth_hh <- get_abs_per_capita_household_size(lga = "Perth (C)") 3 | age_breaks_0_75 <- c(seq(0, 75, by = 5), Inf) 4 | age_breaks_0_85 <- c(seq(0, 85, by = 5), Inf) 5 | 6 | perth_contact <- extrapolate_polymod( 7 | perth, 8 | per_capita_household_size = perth_hh 9 | ) 10 | 11 | perth_ngm_lga <- generate_ngm( 12 | perth, 13 | age_breaks = age_breaks_0_75, 14 | per_capita_household_size = perth_hh, 15 | R_target = 1.5 16 | ) 17 | 18 | perth_ngm <- generate_ngm( 19 | perth_contact, 20 | age_breaks = age_breaks_0_75, 21 | R_target = 1.5 22 | ) 23 | 24 | perth_ngm_oz <- generate_ngm_oz( 25 | lga_name = "Perth (C)", 26 | age_breaks = age_breaks_0_75, 27 | R_target = 1.5 28 | ) 29 | 30 | test_that("the three variants of the generate_ngm produce the same result", { 31 | expect_true(all.equal(perth_ngm_lga, perth_ngm)) 32 | expect_true(all.equal(perth_ngm_lga, perth_ngm_oz)) 33 | expect_true(all.equal(perth_ngm_oz, perth_ngm)) 34 | }) 35 | 36 | test_that("NGMs from each generate_ngm type return the same object", { 37 | expect_snapshot( 38 | perth_ngm_lga 39 | ) 40 | expect_snapshot( 41 | perth_ngm 42 | ) 43 | expect_snapshot( 44 | perth_ngm_oz 45 | ) 46 | }) 47 | 48 | test_that("generate_ngm fails when given wrong age breaks", { 49 | expect_snapshot( 50 | error = TRUE, 51 | generate_ngm( 52 | perth_contact, 53 | age_breaks = age_breaks_0_85, 54 | R_target = 1.5 55 | ) 56 | ) 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/test-get-abs-household-size-distribution.R: -------------------------------------------------------------------------------- 1 | test_that("get_abs_household_size_distribution works", { 2 | expect_snapshot( 3 | get_abs_household_size_distribution(lga = "Fairfield (C)") 4 | ) 5 | expect_snapshot( 6 | get_abs_household_size_distribution(state = "NSW") 7 | ) 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-get-polymod-population.R: -------------------------------------------------------------------------------- 1 | test_that("get_polymod_contact_data() works", { 2 | skip_on_ci() 3 | set.seed(2021 - 10 - 4) 4 | expect_snapshot(get_polymod_contact_data()) 5 | }) 6 | 7 | test_that("get_polymod_population() works", { 8 | skip_on_ci() 9 | set.seed(2021 - 10 - 4) 10 | expect_snapshot(get_polymod_population()) 11 | }) 12 | 13 | test_that("get_polymod_setting_data() and derivatives work", { 14 | skip_on_ci() 15 | set.seed(2021 - 10 - 4) 16 | polymod_setting_data <- get_polymod_setting_data() 17 | expect_snapshot(polymod_setting_data) 18 | expect_snapshot(polymod_setting_data$home) 19 | expect_snapshot(polymod_setting_data$work) 20 | expect_snapshot(polymod_setting_data$school) 21 | expect_snapshot(polymod_setting_data$other) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-lga_household_works.R: -------------------------------------------------------------------------------- 1 | library(purrr) 2 | library(conmat) 3 | 4 | test_that("get_abs_per_capita_household_size errors for some lgas", { 5 | skip_on_ci() 6 | expect_snapshot_error(map( 7 | .x = unique(abs_household_lga$lga), 8 | .f = ~ get_abs_per_capita_household_size(lga = .x) 9 | )) 10 | }) 11 | 12 | test_that("check_lga_name errors for some lgas", { 13 | skip_on_ci() 14 | expect_snapshot_error(map( 15 | .x = unique(abs_household_lga$lga), 16 | .f = ~ check_lga_name(lga = .x) 17 | )) 18 | }) 19 | 20 | # safe_get_abs_per_capita_household_size <- safely(get_abs_per_capita_household_size) 21 | # 22 | # household_per_capita_runs <- map( 23 | # .x = unique(abs_household_lga$lga), 24 | # .f = ~ safe_get_abs_per_capita_household_size(lga = .x) 25 | # ) 26 | 27 | # t_household_per_capita_runs <- transpose(household_per_capita_runs) 28 | # compact(t_household_per_capita_runs$error) 29 | 30 | # thinking about which ones error? 31 | # safe_check_lga_name <- safely(check_lga_name) 32 | # 33 | # check_lga_name_runs <- map( 34 | # .x = unique(abs_household_lga$lga), 35 | # .f = ~ safe_check_lga_name(lga = .x) 36 | # ) 37 | # 38 | # transpose_errors <- transpose(check_lga_name_runs) 39 | # 40 | # which_errors <- which(map_lgl( 41 | # transpose_errors$error, 42 | # \(x) !is.null(x) 43 | # ) 44 | # ) 45 | -------------------------------------------------------------------------------- /tests/testthat/test-matrix-to-predictions.R: -------------------------------------------------------------------------------- 1 | fairfield <- abs_age_lga("Fairfield (C)") 2 | 3 | fairfield_school_contacts <- predict_contacts( 4 | model = polymod_setting_models$school, 5 | population = fairfield, 6 | age_breaks = c(0, 5, 10, 15, Inf) 7 | ) 8 | 9 | fairfield_school_mat <- predictions_to_matrix(fairfield_school_contacts) 10 | 11 | test_that("matrix_to_predictions works", { 12 | expect_snapshot( 13 | matrix_to_predictions(fairfield_school_mat) 14 | ) 15 | }) 16 | 17 | test_that("predictions_to_matrix works", { 18 | expect_snapshot( 19 | predictions_to_matrix(fairfield_school_contacts) 20 | ) 21 | }) 22 | -------------------------------------------------------------------------------- /tests/testthat/test-per_capita_household_size.R: -------------------------------------------------------------------------------- 1 | test_that("refactored code works", { 2 | expect_identical( 3 | get_abs_per_capita_household_size_state("NSW"), 4 | get_abs_per_capita_household_size("NSW") 5 | ) 6 | }) 7 | 8 | test_that("refactored code works with lga", { 9 | expect_identical( 10 | get_abs_per_capita_household_size_lga(unique(abs_lga_lookup$lga)[1]), 11 | get_abs_per_capita_household_size(lga = unique(abs_lga_lookup$lga)[1]) 12 | ) 13 | }) 14 | 15 | 16 | test_that("errors when given incorrect state", { 17 | expect_error(get_abs_per_capita_household_size_state("NSA")) 18 | }) 19 | 20 | 21 | test_that("errors when given incorrect lga", { 22 | expect_error(get_abs_per_capita_household_size_lga("Fairfield")) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-predict-contacts.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | contact_data <- get_polymod_contact_data("all") %>% 3 | filter( 4 | age_from <= 20, 5 | age_to <= 20 6 | ) 7 | 8 | population <- get_polymod_population() %>% 9 | filter(lower.age.limit <= 20) 10 | 11 | m_all <- fit_single_contact_model( 12 | contact_data = contact_data, 13 | population = population 14 | ) 15 | 16 | age_breaks_5y <- c(seq(0, 10, by = 5), Inf) 17 | 18 | synthetic_pred <- predict_contacts( 19 | model = m_all, 20 | population = population, 21 | age_breaks = age_breaks_5y 22 | ) 23 | 24 | test_that("predict_contacts() works", { 25 | expect_s3_class(synthetic_pred, "tbl_df") 26 | expect_snapshot(names(synthetic_pred)) 27 | expect_snapshot(dim(synthetic_pred)) 28 | expect_snapshot(synthetic_pred$age_group_from) 29 | expect_snapshot(synthetic_pred$age_group_to) 30 | }) 31 | 32 | synthetic_all_5y <- synthetic_pred %>% 33 | predictions_to_matrix() 34 | 35 | test_that("predictions_to_matrix() works", { 36 | expect_snapshot(dim(synthetic_all_5y)) 37 | expect_snapshot(rownames(synthetic_all_5y)) 38 | expect_snapshot(colnames(synthetic_all_5y)) 39 | }) 40 | -------------------------------------------------------------------------------- /tests/testthat/test-print-conmat-matrix-method.R: -------------------------------------------------------------------------------- 1 | perth_city <- abs_age_lga("Perth (C)") 2 | set.seed(2022 - 12 - 14) 3 | synthetic_settings_5y_perth <- extrapolate_polymod( 4 | population = perth_city 5 | ) 6 | 7 | test_that("Print method for setting prediction matrices works", { 8 | expect_snapshot(synthetic_settings_5y_perth) 9 | expect_snapshot(synthetic_settings_5y_perth$home) 10 | }) 11 | -------------------------------------------------------------------------------- /tests/testthat/test-setting-prediction-matrix.R: -------------------------------------------------------------------------------- 1 | age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 2 | one_by_nine <- matrix(1, nrow = 9, ncol = 9) 3 | 4 | test_that("setting_prediction_matrix works", { 5 | expect_snapshot( 6 | setting_prediction_matrix( 7 | home = one_by_nine, 8 | work = one_by_nine, 9 | age_breaks = age_breaks_0_80_plus 10 | ) 11 | ) 12 | }) 13 | 14 | mat_list <- list( 15 | home = one_by_nine, 16 | work = one_by_nine 17 | ) 18 | 19 | test_that("as_setting_prediction_matrix works", { 20 | expect_snapshot( 21 | as_setting_prediction_matrix( 22 | mat_list, 23 | age_breaks = age_breaks_0_80_plus 24 | ) 25 | ) 26 | }) 27 | 28 | setting_mat <- setting_prediction_matrix( 29 | home = one_by_nine, 30 | work = one_by_nine, 31 | age_breaks = age_breaks_0_80_plus 32 | ) 33 | 34 | test_that("as_setting_prediction_matrix warns when setting pred matrix given", { 35 | expect_snapshot( 36 | as_setting_prediction_matrix( 37 | setting_mat, 38 | age_breaks = age_breaks_0_80_plus 39 | ) 40 | ) 41 | }) 42 | 43 | test_that("as_setting_prediction_matrix fails when wrong object given", { 44 | expect_snapshot( 45 | error = TRUE, 46 | as_setting_prediction_matrix( 47 | iris, 48 | age_breaks = age_breaks_0_80_plus 49 | ) 50 | ) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-setting-transmission-matrix.R: -------------------------------------------------------------------------------- 1 | age_breaks_0_80_plus <- c(seq(0, 80, by = 10), Inf) 2 | one_05 <- matrix(0.05, nrow = 9, ncol = 9) 3 | 4 | test_that("transmission_probability_matrix works", { 5 | expect_snapshot( 6 | transmission_probability_matrix( 7 | home = one_05, 8 | work = one_05, 9 | age_breaks = age_breaks_0_80_plus 10 | ) 11 | ) 12 | 13 | expect_snapshot( 14 | transmission_probability_matrix( 15 | one_05, 16 | one_05, 17 | age_breaks = age_breaks_0_80_plus 18 | ) 19 | ) 20 | }) 21 | -------------------------------------------------------------------------------- /touchstone/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !script.R 3 | !config.json 4 | !.gitignore 5 | !header.R 6 | !footer.R 7 | -------------------------------------------------------------------------------- /touchstone/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "os": "ubuntu-20.04", 3 | "r": "4.1.1", 4 | "rspm": "https://packagemanager.rstudio.com/all/__linux__/focal/2022-01-07+MTo3NDQwNTcyLDI6NDUyNjIxNTs0QzU3NUZBRQ", 5 | // "benchmarking_repo": "lorenzwalthert/here", 6 | // "benchmarking_ref": "ca9c8e69c727def88d8ba1c8b85b0e0bcea87b3f", 7 | "benchmarking_path": "touchstone/sources/here", 8 | } 9 | -------------------------------------------------------------------------------- /touchstone/footer.R: -------------------------------------------------------------------------------- 1 | # You can modify the PR comment footer here. You can use github markdown e.g. 2 | # emojis like :tada:. 3 | # This file will be parsed and evaluate within the context of 4 | # `benchmark_analyze` and should return the comment text as the last value. 5 | # See `?touchstone::pr_comment` 6 | link <- "https://lorenzwalthert.github.io/touchstone/articles/inference.html" 7 | glue::glue( 8 | "\nFurther explanation regarding interpretation and", 9 | " methodology can be found in the [documentation]({link})." 10 | ) 11 | -------------------------------------------------------------------------------- /touchstone/header.R: -------------------------------------------------------------------------------- 1 | # You can modify the PR comment header here. You can use github markdown e.g. 2 | # emojis like :tada:. 3 | # This file will be parsed and evaluate within the context of 4 | # `benchmark_analyze` and should return the comment text as the last value. 5 | # Available variables for glue substitution: 6 | # * ci: confidence interval 7 | # * branches: BASE and HEAD branches benchmarked against each other. 8 | # See `?touchstone::pr_comment` 9 | glue::glue( 10 | "This is how benchmark results would change (along with a", 11 | " {100 * ci}% confidence interval in relative change) if ", 12 | "{system2('git', c('rev-parse', 'HEAD'), stdout = TRUE)} is merged into {branches[1]}:\n" 13 | ) 14 | -------------------------------------------------------------------------------- /touchstone/script.R: -------------------------------------------------------------------------------- 1 | # see `help(run_script, package = 'touchstone')` on how to run this 2 | # interactively 3 | 4 | # TODO OPTIONAL Add directories you want to be available in this file or during the 5 | # benchmarks. 6 | # touchstone::pin_assets("some/dir") 7 | 8 | # installs branches to benchmark 9 | touchstone::branch_install() 10 | 11 | # benchmark a function call from your package (two calls per branch) 12 | touchstone::benchmark_run( 13 | expr_before_benchmark = source("touchstone/touchstone-setup.R"), 14 | fit_single_contact_model = conmat::fit_single_contact_model( 15 | contact_data = contact_settings$home, 16 | population = polymod_population 17 | ), 18 | n = 2 19 | ) 20 | 21 | touchstone::benchmark_run( 22 | expr_before_benchmark = source("touchstone/touchstone-setup.R"), 23 | fit_single_contact_model = conmat::predict_contacts( 24 | model = polymod_setting_models$home, 25 | population = fairfield 26 | ), 27 | n = 2 28 | ) 29 | 30 | # TODO OPTIONAL benchmark any R expression (six calls per branch) 31 | # touchstone::benchmark_run( 32 | # more = { 33 | # if (TRUE) { 34 | # y <- yourpkg::f2(x = 3) 35 | # } 36 | # }, #<- TODO put the call you want to benchmark here 37 | # n = 6 38 | # ) 39 | 40 | # create artifacts used downstream in the GitHub Action 41 | touchstone::benchmark_analyze() 42 | -------------------------------------------------------------------------------- /touchstone/touchstone-setup.R: -------------------------------------------------------------------------------- 1 | library(conmat) 2 | contact_settings <- get_polymod_setting_data() 3 | polymod_population <- get_polymod_population() 4 | fairfield <- abs_age_lga("Fairfield (C)") 5 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | --------------------------------------------------------------------------------