Skip to content

Commit

Permalink
add est.incidence.by test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisorwa committed Nov 10, 2024
2 parents 29fe7dc + 0420364 commit 0ad4a23
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 104 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/lint-changed-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ jobs:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
- uses: r-lib/actions/setup-r-dependencies@HEAD
with:
extra-packages: |
any::gh
any::lintr
any::purrr
needs: check
needs: lint

- name: Add lintr options
run: |
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: serocalculator
Title: Estimating Infection Rates from Serological Data
Version: 1.2.0.9020
Version: 1.2.0.9021
Authors@R: c(
person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# serocalculator (development version)

## New features

* Added example datasets with documentation for examples and testing (#314)

* Improved error messaging for `autoplot.pop_data()` (#234).

* Clarified package installation instructions in scrub typhus vignette (#234).
Expand All @@ -25,6 +28,10 @@
## Internal changes
* Change default pipe setting (#312)

* Added `snapshot_value` test for `est.incidence()` (#315)

* Sped up `lint-changed-files` GitHub Action (#317)

* Added online preview builds for PRs that change the `pkgdown` website (#309)

* Added `test-autoplot.pop_data` test (#234)
Expand Down
26 changes: 26 additions & 0 deletions R/example_noise_params_pk.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' @title Small example of noise parameters for typhoid
#'
#' @description A subset of noise parameter estimates from the SEES study,
#' for examples and testing.
#'
#' @format ## `example_noise_params_pk`
#' A `curve_params` object (from [as_curve_params()]) with 4 rows and 7 columns:
#' \describe{
#' \item{antigen_iso}{which antigen and isotype are being measured
#' (data is in long format)}
#' \item{Country}{Location for which the noise parameters were estimated}
#' \item{y.low}{Lower limit of detection}
#' \item{eps}{Measurement noise, defined by a CV (coefficient of variation)
#' as the ratio of the standard deviation to the mean for replicates.
#' Note that the CV should ideally be measured across plates
#' rather than within the same plate.}
#' \item{nu}{Biological noise: error from
#' cross-reactivity to other antibodies.
#' It is defined as the 95th percentile of
#' the distribution of antibody responses to the antigen-isotype
#' in a population with no exposure.}
#' \item{y.high}{Upper limit of detection}
#' \item{Lab}{Lab for which noise was estimated.}
#' }
#' @source <https://osf.io/rtw5k>
"example_noise_params_pk"
19 changes: 19 additions & 0 deletions R/example_typhoid_curves_nostrat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Small example of antibody response curve parameters for typhoid
#'
#' A subset of data from the SEES study, for examples and testing.
#'
#' @format ## `typhoid_curves_nostrat_100`
#' A `curve_params` object (from [as_curve_params()]) with 500 rows and 7
#' columns:
#' \describe{
#' \item{antigen_iso}{which antigen and isotype are being measured
#' (data is in long format)}
#' \item{iter}{MCMC iteration}
#' \item{y0}{Antibody concentration at t = 0 (start of active infection)}
#' \item{y1}{Antibody concentration at t = `t1` (end of active infection)}
#' \item{t1}{Duration of active infection}
#' \item{alpha}{Antibody decay rate coefficient}
#' \item{r}{Antibody decay rate exponent parameter}
#' }
#' @source <https://osf.io/rtw5k>
"typhoid_curves_nostrat_100"
37 changes: 37 additions & 0 deletions R/sees_pop_data_pakistan_100.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Small example cross-sectional data set
#'
#' A subset of data from the SEES data, for examples and testing.
#'
#' @format ## `sees_pop_data_pk_100`
#' A `pop_data` object (from [as_pop_data()]) with 200 rows and 8 columns:
#' \describe{
#' \item{id}{Observation ID}
#' \item{Country}{Country where the participant was living}
#' \item{cluster}{survey sampling cluster}
#' \item{catchment}{survey catchment area}
#' \item{age}{participant's age when sampled, in years}
#' \item{antigen_iso}{which antigen and isotype are being measured
#' (data is in long format)}
#' \item{value}{concentration of antigen isotype, in ELISA units}
#' }
#' @source <https://osf.io/n6cp3>
"sees_pop_data_pk_100"

#' Small example cross-sectional data set
#'
#' A subset of data from the SEES data, for examples and testing.
#'
#' @format ## `sees_pop_data_pk_100_old_names`
#' A `pop_data` object (from [as_pop_data()]) with 200 rows and 8 columns:
#' \describe{
#' \item{index_id}{Observation ID}
#' \item{Country}{Country where the participant was living}
#' \item{cluster}{survey sampling cluster}
#' \item{catchment}{survey catchment area}
#' \item{Age}{participant's age when sampled, in years}
#' \item{antigen_iso}{which antigen and isotype are being measured
#' (data is in long format)}
#' \item{result}{concentration of antigen isotype, in ELISA units}
#' }
#' @source <https://osf.io/n6cp3>
"sees_pop_data_pk_100_old_names"
5 changes: 5 additions & 0 deletions data-raw/example_noise_params_pk.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
example_noise_params_pk <-
load_noise_params("https://osf.io/download//hqy4v/") %>%
filter(Country == "Pakistan")

usethis::use_data(example_noise_params_pk, overwrite = TRUE)
23 changes: 23 additions & 0 deletions data-raw/sees_pop_data_pakistan_100.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sees_pop_data_pk_100 <- load_pop_data(
file_path = "https://osf.io/download//n6cp3/",
age = "Age",
value = "result",
id = "index_id",
standardize = TRUE
) %>%
filter(Country == "Pakistan") %>%
slice_head(n = 100, by = antigen_iso)

usethis::use_data(sees_pop_data_pk_100, overwrite = TRUE)

sees_pop_data_pk_100_old_names <- load_pop_data(
file_path = "https://osf.io/download//n6cp3/",
age = "Age",
value = "result",
id = "index_id",
standardize = FALSE
) %>%
filter(Country == "Pakistan") %>%
slice_head(n = 100, by = antigen_iso)

usethis::use_data(sees_pop_data_pk_100_old_names, overwrite = TRUE)
5 changes: 5 additions & 0 deletions data-raw/typhoid_curves_nostrat_100.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typhoid_curves_nostrat_100 <-
load_curve_params("https://osf.io/download/rtw5k/") %>%
dplyr::filter(iter %in% 1:100)

usethis::use_data(typhoid_curves_nostrat_100, overwrite = TRUE)
Binary file added data/example_noise_params_pk.rda
Binary file not shown.
Binary file added data/sees_pop_data_pk_100.rda
Binary file not shown.
Binary file added data/sees_pop_data_pk_100_old_names.rda
Binary file not shown.
Binary file added data/typhoid_curves_nostrat_100.rda
Binary file not shown.
40 changes: 40 additions & 0 deletions man/example_noise_params_pk.Rd

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

32 changes: 32 additions & 0 deletions man/sees_pop_data_pk_100.Rd

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

32 changes: 32 additions & 0 deletions man/sees_pop_data_pk_100_old_names.Rd

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

33 changes: 33 additions & 0 deletions man/typhoid_curves_nostrat_100.Rd

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

12 changes: 10 additions & 2 deletions tests/testthat/_snaps/est.incidence.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# est.incidence() produces expected results for typhoid data

Code
typhoid_results
summary(typhoid_results)
Output
# A tibble: 1 x 10
est.start incidence.rate SE CI.lwr CI.upr coverage log.lik iterations
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
1 0.1 0.133 0.0216 0.0962 0.182 0.95 -261. 4
1 0.1 0.166 0.0178 0.135 0.205 0.95 -524. 5
# i 2 more variables: antigen.isos <chr>, nlm.convergence.code <ord>

---

structure(list(minimum = 523.575044823023, estimate = -1.7955958453869,
gradient = 3.60891331241403e-06, hessian = structure(86.991906300701, dim = c(1L,
1L)), code = 1L, iterations = 5L), class = c("seroincidence",
"list"), lambda_start = 0.1, antigen_isos = c("HlyE_IgG", "HlyE_IgA"
))

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/log_likelihood.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `log_likelihood()` gives consistent results

-9268.8238
-533.379886031329

Loading

0 comments on commit 0ad4a23

Please sign in to comment.