Skip to content

Commit

Permalink
Dev fix pr 1 (#80)
Browse files Browse the repository at this point in the history
* Documentation of the visualisation and modelling modules

* automatic documentation of the visualisation and modeling modules

* minor changes to the documentation. Typos and minor bugs corrected.

* feat: define a preliminar version of the minimal dataset needed to use the library, now stored in data/data.RDS (data/data_bu.RDS is backup of the old dataset). The prepare_data() function in seroprevalence_data process the dataset creating 5 columns needed for the analysis (age_mean_f, sample_size, prev_obs, prev_obs_lower and prev_obs_upper). This function is tested in test/test_minimal_data and implemented in test_individual_models.

* fix: remove unused functions from all modules in preparation for a compiltation test. Remove the corresponding documentation files. Remove the folder R/stantmodels (it's redundant with inst/extdata/stanmodels). Update dependencies in DESCRIPTION (epitrix and cowplot removed).

* fix: prepare data_test for compilation of the package

* Dev compilation test nicolas (#10)

* minor changes in how the summary is shown

* change summary message

* minor change in extract_summary_model

* create template of vignette

* delete temporary files

* testing vignette

* vignette's test

* adding workflows sca and r-cmd-check

* adding workflows sca and r-cmd-check (#11)

* Static code review with lintr in package modules

* changing descriotion

* adding info into run-model function

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* returning logo

* adding a script for model comparison

* adding a script for model comparison

* changing README.Rmd file

* changing README.Rmd file

* changing README.Rmd file

* changing README.Rmd file

* adding plots to the readme file

* adding plots to the readme file

* adding function for plotting raw seroprevalence data

* adding the packages name standart

* adding data reference for dplyr

* update function documentation

* Static code analysis for package modules

* Static code analysis for the modeling module

* Clean test/test_comparison.R. Add a warning for first compilation of the models. Minor sintaxis changes. Change slightly the name of the visualization module.

* fix: Calculate the  binomial confidence interval from the raw seroprevalence data in function plot_seroprev. The function is tested in test_plot_functions.R. Add compilation line to test_individual models.R.

* Compilation test in test_plot_functions.R

* minor changes before merging with dev

* feat: Add function prepare_bin_data to seroprevalence_data module. This function prepares the data to plot the binomial confidence intervals and allows to remove redundant code in the visualization and modelling modules.

* minor changes before merging with dev

* fix: corrects the bin size in plot_seroprev(). Minor syntax changes.

* doc: Add the corresponding documentation for plot_seroprev() to README.Rmd and README.md including the example image file man/figures/plot_seroprev_example.png

* Dev docu mg (#16)

* Added examples in core functions documentation

* Example of the functions in the documentation

* updating links of R-CMD check and Codecov test

* Dev doc nicolas (#18)

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* updating package version and contributors

* Dev doc nicolas (#20)

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* doc: minor changes to the modelling module. Quotation marks added for string variables in the documentation and some minor errors fixed.

* Dev docker tests (#22)

* 1st version of Dockerfile

* Addedd auto dep install for docker container

* Refactor docker folder

* Changed process to obtain path of stan and RDS files to make it compatible with testhat

* First version of tests

* Factored testing functions

* config.yml now only stores the base path of stan models

* Added automated test tasks for vscode

* Added more tests

* misc changes to vscode tasks

* Misc improvements to containers

* small fixes to container

* misc docker refactor

* moved docker scripts to an R file (tested only on Linux)

* Temporary change to test github actions on this branch

* added testthat to deps

* Added devtools to deps

* removed erroneous code in unit test

* moving config.yml to inst

* same

* temp changes to github actions files for testing

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* Added R CMD Check to Docker

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* Added more files to rbuildignore

* more testing of github actions

* misc fixes

* testing windows

* adding BH dep

* Added linking deps for rstan

* added suggest deps for rstan

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* Add LinkingTo field (#19)

* Add LinkingTo field

* Add roxygen comments from rstantools::use_rstan()

* temporarily removed some deps

* temp remove of this branch from yaml

* added vscode configs

* Fixes linking errors in R CMD CHeck

* Fixed examples

* Fixed tests for latest changes in function and var names

* added missing deps

---------

Co-authored-by: Nicolas Torres <[email protected]>
Co-authored-by: Hugo Gruson <[email protected]>

* Now most examples run without errors. Those that not are temporarily enclosed in \dontrun

* Documentation of the seroprevalence_data and visualisation modules (#24)

Co-authored-by: Nicolás Torres Domínguez <[email protected]>

* Added test functions for plots

* doc: Update author's information in DESCRIPTION.

* Added myself to contributors

* Removed test/ folder

* Added a TODO

* More automatic tests

* Update .gitignore

Added dataframes actual test folder

* Fixed save_or_load_model to avoid DLL Bug

* same

* dontrun some examples

* same

* misc changes

* Some corrections to the documentation

* R CMD Check now seems to be working without errors (hopefully :)

* Some fixes to module documentation

* R CMD Check works without errors (locally)

* doc: review and correct visualization module documentation.

* doc: minor changes to seroprevalence_data module documentation.

* Add function to generate comparative plot of the models (#29)

* test: Add plot tests for each model to test_plot_functions.

* fix: Change GridExtra dependencie for cowplot (visualization module). Add plots for the 3 models to test_plot_functions.

* feat: Add function plot_models_list to the visualization module. This function plots a grid arrange by means of cowplot::plot_grid. A change that is still needed is to add proper default values for n_row and n_col or an exception for the case when they're passed as NULL. An example of the use of this function can be found at the end of test_plot_functions and the corresponding result can be visualized in plot-arrange-models.

* Minor changes to individual_models .svg files.

* Testing all platforms in github actions

* testing coverage

* added missing BH dep to make it work on windows

* added more missing deps

* doc: minor change to fit_model function documentation.

* add back the data folder to use mydata object when importing the library.

* doc: generate documentation with devtools::document().

* updated RMD Check tasks for vscode and docker to make them more similar to github actions'

* Added some deps to avoid warnings in R CMD Check

* Updated man pages with roxygen2

* Added dep to TBB to hopefully fix compilation problems in windows

* Upgraded rstan to v2.26.11. Added required TBB dep

* Updated SVGs and CSVs to match results from rstan v2.26.11

* Added mc-stan as extra repo to support rstan 2.26.11

* Misc fixes

* Rename plot_models_list to plot_seroprev_models_grid.

* doc: add documentation for plot_seroprev_models_grid function.

* Added more docker-related funcionality

* Added script to clean SVGs and CSVs when there rstan needs to be updated and tests fail

* misc changes

* Dev webrd (#32)

* test epidemics

* changes to vignette

* testing epidemics

* testing site

* improved vignette

* improved vignette

* improved vignette

* improved vignette with contributions

* improved vignette with contributions

* improved vignette with refernces

* improved vignette with references

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* use cases

* use cases

* update preloaded package datasets. mydata and serodata contain a copy of the same dataset for the time being.

* add additional changes to add multiple datasets to the package.

* doc: add datasets documentation files.

* use cases

* adding veev panama

* adding chik 2015

* adding chik 2015

* removing unnecesary data

* correcting chik data for nicaragua

* correcting chagas data for Colombia

* correcting chagas data for Colombia

* doc: add mydata and serodata documentation and .R files.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

---------

Co-authored-by: Zulma Cucunubá <[email protected]>
Co-authored-by: Zulma M Cucunubá <[email protected]>

* dependencie rstan (>= 2.26.11) changed to rstan (>= 2.21.1). 2.26.11 was generating an error in the installation of the package.

* Back to rstan (>= 2.26.11),

* Adding multiplatform tests

* test: run all tests for the new test dataset.

* update plot_functions test figures.

* doc: minor change to plot_seroprev_models_grid documentation.

* style: Update the name of the functions to specify they refer to seroprevalence models (seroprev sufix). Update the documentation correspondingly.

* style: mydata changed to serodata. The current dataset is chagas2012.RDS, but this will be changed to a simulated dataset in the future.

* update tdata_test dataset. The dataset now corresponds to chagas2012. This will be changed by a simulated dataset in the future.

* removed unused code

* Temporarily skipping tests on windows and mac, until we find an efficient way to test in those platforms without worrying about reproducibility

* branch change for testing

* updated testing snapshots

* misch changes

* added install deps task for vscode

* Added TODOs

* Added missing deps

* Added missing testthat snapthots

* Created new function `expect_similar_dataframes` to test dataframes using snapshots. It is compatible with column_comparation_functions

* Increased default tolerance to deal with rstan shenanigans

* testing ci

* Skipping these tests on CI

* Misc changes

* Temporary changes while we improve tests

* fix: solve minor typo in the name of function prepare_seroprev_data.

* Dev zulma vignette (#34)

* vignette draft

* vignette draft

* vignette draft

* testing vignette

* testing vignette

* updating vignette

* updating vignette

* remove doc of .gitignore

---------

Co-authored-by: zmcucunuba <[email protected]>
Co-authored-by: GeraldineGomez <[email protected]>

* Dev webrd (#35)

* test epidemics

* changes to vignette

* testing epidemics

* testing site

* improved vignette

* improved vignette

* improved vignette

* improved vignette with contributions

* improved vignette with contributions

* improved vignette with refernces

* improved vignette with references

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* use cases

* use cases

* update preloaded package datasets. mydata and serodata contain a copy of the same dataset for the time being.

* add additional changes to add multiple datasets to the package.

* doc: add datasets documentation files.

* use cases

* adding veev panama

* adding chik 2015

* adding chik 2015

* removing unnecesary data

* correcting chik data for nicaragua

* correcting chagas data for Colombia

* correcting chagas data for Colombia

* doc: add mydata and serodata documentation and .R files.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* changing rstan version from 2.26.11 (non existen) to > 2.21.1

* simulated fake data

* refac: test_sim_data is refactorized. I cleaned the code and added a function to plot the simulated datasets obtained for each foi example.

* Save selected simulated data for scenarios A,B and D to tests/sim_data. I took all the grouped datasets for n=5.

* chik-seroinference-simulations

---------

Co-authored-by: Zulma Cucunubá <[email protected]>
Co-authored-by: Zulma M Cucunubá <[email protected]>

* fix: function get_exposure_years was returning ages that were not consistent with the survey time and the minimal birth_year in the dataset. I changed the name of the function to get_exposure_ages for consistency with the output.

* fix: description typo.

* change the name of get_exposure_years to get_exposure_ages (for lack of a better name). Update mydata to serodata. Reran all tests (slight changes in the tests results).

* fix: updating functions and variables names in the vignettes files. This was causing the R-CMD github checks to fail.

* Removed dev from actions scripts

* Updated badges in README.Rmd. Updated README.md with latest changes from README.Rmd

* fix: add default value for seroprev_data to the prepare_seroprev_data function.

* Update prepare_seroprev_data documentation.

* doc: minor corrections to simulated_data.Rmd.

* webpage publication

* fixed bug "recompiling to avoid crashing R session"

* Update use_cases.Rmd

* Add simulated data generation (#36)

* Add conditional to prepare_seroprev_data. In some cases, like when datasets are being simulated, columns age_mean_f and birt_year need to be added prior to the data preparation in order to compute the exposure matrix.

* refac: modification of get_exposure_matrix. Now it does not depend on get_exposure_ages explicitely, this was a redundant dependency.

* testing changes in extract_seroprev_model_summary.

* feat: add functions get_sim_counts, generate_sim_data and generate_sim_data_grouped to module seroprevalence_data. This functions can be used to generate simulated datasets like is shown in test_simdata_caseA.R

* add results obtained by running the test test_simdata_caseA.R

* delete redundant or unnecessary tests and their corresponding results.

* remove old simulated data.

* Add simulated data test script (tests/testthat/test_simdata_cases.R) and results for a constant foi (case A) and for a stepwise decreasing foi (case B).

* doc: add documentation for the data simulation functions.

* Add title identifying the specific case of each simulation for the test test_simdata_cases.R. Update the corresponding figures.

* Save simulated data into testthat/exdata/ for cases A and B. They are stored automatically on running test_simdata_cases.

* remove unused man files.

* refac: Removed functions still in developing stage that will be added in a future version. In particular all functions for data simulation are removed. The function plot_seroprev_models_grid can be replaced in its current state by cowplot::plot_grid() function. Function get_comparison_table is unused.

* refac: Remove redundant tests and refactorize test_indivudual_models (now test_models); now it runs the models using a for cycle instead of running each model one by one. Remove unnecessary folder test/.

* Remove unused file R/test_vignettes.R

* Remove unused data files.

* Minor changes to vignettes.

* Remove cowplot and pracma from dependencies and unnecessary test file test_plot_functions.

* chore: change seroprev_model to seromodel.

* chore: change seroprev_data to serodata.

* chore: change model_object for seromodel_object.

* Add option print_summary with deaful TRUE to run_seromodel (modelling module).

* doc: update documentation for model_comparison and modelling modules.

* doc: update documentation for visualization and modelling seroprevalence_data modules.

* activate test-coverage github action for dev branch

* run models inside the for loop in test_models instead of using lapply function

* minor changes to documentation in all modules

* Add back cowplot dependencie since its used for some plotting functions

* change models names constant_foi_bi -> constant, continuous_foi_normal_bi -> tv_normal, continuous_foi_normal_log_bi -> tv_normal_log. tv stands for time-varying.

* change models names constant_foi_bi -> constant, continuous_foi_normal_bi -> tv_normal, continuous_foi_normal_log_bi -> tv_normal_log. tv stands for time-varying.

* refac: Divide test_models into three different tests (one for each current model). This is done in order to not use for loops in the coverage tests

* Dev datasets (#40)

* Remove year_init and year_end from the default dataset serodata

* Remove year_init and year_end from the default dataset chagas2012

* Remove year_init and year_end from the dataset chik2015

* Remove year_init and year_end from the dataset veev2012

* doc: remove year_init and year_end from documentation

* Dev plot foi (#41)

* remove unused test datasets

* add option to plot additional plot data to plot_foi and plot_seromodel methods

* add test for the plot_foi method of the visualization module

* update documentation for plot_foi and plot_seromodel. Add new simulated dataset serodata_simD and add test simulated data serodata_simD.R

* add test test_plot_foi

* change simulated foi data plot in plot_foi from scattered to line

* add the simulated datasets simdata_constant, simdata_sw_dec and simdata_large_epi that will be used in the vignettes' article 'FoI models'

* added scripts to test exceptions of visualisation module functions

* Dev vignettes: add contents to vignettes articles (#42)

* version of the package set to 0.0.9

* doc: update README.Rmd

* correct serofoi.Rproj

* doc: add FoI models vignette

* doc: modifications and corrections to Geting Started section of the vignettes

* doc: vignettes publication test

* doc: audd use_cases.Rmd vignette contents

* doc: add updated README.md file

* vignettes publication test

* vignettes publication test

* remove docs/ from .gitignore to test website publication

* add doc/ files generated by pkgdown::build_site function

* remove doc/ folder

* vignettes publication test: add dev to push activation branches in pkgdown workflow and change the deployment branch to dev

* Deploying to dev from @ 7c4f8f4 🚀

* website publication test: ignore docs folder. Remove dev from push trigger branches in pkgdown workflow and update the branch to gh-pages and the folder to ./

* doc: minor corrections to vignettes/references.bib

* remove skip_on_ci() from all tests

* Remove files generated by pkgdown (#45)

* Remove files generated by pkgdown

* Restore original pkgdown workflow

* Issue 47: fix inflexible age group structure definition for visualization (#49)

* remove link.svg file

* chore: update .gitignore file

* fix predicted_prev age definition in function get_prev_expanded (modelling module). Add test for error reproduction.

* Issue 47: fix inflexible age group structure definition for visualization (#49)

* remove link.svg file

* chore: update .gitignore file

* fix predicted_prev age definition in function get_prev_expanded (modelling module). Add test for error reproduction.

* Update _pkgdown.yml

* Dev (#44)

* Documentation of the visualisation and modelling modules

* automatic documentation of the visualisation and modeling modules

* minor changes to the documentation. Typos and minor bugs corrected.

* feat: define a preliminar version of the minimal dataset needed to use the library, now stored in data/data.RDS (data/data_bu.RDS is backup of the old dataset). The prepare_data() function in seroprevalence_data process the dataset creating 5 columns needed for the analysis (age_mean_f, sample_size, prev_obs, prev_obs_lower and prev_obs_upper). This function is tested in test/test_minimal_data and implemented in test_individual_models.

* fix: remove unused functions from all modules in preparation for a compiltation test. Remove the corresponding documentation files. Remove the folder R/stantmodels (it's redundant with inst/extdata/stanmodels). Update dependencies in DESCRIPTION (epitrix and cowplot removed).

* fix: prepare data_test for compilation of the package

* Dev compilation test nicolas (#10)

* minor changes in how the summary is shown

* change summary message

* minor change in extract_summary_model

* create template of vignette

* delete temporary files

* testing vignette

* vignette's test

* adding workflows sca and r-cmd-check

* adding workflows sca and r-cmd-check (#11)

* Static code review with lintr in package modules

* changing descriotion

* adding info into run-model function

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* adding a script for model comparison

* returning logo

* adding a script for model comparison

* adding a script for model comparison

* changing README.Rmd file

* changing README.Rmd file

* changing README.Rmd file

* changing README.Rmd file

* adding plots to the readme file

* adding plots to the readme file

* adding function for plotting raw seroprevalence data

* adding the packages name standart

* adding data reference for dplyr

* update function documentation

* Static code analysis for package modules

* Static code analysis for the modeling module

* Clean test/test_comparison.R. Add a warning for first compilation of the models. Minor sintaxis changes. Change slightly the name of the visualization module.

* fix: Calculate the  binomial confidence interval from the raw seroprevalence data in function plot_seroprev. The function is tested in test_plot_functions.R. Add compilation line to test_individual models.R.

* Compilation test in test_plot_functions.R

* minor changes before merging with dev

* feat: Add function prepare_bin_data to seroprevalence_data module. This function prepares the data to plot the binomial confidence intervals and allows to remove redundant code in the visualization and modelling modules.

* minor changes before merging with dev

* fix: corrects the bin size in plot_seroprev(). Minor syntax changes.

* doc: Add the corresponding documentation for plot_seroprev() to README.Rmd and README.md including the example image file man/figures/plot_seroprev_example.png

* Dev docu mg (#16)

* Added examples in core functions documentation

* Example of the functions in the documentation

* updating links of R-CMD check and Codecov test

* Dev doc nicolas (#18)

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* updating package version and contributors

* Dev doc nicolas (#20)

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* doc: minor changes to the modelling module. Quotation marks added for string variables in the documentation and some minor errors fixed.

* Dev docker tests (#22)

* 1st version of Dockerfile

* Addedd auto dep install for docker container

* Refactor docker folder

* Changed process to obtain path of stan and RDS files to make it compatible with testhat

* First version of tests

* Factored testing functions

* config.yml now only stores the base path of stan models

* Added automated test tasks for vscode

* Added more tests

* misc changes to vscode tasks

* Misc improvements to containers

* small fixes to container

* misc docker refactor

* moved docker scripts to an R file (tested only on Linux)

* Temporary change to test github actions on this branch

* added testthat to deps

* Added devtools to deps

* removed erroneous code in unit test

* moving config.yml to inst

* same

* temp changes to github actions files for testing

* doc: Update documentation for run_model, save_or_load_model and fit_model. The name of some functions and parameters were changed for the sake of clarity (make_yexpo -> get_exposure_years, save_or_read_model -> save_or_load_model, yexpo -> exposure_years, ). The order of functions definitions were in the modeling module were changed; now they appear in hierarchical order starting from run_model, since this is the most important function in the module.

* Added R CMD Check to Docker

* refac: fit_model_log function removed. Now the function fit_model has an exception that implements the logarithmic model as the removed function used to. fit_model documentation updated. Minor changes in the name of the objects returned by the functions.

* Added more files to rbuildignore

* more testing of github actions

* misc fixes

* testing windows

* adding BH dep

* Added linking deps for rstan

* added suggest deps for rstan

* doc: modelling module documentation updated. get_posterior_summary function removed (unused).

* Add LinkingTo field (#19)

* Add LinkingTo field

* Add roxygen comments from rstantools::use_rstan()

* temporarily removed some deps

* temp remove of this branch from yaml

* added vscode configs

* Fixes linking errors in R CMD CHeck

* Fixed examples

* Fixed tests for latest changes in function and var names

* added missing deps

---------

Co-authored-by: Nicolas Torres <[email protected]>
Co-authored-by: Hugo Gruson <[email protected]>

* Now most examples run without errors. Those that not are temporarily enclosed in \dontrun

* Documentation of the seroprevalence_data and visualisation modules (#24)

Co-authored-by: Nicolás Torres Domínguez <[email protected]>

* Added test functions for plots

* doc: Update author's information in DESCRIPTION.

* Added myself to contributors

* Removed test/ folder

* Added a TODO

* More automatic tests

* Update .gitignore

Added dataframes actual test folder

* Fixed save_or_load_model to avoid DLL Bug

* same

* dontrun some examples

* same

* misc changes

* Some corrections to the documentation

* R CMD Check now seems to be working without errors (hopefully :)

* Some fixes to module documentation

* R CMD Check works without errors (locally)

* doc: review and correct visualization module documentation.

* doc: minor changes to seroprevalence_data module documentation.

* Add function to generate comparative plot of the models (#29)

* test: Add plot tests for each model to test_plot_functions.

* fix: Change GridExtra dependencie for cowplot (visualization module). Add plots for the 3 models to test_plot_functions.

* feat: Add function plot_models_list to the visualization module. This function plots a grid arrange by means of cowplot::plot_grid. A change that is still needed is to add proper default values for n_row and n_col or an exception for the case when they're passed as NULL. An example of the use of this function can be found at the end of test_plot_functions and the corresponding result can be visualized in plot-arrange-models.

* Minor changes to individual_models .svg files.

* Testing all platforms in github actions

* testing coverage

* added missing BH dep to make it work on windows

* added more missing deps

* doc: minor change to fit_model function documentation.

* add back the data folder to use mydata object when importing the library.

* doc: generate documentation with devtools::document().

* updated RMD Check tasks for vscode and docker to make them more similar to github actions'

* Added some deps to avoid warnings in R CMD Check

* Updated man pages with roxygen2

* Added dep to TBB to hopefully fix compilation problems in windows

* Upgraded rstan to v2.26.11. Added required TBB dep

* Updated SVGs and CSVs to match results from rstan v2.26.11

* Added mc-stan as extra repo to support rstan 2.26.11

* Misc fixes

* Rename plot_models_list to plot_seroprev_models_grid.

* doc: add documentation for plot_seroprev_models_grid function.

* Added more docker-related funcionality

* Added script to clean SVGs and CSVs when there rstan needs to be updated and tests fail

* misc changes

* Dev webrd (#32)

* test epidemics

* changes to vignette

* testing epidemics

* testing site

* improved vignette

* improved vignette

* improved vignette

* improved vignette with contributions

* improved vignette with contributions

* improved vignette with refernces

* improved vignette with references

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* use cases

* use cases

* update preloaded package datasets. mydata and serodata contain a copy of the same dataset for the time being.

* add additional changes to add multiple datasets to the package.

* doc: add datasets documentation files.

* use cases

* adding veev panama

* adding chik 2015

* adding chik 2015

* removing unnecesary data

* correcting chik data for nicaragua

* correcting chagas data for Colombia

* correcting chagas data for Colombia

* doc: add mydata and serodata documentation and .R files.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

---------

Co-authored-by: Zulma Cucunubá <[email protected]>
Co-authored-by: Zulma M Cucunubá <[email protected]>

* dependencie rstan (>= 2.26.11) changed to rstan (>= 2.21.1). 2.26.11 was generating an error in the installation of the package.

* Back to rstan (>= 2.26.11),

* Adding multiplatform tests

* test: run all tests for the new test dataset.

* update plot_functions test figures.

* doc: minor change to plot_seroprev_models_grid documentation.

* style: Update the name of the functions to specify they refer to seroprevalence models (seroprev sufix). Update the documentation correspondingly.

* style: mydata changed to serodata. The current dataset is chagas2012.RDS, but this will be changed to a simulated dataset in the future.

* update tdata_test dataset. The dataset now corresponds to chagas2012. This will be changed by a simulated dataset in the future.

* removed unused code

* Temporarily skipping tests on windows and mac, until we find an efficient way to test in those platforms without worrying about reproducibility

* branch change for testing

* updated testing snapshots

* misch changes

* added install deps task for vscode

* Added TODOs

* Added missing deps

* Added missing testthat snapthots

* Created new function `expect_similar_dataframes` to test dataframes using snapshots. It is compatible with column_comparation_functions

* Increased default tolerance to deal with rstan shenanigans

* testing ci

* Skipping these tests on CI

* Misc changes

* Temporary changes while we improve tests

* fix: solve minor typo in the name of function prepare_seroprev_data.

* Dev zulma vignette (#34)

* vignette draft

* vignette draft

* vignette draft

* testing vignette

* testing vignette

* updating vignette

* updating vignette

* remove doc of .gitignore

---------

Co-authored-by: zmcucunuba <[email protected]>
Co-authored-by: GeraldineGomez <[email protected]>

* Dev webrd (#35)

* test epidemics

* changes to vignette

* testing epidemics

* testing site

* improved vignette

* improved vignette

* improved vignette

* improved vignette with contributions

* improved vignette with contributions

* improved vignette with refernces

* improved vignette with references

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* improved vignette with use cases

* use cases

* use cases

* update preloaded package datasets. mydata and serodata contain a copy of the same dataset for the time being.

* add additional changes to add multiple datasets to the package.

* doc: add datasets documentation files.

* use cases

* adding veev panama

* adding chik 2015

* adding chik 2015

* removing unnecesary data

* correcting chik data for nicaragua

* correcting chagas data for Colombia

* correcting chagas data for Colombia

* doc: add mydata and serodata documentation and .R files.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* doc: add documentation files for the additional incorporated datasets chagas2012, chik2015 and veev2012.

* changing rstan version from 2.26.11 (non existen) to > 2.21.1

* simulated fake data

* refac: test_sim_data is refactorized. I cleaned the code and added a function to plot the simulated datasets obtained for each foi example.

* Save selected simulated data for scenarios A,B and D to tests/sim_data. I took all the grouped datasets for n=5.

* chik-seroinference-simulations

---------

Co-authored-by: Zulma Cucunubá <[email protected]>
Co-authored-by: Zulma M Cucunubá <[email protected]>

* fix: function get_exposure_years was returning ages that were not consistent with the survey time and the minimal birth_year in the dataset. I changed the name of the function to get_exposure_ages for consistency with the output.

* fix: description typo.

* change the name of get_exposure_years to get_exposure_ages (for lack of a better name). Update mydata to serodata. Reran all tests (slight changes in the tests results).

* fix: updating functions and variables names in the vignettes files. This was causing the R-CMD github checks to fail.

* Removed dev from actions scripts

* Updated badges in README.Rmd. Updated README.md with latest changes from README.Rmd

* fix: add default value for seroprev_data to the prepare_seroprev_data function.

* Update prepare_seroprev_data documentation.

* doc: minor corrections to simulated_data.Rmd.

* webpage publication

* fixed bug "recompiling to avoid crashing R session"

* Update use_cases.Rmd

* Add simulated data generation (#36)

* Add conditional to prepare_seroprev_data. In some cases, like when datasets are being simulated, columns age_mean_f and birt_year need to be added prior to the data preparation in order to compute the exposure matrix.

* refac: modification of get_exposure_matrix. Now it does not depend on get_exposure_ages explicitely, this was a redundant dependency.

* testing changes in extract_seroprev_model_summary.

* feat: add functions get_sim_counts, generate_sim_data and generate_sim_data_grouped to module seroprevalence_data. This functions can be used to generate simulated datasets like is shown in test_simdata_caseA.R

* add results obtained by running the test test_simdata_caseA.R

* delete redundant or unnecessary tests and their corresponding results.

* remove old simulated data.

* Add simulated data test script (tests/testthat/test_simdata_cases.R) and results for a constant foi (case A) and for a stepwise decreasing foi (case B).

* doc: add documentation for the data simulation functions.

* Add title identifying the specific case of each simulation for the test test_simdata_cases.R. Update the corresponding figures.

* Save simulated data into testthat/exdata/ for cases A and B. They are stored automatically on running test_simdata_cases.

* remove unused man files.

* refac: Removed functions still in developing stage that will be added in a future version. In particular all functions for data simulation are removed. The function plot_seroprev_models_grid can be replaced in its current state by cowplot::plot_grid() function. Function get_comparison_table is unused.

* refac: Remove redundant tests and refactorize test_indivudual_models (now test_models); now it runs the models using a for cycle instead of running each model one by one. Remove unnecessary folder test/.

* Remove unused file R/test_vignettes.R

* Remove unused data files.

* Minor changes to vignettes.

* Remove cowplot and pracma from dependencies and unnecessary test file test_plot_functions.

* chore: change seroprev_model to seromodel.

* chore: change seroprev_data to serodata.

* chore: change model_object for seromodel_object.

* Add option print_summary with deaful TRUE to run_seromodel (modelling module).

* doc: update documentation for model_comparison and modelling modules.

* doc: update documentation for visualization and modelling seroprevalence_data modules.

* activate test-coverage github action for dev branch

* run models inside the for loop in test_models instead of using lapply function

* minor changes to documentation in all modules

* Add back cowplot dependencie since its used for some plotting functions

* change models names constant_foi_bi -> constant, continuous_foi_normal_bi -> tv_normal, continuous_foi_normal_log_bi -> tv_normal_log. tv stands for time-varying.

* change models names constant_foi_bi -> constant, continuous_foi_normal_bi -> tv_normal, continuous_foi_normal_log_bi -> tv_normal_log. tv stands for time-varying.

* refac: Divide test_models into three different tests (one for each current model). This is done in order to not use for loops in the coverage tests

* Dev datasets (#40)

* Remove year_init and year_end from the default dataset serodata

* Remove year_init and year_end from the default dataset chagas2012

* Remove year_init and year_end from the dataset chik2015

* Remove year_init and year_end from the dataset veev2012

* doc: remove year_init and year_end from documentation

* Dev plot foi (#41)

* remove unused test datasets

* add option to plot additional plot data to plot_foi and plot_seromodel methods

* add test for the plot_foi method of the visualization module

* update documentation for plot_foi and plot_seromodel. Add new simulated dataset serodata_simD and add test simulated data serodata_simD.R

* add test test_plot_foi

* change simulated foi data plot in plot_foi from scattered to line

* add the simulated datasets simdata_constant, simdata_sw_dec and simdata_large_epi that will be used in the vignettes' article 'FoI models'

* Dev vignettes: add contents to vignettes articles (#42)

* version of the package set to 0.0.9

* doc: update README.Rmd

* correct serofoi.Rproj

* doc: add FoI models vignette

* doc: modifications and corrections to Geting Started section of the vignettes

* doc: vignettes publication test

* doc: audd use_cases.Rmd vignette contents

* doc: add updated README.md file

* vignettes publication test

* vignettes publication test

* remove docs/ from .gitignore to test website publication

* add doc/ files generated by pkgdown::build_site function

* remove doc/ folder

* vignettes publication test: add dev to push activation branches in pkgdown workflow and change the deployment branch to dev

* Deploying to dev from @ 7c4f8f4 🚀

* website publication test: ignore docs folder. Remove dev from push trigger branches in pkgdown workflow and update the branch to gh-pages and the folder to ./

---------

Co-authored-by: megamezl <[email protected]>
Co-authored-by: tracelac <[email protected]>
Co-authored-by: zmcucunuba <[email protected]>
Co-authored-by: GeraldineGomez <[email protected]>
Co-authored-by: Miguel Enrique Gámez López <[email protected]>
Co-authored-by: Jaime Pavlich-Mariscal <[email protected]>
Co-authored-by: Hugo Gruson <[email protected]>
Co-authored-by: JAIME ANDRÉS PAVLICH MARISCAL <[email protected]>
Co-authored-by: Zulma Cucunubá <[email protected]>

* Remove files generated by pkgdown (#45)

* Remove files generated by pkgdown

* Restore original pkgdown workflow

* creating scripts for module tests

* refac: unify individual models tests into a single test for the modelling module. Remove unnecessary files

* add option bin_data to prepare_serodata (modelling) and plot_seroprev_fitted (visualization).

* test for the modelling module now compares the results with a standardize dataframe of the expanded prevalence which contains significant information about the seroprevalence fitting

* add models_serialization.R to tests/testthat. This script saves the model objects information into json format to avoid re-running and standardize models accross platforms for tests purposes.

* refactorize test for the visualization model reading the models from the corresponding json files.

* Added missing deps

* Added missing newline at the end

* Added missing data

* misc fixes

* moved RDS files outside data/ dir to comply with r-cmd-check

* Removed r-cmd-check warnings

* Removed save_or_load_model, since rstantools does that job now

* migrated to rstantools

* added dev to trigger action

* fix: update config R-CMD-check.yaml adding devel and oldrel-1 libraries for ubuntu release

* Revert "fix: update config R-CMD-check.yaml adding devel and oldrel-1 libraries for ubuntu release"

This reverts commit ed861cc.

* fix: update config R-CMD-check.yaml removing  release libraries for ubuntu release

* add missing config files

* remove obsolete src dir

* add missing dependency lines

* update config R-CMD-check.yaml adding macos, windows and ubuntu-latests devel/release and oldrel-1

* remove stray line

* fix: small change to stanmodels.R (normal_log_model)

* doc: minor correction to documentation. This addresses an R-CMD-check warning for ubuntu-latests (oldrel-1)

* doc: minor correction to documentation. This addresses an R-CMD-check warning for ubuntu-latests (oldrel-1) - 2nd try

---------

Co-authored-by: megamezl <[email protected]>
Co-authored-by: tracelac <[email protected]>
Co-authored-by: zmcucunuba <[email protected]>
Co-authored-by: GeraldineGomez <[email protected]>
Co-authored-by: Miguel Enrique Gámez López <[email protected]>
Co-authored-by: Jaime Pavlich-Mariscal <[email protected]>
Co-authored-by: Hugo Gruson <[email protected]>
Co-authored-by: JAIME ANDRÉS PAVLICH MARISCAL <[email protected]>
Co-authored-by: Zulma Cucunubá <[email protected]>
Co-authored-by: Miguel Enrique Gamez Lopez <[email protected]>
Co-authored-by: Sebastian Funk <[email protected]>
  • Loading branch information
12 people authored Jun 29, 2023
1 parent a8aa8d6 commit cfe9847
Show file tree
Hide file tree
Showing 57 changed files with 507 additions and 369 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, dev]
pull_request:
branches: [main, master]

Expand All @@ -18,11 +18,11 @@ jobs:
fail-fast: false
matrix:
config:
# - {os: macos-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
43 changes: 41 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ vignettes/*.pdf
.Rhistory


# RStudio Connect folder
rsconnect/

# Mac File
.DS_Store

Expand All @@ -53,5 +56,41 @@ _snaps/
!tests/testthat/_snaps
tests/testthat/Rplots.pdf
t,
tests/testthat/extdata/plots/actual/*.png
tests/testthat/extdata/dataframes/actual/*.csv


# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

inst/stan/*.rds

src/
53 changes: 31 additions & 22 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Authors@R:
),
person(
given = "Nicolás",
family = "T-Domínguez",
family = "T. Domínguez",
role = c("aut"),
email = "[email protected]",
comment = c(ORCID = "https://orcid.org/0009-0002-8484-1298")
Expand All @@ -38,38 +38,47 @@ LazyData: true
RoxygenNote: 7.2.3
Depends:
R (>= 3.5.0)
Imports:
config,
rstan (>= 2.21.1),
StanHeaders,
tidyverse,
reshape2,
bayesplot,
loo,
Hmisc,
Imports:
methods,
Rcpp (>= 0.12.0),
RcppParallel (>= 5.0.1),
rstan (>= 2.18.1),
rstantools (>= 2.3.1),
dplyr,
gsubfn,
usethis,
testthat (>= 3.0.0),
vdiffr (>= 1.0.0),
bayesplot,
config,
cowplot,
devtools,
methods,
Rcpp,
ggplot2,
BH,
RcppEigen,
RcppParallel,
gsubfn,
Hmisc,
jsonlite,
loo,
purrr,
cowplot
qtl,
reshape2,
tidyverse,
usethis,
vdiffr (>= 1.0.0)
LinkingTo:
BH (>= 1.66.0),
Rcpp (>= 0.12.0),
RcppEigen (>= 0.3.3.3.0),
RcppParallel (>= 5.0.1),
rstan (>= 2.18.1),
StanHeaders (>= 2.18.0)
Suggests:
knitr,
rmarkdown
rmarkdown,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Config/Needs/website:
epiverse-trace/epiversetheme
VignetteBuilder: knitr
URL: https://trace-lac.github.io/serofoi/
Additional_repositories:
https://mc-stan.org/r-packages/
Config/testthat/edition: 3
Remotes:
tidyverse/purrr
Biarch: true
SystemRequirements: GNU make
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export(plot_seroprev_fitted)
export(prepare_bin_data)
export(prepare_serodata)
export(run_seromodel)
export(save_or_load_model)
import(Rcpp)
import(dplyr)
import(methods)
Expand All @@ -24,3 +23,4 @@ importFrom(graphics,text)
importFrom(rstan,sampling)
importFrom(stats,quantile)
importFrom(utils,read.table)
useDynLib(serofoi, .registration = TRUE)
1 change: 1 addition & 0 deletions R/chagas2012.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO Check if we really need to have the package `qtl` installed. Otherwise remove all entries of the form `see \code{\link[qtl]...`
#' Seroprevalence data on serofoi
#'
#' Data from a serological surveys
Expand Down
115 changes: 44 additions & 71 deletions R/modelling.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Function that runs the specified stan model for the Force-of-Infection and estimates de seroprevalence based on the result of the fit
#'
#' This function runs the specified model for the Force-of-Infection \code{foi_model} using the data froma seroprevalence survey
# TODO Complete @param documentation


#' Function that runs the specified stan model for the Force-of-Infection and estimates de seroprevalence based on the result of the fit
#'
#' This function runs the specified model for the Force-of-Infection \code{foi_model} using the data froma seroprevalence survey
#' \code{serodata} as the input data. See \link{fit_seromodel} for further details.
#'
#' @param serodata A data frame containing the data from a seroprevalence survey.
Expand Down Expand Up @@ -36,6 +39,7 @@
#' For further details refer to the \code{control} parameter in \link[rstan]{sampling} or \href{https://mc-stan.org/rstanarm/reference/adapt_delta.html}{here}.
#' @param m_treed Maximum tree depth for the binary tree used in the NUTS stan sampler. For further details refer to the \code{control} parameter in \link[rstan]{sampling}.
#' @param decades Number of decades covered by the survey data.
#' @param print_summary TBD
#' @return \code{seromodel_object}. An object containing relevant information about the implementation of the model. For further details refer to \link{fit_seromodel}.
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -69,46 +73,11 @@ run_seromodel <- function(serodata,
return(seromodel_object)
}

# TODO The warning 'recompiling to avoid crashing R session' still appears when the function is run for a second time.
#' Function used to determine whether the stan model corresponding to the specified serological model has been already compiled or not
#'
#' This function determines whether the corresponding .RDS file of the selected model exists or not.
#' In case the .RDS file exists, it is read and returned; otherwise, the object model is created through the
#' \link[rstan]{stan_model} function, saved as an .RDS file and returned as the output of the function.
#' @param foi_model Name of the selected model. Current version provides three options:
#' \describe{
#' \item{\code{"constant"}}{Runs a constant model}
#' \item{\code{"tv_normal"}}{Runs a normal model}
#' \item{\code{"tv_normal_log"}}{Runs a normal logarithmic model}
#' }
#' @return \code{model}. The rstan model object corresponding to the selected model.
#' @examples
#' \dontrun{
#' model <- save_or_load_model(foi_model="constant")
#' }
#'
#' @export

save_or_load_model <- function(foi_model = "constant") {
base_path <- config::get("stan_models_base_path",
file = system.file("config.yml", package = "serofoi", mustWork = TRUE))
rds_path <- system.file(base_path, paste(foi_model, ".rds", sep = ""), package = getPackageName())
if (!file.exists(rds_path)) {
message(sprintf("\nNo rds file found for model %s. Compiling stan model...", foi_model))
}
stan_path <- system.file(base_path, paste(foi_model, ".stan", sep = ""), package = getPackageName())

model <- rstan::stan_model(stan_path, auto_write = TRUE)

return(model)
}


#' Function that fits the selected model to the specified seroprevalence survey data
#'
#' This function fits the specified model \code{foi_model} to the serological survey data \code{serodata}
#' by means of the \link[rstan]{sampling} method. The function determines whether the corresponding stan model
#' object needs to be compiled by means of the function \link{save_or_load_model}.
#'
#' This function fits the specified model \code{foi_model} to the serological survey data \code{serodata}
#' by means of the \link[rstan]{sampling} method. The function determines whether the corresponding stan model
#' object needs to be compiled by rstan.
#' @param serodata A data frame containing the data from a seroprevalence survey. For further details refer to \link{run_seromodel}.
#' @param foi_model Name of the selected model. Current version provides three options:
#' \describe{
Expand Down Expand Up @@ -160,7 +129,7 @@ fit_seromodel <- function(serodata,
m_treed = 10,
decades = 0) {
# TODO Add a warning because there are exceptions where a minimal amount of iterations is needed
model <- save_or_load_model(foi_model)
model <- stanmodels[[foi_model]]
exposure_ages <- get_exposure_ages(serodata)
exposure_years <- (min(serodata$birth_year):serodata$tsur[1])[-1]
exposure_matrix <- get_exposure_matrix(serodata)
Expand Down Expand Up @@ -280,7 +249,7 @@ fit_seromodel <- function(serodata,

#' Function that generates an atomic vector containing the corresponding exposition years of a serological survey
#'
#' This function generates an atomic vector containing the exposition years corresponding to the specified serological survey data \code{serodata}.
#' This function generates an atomic vector containing the exposition years corresponding to the specified serological survey data \code{serodata}.
#' The exposition years to the disease for each individual corresponds to the time from birth to the moment of the survey.
#' @param serodata A data frame containing the data from a seroprevalence survey. This data frame must contain the year of birth for each individual (birth_year) and the time of the survey (tsur). birth_year can be constructed by means of the \link{prepare_serodata} function.
#' @return \code{exposure_ages}. An atomic vector with the numeration of the exposition years in serodata
Expand Down Expand Up @@ -321,15 +290,15 @@ get_exposure_matrix <- function(serodata) {

#' Method to extact a summary of the specified serological model object
#'
#' This method extracts a summary corresponding to a serological model object that contains information about the original serological
#' survey data used to fit the model, such as the year when the survey took place, the type of test taken and the corresponding antibody,
#' as well as information about the convergence of the model, like the expected log pointwise predictive density \code{elpd} and its
#' This method extracts a summary corresponding to a serological model object that contains information about the original serological
#' survey data used to fit the model, such as the year when the survey took place, the type of test taken and the corresponding antibody,
#' as well as information about the convergence of the model, like the expected log pointwise predictive density \code{elpd} and its
#' corresponding standar deviation.
#' @param seromodel_object \code{seromodel_object}. An object containing relevant information about the implementation of the model.
#' @param seromodel_object \code{seromodel_object}. An object containing relevant information about the implementation of the model.
#' Refer to \link{fit_seromodel} for further details.
#' @return \code{model_summary}. Object with a summary of \code{seromodel_object} containing the following:
#' \tabular{ll}{
#' \code{foi_model} \tab Name of the selected model. For further details refer to \link{save_or_load_model}. \cr \tab \cr
#' \code{foi_model} \tab Name of the selected model. \cr \tab \cr
#' \code{data_set} \tab Seroprevalence survey label.\cr \tab \cr
#' \code{country} \tab Name of the country were the survey was conducted in. \cr \tab \cr
#' \code{year} \tab Year in which the survey was conducted. \cr \tab \cr
Expand Down Expand Up @@ -385,14 +354,15 @@ extract_seromodel_summary <- function(seromodel_object) {
return(model_summary)
}


#' Function that generates an object containing the confidence interval based on a
# TODO Complete @param documentation
#' Function that generates an object containing the confidence interval based on a
#' Force-of-Infection fitting
#'
#' This function computes the corresponding binomial confidence intervals for the obtained prevalence based on a fitting
#' of the Force-of-Infection \code{foi} for plotting an analysis purposes.
#' @param serodata A data frame containing the data from a seroprevalence survey. For further details refer to \link{run_seromodel}.
#' of the Force-of-Infection \code{foi} for plotting an analysis purposes.
#' @param foi Object containing the information of the force of infection. It is obtained from \code{rstan::extract(seromodel_object$fit, "foi", inc_warmup = FALSE)[[1]]}.
#' @param serodata A data frame containing the data from a seroprevalence survey. For further details refer to \link{run_seromodel}.
#' @param bin_data TBD
#' @return \code{prev_final}. The expanded prevalence data. This is used for plotting purposes in the \code{visualization} module.
#' @examples
#' \dontrun{
Expand All @@ -404,8 +374,10 @@ extract_seromodel_summary <- function(seromodel_object) {
#' }
#' @export
get_prev_expanded <- function(foi,
serodata) {
serodata,
bin_data = FALSE) {
dim_foi <- dim(foi)[2]
# TODO: check whether this conditional is necessary
if (dim_foi < 80) {
oldest_year <- 80 - dim_foi + 1
foin <- matrix(NA, nrow = dim(foi)[1], 80)
Expand Down Expand Up @@ -438,7 +410,7 @@ get_prev_expanded <- function(foi,
medianv <- apply(prev_pn, 2, function(x) quantile(x, 0.5))

predicted_prev <- data.frame(
age = 1:80,
age = 1:age_max,
predicted_prev = medianv,
predicted_prev_lower = lower,
predicted_prev_upper = upper
Expand All @@ -460,22 +432,23 @@ get_prev_expanded <- function(foi,
observed_prev,
by = "age",
all.x = TRUE) %>% dplyr::mutate(survey = serodata$survey[1])

# I added this here for those cases when binned is prefered for plotting
if (serodata$age_max[1] - serodata$age_min[1] < 3) {
xx <- prepare_bin_data(serodata)
prev_final <-
base::merge(prev_expanded, xx, by = "age", all.x = TRUE)
} else {
prev_final <- prev_expanded %>% dplyr::mutate(
cut_ages = "original",
bin_size = .data$sample_by_age,
bin_pos = .data$positives,
p_obs_bin = .data$prev_obs,
p_obs_bin_l = .data$prev_obs_lower,
p_obs_bin_u = .data$prev_obs_upper
)
if (bin_data) {
# I added this here for those cases when binned is prefered for plotting
if (serodata$age_max[1] - serodata$age_min[1] < 3) {
xx <- prepare_bin_data(serodata)
prev_expanded <-
base::merge(prev_expanded, xx, by = "age", all.x = TRUE)
} else {
prev_expanded <- prev_expanded %>% dplyr::mutate(
cut_ages = "original",
bin_size = .data$sample_by_age,
bin_pos = .data$positives,
p_obs_bin = .data$prev_obs,
p_obs_bin_l = .data$prev_obs_lower,
p_obs_bin_u = .data$prev_obs_upper
)
}
}

return(prev_final)
return(prev_expanded)
}
21 changes: 21 additions & 0 deletions R/serofoi-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' The 'serofoi' package.
#'
#' @description A DESCRIPTION OF THE PACKAGE
#'
#' @docType package
#' @name serofoi-package
#' @aliases serofoi
#' @useDynLib serofoi, .registration = TRUE
#' @import dplyr
#' @importFrom dplyr %>%

#' @import methods
#' @import Rcpp
#' @importFrom rstan sampling
#' @importFrom graphics text
#' @importFrom utils read.table
#' @importFrom stats quantile
#' @references
#' Stan Development Team (NA). RStan: the R interface to Stan. R package version 2.26.22. https://mc-stan.org
#'
NULL
Loading

0 comments on commit cfe9847

Please sign in to comment.