diff --git a/README.md b/README.md index 704749b..5a901f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # epikinetics [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) [![R-CMD-check](https://github.com/seroanalytics/epikinetics/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/seroanalytics/epikinetics/actions/workflows/check-standard.yaml) [![codecov](https://codecov.io/gh/seroanalytics/epikinetics/graph/badge.svg?token=5MZYYDUZYH)](https://codecov.io/gh/seroanalytics/epikinetics) +`epikinetics` is an R package for Bayesian hierarchical modelling of antibody kinetics. + +The underlying model is taken from [Russell TW et al., Real-time estimation of immunological responses against emerging SARS-CoV-2 variants in the UK: a mathematical modelling study.](#References) + # Installing This package uses `cmdstanr`, which isn't available on cran, so you will first have to install it as follows: @@ -35,3 +39,6 @@ local changes you have to actually run `devtools::install()`. To build a Docker image, run `docker/build`. To push a new image to Dockerhub, `docker/push`. An image is built and pushed during CI on merge to main. + +# References +Russell TW, Townsley H, Hellewell J, Gahir J, Shawe-Taylor M, Greenwood D, Hodgson D, Hobbs A, Dowgier G, Penn R, Sanderson T, Stevenson-Leggett P, Bazire J, Harvey R, Fowler AS, Miah M, Smith C, Miranda M, Bawumia P, Mears HV, Adams L, Hatipoglu E, O'Reilly N, Warchal S, Ambrose K, Strange A, Kelly G, Kjar S, Papineni P, Corrah T, Gilson R, Libri V, Kassiotis G, Gamblin S, Lewis NS, Williams B, Swanton C, Gandhi S, Beale R, Wu MY, Bauer DLV, Carr EJ, Wall EC, Kucharski AJ. Real-time estimation of immunological responses against emerging SARS-CoV-2 variants in the UK: a mathematical modelling study. Lancet Infect Dis. 2024 Sep 11:S1473-3099(24)00484-5. doi: [10.1016/S1473-3099(24)00484-5](https://doi.org/10.1016/s1473-3099(24)00484-5). diff --git a/tests/testthat/test-relative-dates.R b/tests/testthat/test-relative-dates.R new file mode 100644 index 0000000..1664a18 --- /dev/null +++ b/tests/testthat/test-relative-dates.R @@ -0,0 +1,18 @@ +test_that("Can get stan data", { + dat <- data.table::fread(test_path("testdata", "testinput_absolutedates.csv")) + priors <- biokinetics_priors(mu_values = c(1, 2, 3, 4, 5, 6), + sigma_values = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)) + mod <- biokinetics$new(data = dat, priors = priors) + stan_data <- mod$get_stan_data() + expect_true(is.list(stan_data)) + expect_equal(names(stan_data), c("N", "N_events", "id", "value", "censored", + "titre_type", "preds_sd", "K", "N_uncens", "N_lo", + "N_hi", "uncens_idx", "cens_lo_idx", + "cens_hi_idx", "t", "X", "P", "mu_t0", + "mu_tp", "mu_ts", "mu_m1", "mu_m2", "mu_m3", + "sigma_t0", "sigma_tp", "sigma_ts", "sigma_m1", "sigma_m2", + "sigma_m3")) + expect_equal(stan_data$mu_t0, priors$mu_t0) + expect_equal(stan_data$sigma_t0, priors$sigma_t0) + expect_equal(stan_data$id, dat$pid) +}) diff --git a/tests/testthat/test-snapshot.R b/tests/testthat/test-snapshot.R new file mode 100644 index 0000000..0d72efd --- /dev/null +++ b/tests/testthat/test-snapshot.R @@ -0,0 +1,10 @@ +test_that("Model outputs are consistent", { + mod <- biokinetics$new(file_path = system.file("delta_full.rds", package = "epikinetics")) + res <- mod$fit(chains = 4, + parallel_chains = 4, + iter_warmup = 10, + iter_sampling = 40, + threads_per_chain = 4, + seed = 1) + expect_snapshot(res) +}) diff --git a/tests/testthat/testdata/testinput_absolutedates.csv b/tests/testthat/testdata/testinput_absolutedates.csv new file mode 100644 index 0000000..80fed48 --- /dev/null +++ b/tests/testthat/testdata/testinput_absolutedates.csv @@ -0,0 +1,22 @@ +pid,date,last_exp_date,titre_type,value,censored,infection_history,last_vax_type,exp_num +1,2021-03-10,2021-03-08,Ancestral,175.9349878,0,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Ancestral,607.57499,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Ancestral,179.0462942,0,Infection naive,BNT162b2,2 +1,2021-03-10,2021-03-08,Alpha,5,-1,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Alpha,416.790471100001,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Alpha,103.5273976,0,Infection naive,BNT162b2,2 +1,2021-03-10,2021-03-08,Delta,5,-1,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Delta,288.1785015,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Delta,128.8900265,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Ancestral,595.449313599998,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Ancestral,430.528648299999,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Ancestral,198.2081189,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Ancestral,110.3680043,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Alpha,189.0453557,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Alpha,142.9343886,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Alpha,133.8404918,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Alpha,93.9296002800003,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Delta,72.02175288,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Delta,92.7027533499997,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Delta,46.2628491,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Delta,54.55012061,0,Infection naive,BNT162b2,2 \ No newline at end of file diff --git a/tests/testthat/testdata/testinput_relativedates.csv b/tests/testthat/testdata/testinput_relativedates.csv new file mode 100644 index 0000000..80fed48 --- /dev/null +++ b/tests/testthat/testdata/testinput_relativedates.csv @@ -0,0 +1,22 @@ +pid,date,last_exp_date,titre_type,value,censored,infection_history,last_vax_type,exp_num +1,2021-03-10,2021-03-08,Ancestral,175.9349878,0,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Ancestral,607.57499,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Ancestral,179.0462942,0,Infection naive,BNT162b2,2 +1,2021-03-10,2021-03-08,Alpha,5,-1,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Alpha,416.790471100001,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Alpha,103.5273976,0,Infection naive,BNT162b2,2 +1,2021-03-10,2021-03-08,Delta,5,-1,Infection naive,BNT162b2,2 +1,2021-04-15,2021-03-08,Delta,288.1785015,0,Infection naive,BNT162b2,2 +1,2021-07-08,2021-03-08,Delta,128.8900265,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Ancestral,595.449313599998,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Ancestral,430.528648299999,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Ancestral,198.2081189,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Ancestral,110.3680043,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Alpha,189.0453557,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Alpha,142.9343886,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Alpha,133.8404918,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Alpha,93.9296002800003,0,Infection naive,BNT162b2,2 +2,2021-02-23,2021-01-11,Delta,72.02175288,0,Infection naive,BNT162b2,2 +2,2021-03-16,2021-01-11,Delta,92.7027533499997,0,Infection naive,BNT162b2,2 +2,2021-04-27,2021-01-11,Delta,46.2628491,0,Infection naive,BNT162b2,2 +2,2021-07-27,2021-01-11,Delta,54.55012061,0,Infection naive,BNT162b2,2 \ No newline at end of file