diff --git a/.DS_Store b/.DS_Store index 0138b133..b717a712 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 86e619a3..3d06234e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ outputs/fits/* - +vignettes/int/* # Except for the simulate_data directory !outputs/fits/simulated_data/ diff --git a/R/.DS_Store b/R/.DS_Store deleted file mode 100644 index 51e77870..00000000 Binary files a/R/.DS_Store and /dev/null differ diff --git a/R/postprocess.R b/R/postprocess.R index 7a549be8..f92d17f8 100644 --- a/R/postprocess.R +++ b/R/postprocess.R @@ -283,6 +283,7 @@ plot_inf_rec <- function(model_summary, file_path) { ggsave(here::here(file_path, "infection_recov.png"), height = 10, width = 10) } + plot_cop_rec <- function(model_summary, file_path) { fitfull <- model_summary$fit diff --git a/R/utils_model.R b/R/utils_model.R index 94bfea8d..bbc0a5be 100644 --- a/R/utils_model.R +++ b/R/utils_model.R @@ -243,8 +243,10 @@ createSeroJumpModel <- function( sample(1:length(exp_prior_list[[i]]), 1, prob = exp_prior_list[[i]]) } - check_exposures_times(data_sero, data_known, exposureTypes, exposureFitted, exposurePriorTime, exposurePriorTimeType) - + if (!is.null(data_known)) { + check_exposures_times(data_sero, data_known, exposureTypes, exposureFitted, exposurePriorTime, exposurePriorTimeType) + } + data_t$exp_list <- exp_prior_list data_t$exp_prior <- exp_prior diff --git a/docs/404.html b/docs/404.html index b7d01be9..9d959d58 100644 --- a/docs/404.html +++ b/docs/404.html @@ -52,7 +52,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 0a713681..15f7f3e7 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/articles/cs1_sim_recovery.html b/docs/articles/cs1_sim_recovery.html index 1c1b3ed2..05e5586d 100644 --- a/docs/articles/cs1_sim_recovery.html +++ b/docs/articles/cs1_sim_recovery.html @@ -52,7 +52,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files @@ -80,7 +80,7 @@

    Case Study 1: Simulation Recovery

    David Hodgson

    -

    2024-10-23

    +

    2024-10-24

    diff --git a/docs/articles/cs2_sarscov2.html b/docs/articles/cs2_sarscov2 copy.html similarity index 96% rename from docs/articles/cs2_sarscov2.html rename to docs/articles/cs2_sarscov2 copy.html index c797ad83..bff51779 100644 --- a/docs/articles/cs2_sarscov2.html +++ b/docs/articles/cs2_sarscov2 copy.html @@ -52,7 +52,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files @@ -81,10 +81,10 @@

    Case Study 2: SARS-CoV-2 inference in The

    David Hodgson

    -

    2024-10-23

    +

    2024-10-24

    - + @@ -124,6 +124,7 @@

    Step 2: Read Simulated DataThis data has been generated using serosim.

     wave_full <- readRDS(file = "wave2_export.RDS")
    +#wave_full <- readRDS(file = "./vignettes/wave2_export.RDS")
     
     sero_data_w2 <- wave_full$sero_data
     known_inf_w2 <- wave_full$known_inf
    @@ -137,6 +138,7 @@ 

    Step 2: Read Simulated Data## No individuals with less than 15 days in the study!

     wave_full <- readRDS(file = "wave3_export.RDS")
    +#wave_full <- readRDS(file = "./vignettes/wave3_export.RDS")
     
     sero_data_w3 <- wave_full$sero_data
     known_inf_w3 <- wave_full$known_inf
    @@ -267,7 +269,9 @@ 

    Step 4: Define the ## Prior parameters of abkineticsModel are: y1_d, t1_d, r_d, y1_vax, t1_vax, r_vax, y1_pd, t1_pd, r_pd, s, wane, y1_d_a, t1_d_a, r_d_a, y1_vax_a, t1_vax_a, r_vax_a, y1_pd_a, t1_pd_a, r_pd_a, s_a, wane_a ## No single entries in data_sero!, ## No individuals with less than 15 days in the study!

    -
    ## Warning in addExposurePrior_checkempirical(exp_prior, T_max): Warning: The number of rows in the exposure prior dataframe does not match the number of time points in the study
    +
    ## Warning in addExposurePrior_checkempirical(exp_prior, T_max): Warning: The number of rows in the exposure prior dataframe does not match the number of time points in the study
    +## Warning in addExposurePrior_checkempirical(exp_prior, T_max): Warning: The number of rows in the exposure prior dataframe does not match the number of time points in the study
    +
    ## There are individuals which have exposure before their first bleed or before their last bleed, ids:  19, 23, 45, 92, 95, 147, 162, 205, 218, 6, 18, 24, 30, 63, 98, 142, 181, 192, 199, 208, 210, 214, 215, 245, 246, 254, 265 . It is hard to perform inference on these people, so we recommend you remove the exposures from the known inf, but, if included, the model ignores these exposures.

    Step 4B: Prerun sanity plots @@ -275,36 +279,19 @@

    Step 4B: Prerun sanity plots
    +
     p1 <- plotSero(model_w2)
     p2 <- plotPriorPredictive(model_w2)
     p3 <- plotPriorInfection(model_w2)
     p1 / p2
    -

    -
    +

    +
     p3
    -

    +

    Step 5: Define the Complete Model

    -
    -rj_settings <- list(
    -        numberChainRuns = 4, 
    -        iterations = 200000,
    -        burninPosterior = 100000,
    -        thin = 100
    -    )
    -
    -save_info <- list(
    -    file_name = "transvir_data",
    -    model_name = "wave2_p1"
    -)
    -
    -#model_summary_p1_2 <- runSeroJump(model_w2, rj_settings, save_info = save_info)
    -
    -#plotMCMCDiagnosis(model_summary_p1_2, save_info = save_info)
    -#plotPostFigs(model_summary_p1_2, save_info = save_info)

    Step 5B: Prerun sanity plots @@ -383,21 +372,23 @@

    Step 5B: Prerun sanity plots
    +
     p1 <- plotSero(model_w3)
     p2 <- plotPriorPredictive(model_w3)
     p3 <- plotPriorInfection(model_w3)
     p1 / p2
    -

    -
    -p3
    -

    +

    +p3
    +

    +
     rj_settings <- list(
             numberChainRuns = 4, 
             iterations = 200000,
             burninPosterior = 100000,
             thin = 100
    +       # onDebug = TRUE, 
    +       # runParallel = FALSE
         )
     
     save_info_w2 <- list(
    @@ -410,6 +401,8 @@ 

    Step 5B: Prerun sanity plots= "wave_3_non" ) + + # Run these but take a while #model_summary_w2 <- runSeroJump(model_w2, rj_settings, save_info = save_info_w2) #model_summary_w3 <- runSeroJump(model_w3, rj_settings, save_info = save_info_w3) diff --git a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-5-1.png similarity index 100% rename from docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-5-1.png rename to docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-5-1.png diff --git a/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-5-2.png new file mode 100644 index 00000000..0dc1b4c6 Binary files /dev/null and b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-5-2.png differ diff --git a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-7-1.png similarity index 100% rename from docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-8-1.png rename to docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-7-1.png diff --git a/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-7-2.png b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-7-2.png new file mode 100644 index 00000000..d83490d0 Binary files /dev/null and b/docs/articles/cs2_sarscov2 copy_files/figure-html/unnamed-chunk-7-2.png differ diff --git a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-5-2.png deleted file mode 100644 index e1e23b0b..00000000 Binary files a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-5-2.png and /dev/null differ diff --git a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-8-2.png b/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-8-2.png deleted file mode 100644 index c548b202..00000000 Binary files a/docs/articles/cs2_sarscov2_files/figure-html/unnamed-chunk-8-2.png and /dev/null differ diff --git a/docs/articles/data_format.html b/docs/articles/data_format.html index fac01c39..9829b620 100644 --- a/docs/articles/data_format.html +++ b/docs/articles/data_format.html @@ -52,7 +52,7 @@ Case Study 1: Simulation Recovery

  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files @@ -80,7 +80,7 @@

    Intro 1: Data format for input files

    David Hodgson

    -

    2024-10-23

    +

    2024-10-24

    diff --git a/docs/articles/index.html b/docs/articles/index.html index bd0947fe..fe92ca54 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files @@ -62,7 +62,7 @@

    All vignettes

    Case Study 1: Simulation Recovery
    -
    Case Study 2: SARS-CoV-2 inference in The Gambia
    +
    Case Study 2: SARS-CoV-2 inference in The Gambia
    Intro 1: Data format for input files
    diff --git a/docs/articles/model_define.html b/docs/articles/model_define.html index 5d4151ac..c27fe27e 100644 --- a/docs/articles/model_define.html +++ b/docs/articles/model_define.html @@ -52,7 +52,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files @@ -81,7 +81,7 @@

    Intro 2: Explanation of observational and

    David Hodgson

    -

    2024-10-23

    +

    2024-10-24

    @@ -363,8 +363,8 @@

    Step 1: Define the First seroModel <- createSeroJumpModel( - data_sero = data_sero, - data_known = NULL, + data_sero = data_sero, + data_known = NULL, biomarkers = biomarkers, exposureTypes = exposureTypes, exposureFitted = exposureFitted, diff --git a/docs/authors.html b/docs/authors.html index 7fa6de86..442e5f7c 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery

  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/index.html b/docs/index.html index 0bad9dfa..f5f7cd27 100644 --- a/docs/index.html +++ b/docs/index.html @@ -53,7 +53,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 4dfd7424..701db27a 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: cs1_sim_recovery: cs1_sim_recovery.html - cs2_sarscov2: cs2_sarscov2.html + cs2_sarscov2 copy: cs2_sarscov2 copy.html data_format: data_format.html model_define: model_define.html -last_built: 2024-10-23T11:20Z +last_built: 2024-10-24T10:28Z diff --git a/docs/reference/abkineticsFunction.html b/docs/reference/abkineticsFunction.html index 272fa7da..5584b168 100644 --- a/docs/reference/abkineticsFunction.html +++ b/docs/reference/abkineticsFunction.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/abkineticsModel.html b/docs/reference/abkineticsModel.html index cb630e39..fb5cc803 100644 --- a/docs/reference/abkineticsModel.html +++ b/docs/reference/abkineticsModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/addAbkineticsModel.html b/docs/reference/addAbkineticsModel.html index 76a364e5..bb397b4b 100644 --- a/docs/reference/addAbkineticsModel.html +++ b/docs/reference/addAbkineticsModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/addCopModel.html b/docs/reference/addCopModel.html index c17a3d73..d6464ee5 100644 --- a/docs/reference/addCopModel.html +++ b/docs/reference/addCopModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/addExposurePrior.html b/docs/reference/addExposurePrior.html index ad488aae..bda0954c 100644 --- a/docs/reference/addExposurePrior.html +++ b/docs/reference/addExposurePrior.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/addObservationalModel.html b/docs/reference/addObservationalModel.html index 73777db2..3cf8382b 100644 --- a/docs/reference/addObservationalModel.html +++ b/docs/reference/addObservationalModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/addPrior.html b/docs/reference/addPrior.html index 89efa419..5a18a0b6 100644 --- a/docs/reference/addPrior.html +++ b/docs/reference/addPrior.html @@ -43,7 +43,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/check_exposures_times.html b/docs/reference/check_exposures_times.html index b12abc09..d70c3ca3 100644 --- a/docs/reference/check_exposures_times.html +++ b/docs/reference/check_exposures_times.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/check_input_data.html b/docs/reference/check_input_data.html index 52129fdb..ea0b31f4 100644 --- a/docs/reference/check_input_data.html +++ b/docs/reference/check_input_data.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/check_sero_no_single_entries.html b/docs/reference/check_sero_no_single_entries.html index 9c50c43d..d669e5eb 100644 --- a/docs/reference/check_sero_no_single_entries.html +++ b/docs/reference/check_sero_no_single_entries.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/check_sero_timings.html b/docs/reference/check_sero_timings.html index 977a8952..6673927a 100644 --- a/docs/reference/check_sero_timings.html +++ b/docs/reference/check_sero_timings.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/copLogLikelihood.html b/docs/reference/copLogLikelihood.html index 5cfec526..9c060a12 100644 --- a/docs/reference/copLogLikelihood.html +++ b/docs/reference/copLogLikelihood.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/createSeroJumpModel.html b/docs/reference/createSeroJumpModel.html index 1040dd66..b105b81d 100644 --- a/docs/reference/createSeroJumpModel.html +++ b/docs/reference/createSeroJumpModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/data_known_exposures_ex1.html b/docs/reference/data_known_exposures_ex1.html index d06d223c..4614275f 100644 --- a/docs/reference/data_known_exposures_ex1.html +++ b/docs/reference/data_known_exposures_ex1.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/data_titre_ex.html b/docs/reference/data_titre_ex.html index 6c05c6be..eaca4e16 100644 --- a/docs/reference/data_titre_ex.html +++ b/docs/reference/data_titre_ex.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/index.html b/docs/reference/index.html index 218025ab..3f99f21d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/makeModel.html b/docs/reference/makeModel.html index 166bb349..77557db1 100644 --- a/docs/reference/makeModel.html +++ b/docs/reference/makeModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/obsLogLikelihood.html b/docs/reference/obsLogLikelihood.html index 3b85559d..868b4ebc 100644 --- a/docs/reference/obsLogLikelihood.html +++ b/docs/reference/obsLogLikelihood.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/observationalModel.html b/docs/reference/observationalModel.html index 4080561e..06d0d8a7 100644 --- a/docs/reference/observationalModel.html +++ b/docs/reference/observationalModel.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotMCMCDiagnosis.html b/docs/reference/plotMCMCDiagnosis.html index a0c4ad10..79166433 100644 --- a/docs/reference/plotMCMCDiagnosis.html +++ b/docs/reference/plotMCMCDiagnosis.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotPostFigs.html b/docs/reference/plotPostFigs.html index 349c9d17..4dda1614 100644 --- a/docs/reference/plotPostFigs.html +++ b/docs/reference/plotPostFigs.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotPostFigsSim.html b/docs/reference/plotPostFigsSim.html index 4ccbba78..53d343c9 100644 --- a/docs/reference/plotPostFigsSim.html +++ b/docs/reference/plotPostFigsSim.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotPriorInfection.html b/docs/reference/plotPriorInfection.html index 3b37f4fe..a2240850 100644 --- a/docs/reference/plotPriorInfection.html +++ b/docs/reference/plotPriorInfection.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotPriorPredictive.html b/docs/reference/plotPriorPredictive.html index d8214c6c..126671ef 100644 --- a/docs/reference/plotPriorPredictive.html +++ b/docs/reference/plotPriorPredictive.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/plotSero.html b/docs/reference/plotSero.html index 7fe30f6f..84f073ad 100644 --- a/docs/reference/plotSero.html +++ b/docs/reference/plotSero.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/rjmc_sero_func.html b/docs/reference/rjmc_sero_func.html index 1404a0dc..0ab9c65d 100644 --- a/docs/reference/rjmc_sero_func.html +++ b/docs/reference/rjmc_sero_func.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/reference/runSeroJump.html b/docs/reference/runSeroJump.html index c0f26810..809ab58f 100644 --- a/docs/reference/runSeroJump.html +++ b/docs/reference/runSeroJump.html @@ -35,7 +35,7 @@ Case Study 1: Simulation Recovery
  • - Case Study 2: SARS-CoV-2 inference in The Gambia + Case Study 2: SARS-CoV-2 inference in The Gambia
  • Intro 1: Data format for input files diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 162607cc..b904ed92 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,7 +2,7 @@ /404.html /LICENSE.html /articles/cs1_sim_recovery.html -/articles/cs2_sarscov2.html +/articles/cs2_sarscov2 copy.html /articles/data_format.html /articles/index.html /articles/model_define.html diff --git a/outputs/.DS_Store b/outputs/.DS_Store index fd76cf38..03b0346a 100644 Binary files a/outputs/.DS_Store and b/outputs/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store index 7aad3318..4e0eb8ee 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/RcppExports.o b/src/RcppExports.o index 224e8435..86917bee 100644 Binary files a/src/RcppExports.o and b/src/RcppExports.o differ diff --git a/vignettes/.DS_Store b/vignettes/.DS_Store deleted file mode 100644 index 102d5f64..00000000 Binary files a/vignettes/.DS_Store and /dev/null differ diff --git a/vignettes/cs2_sarscov2 copy.Rmd b/vignettes/cs2_sarscov2.Rmd similarity index 93% rename from vignettes/cs2_sarscov2 copy.Rmd rename to vignettes/cs2_sarscov2.Rmd index 87e6f863..2e436974 100644 --- a/vignettes/cs2_sarscov2 copy.Rmd +++ b/vignettes/cs2_sarscov2.Rmd @@ -23,8 +23,8 @@ library(devtools) library(tidyr) library(dplyr) library(magrittr) -#library(serojump) -devtools::load_all() +library(serojump) +#devtools::load_all() library(patchwork) @@ -46,8 +46,8 @@ This data has been generated using `serosim`. ```{r} -#wave_full <- readRDS(file = "wave2_export.RDS") -wave_full <- readRDS(file = "./vignettes/wave2_export.RDS") +wave_full <- readRDS(file = "wave2_export.RDS") +#wave_full <- readRDS(file = "./vignettes/wave2_export.RDS") sero_data_w2 <- wave_full$sero_data known_inf_w2 <- wave_full$known_inf @@ -58,8 +58,8 @@ check_sero_no_single_entries(sero_data_w2) check_sero_timings(sero_data_w2) -#wave_full <- readRDS(file = "wave3_export.RDS") -wave_full <- readRDS(file = "./vignettes/wave3_export.RDS") +wave_full <- readRDS(file = "wave3_export.RDS") +#wave_full <- readRDS(file = "./vignettes/wave3_export.RDS") sero_data_w3 <- wave_full$sero_data known_inf_w3 <- wave_full$known_inf @@ -315,19 +315,19 @@ save_info_w3 <- list( # Run these but take a while -model_summary_w2 <- runSeroJump(model_w2, rj_settings, save_info = save_info_w2) -model_summary_w3 <- runSeroJump(model_w3, rj_settings, save_info = save_info_w3) +#model_summary_w2 <- runSeroJump(model_w2, rj_settings, save_info = save_info_w2) +#model_summary_w3 <- runSeroJump(model_w3, rj_settings, save_info = save_info_w3) -#model_summary_w2 <- readRDS("model_summary_w2.RDS") -#model_summary_w3 <- readRDS("model_summary_w3.RDS") +model_summary_w2 <- readRDS("model_summary_w2.RDS") +model_summary_w3 <- readRDS("model_summary_w3.RDS") plotMCMCDiagnosis(model_summary_w2, save_info = save_info_w2) # takes ages to run these so comment out! -plotPostFigs(model_summary_w2, save_info = save_info_w2) +#plotPostFigs(model_summary_w2, save_info = save_info_w2) plotMCMCDiagnosis(model_summary_w3, save_info = save_info_w3) # takes ages to run these so comment out! -plotPostFigs(model_summary_w3, save_info = save_info_w3) +#plotPostFigs(model_summary_w3, save_info = save_info_w3) ``` \ No newline at end of file diff --git a/vignettes/model_define.Rmd b/vignettes/model_define.Rmd index 86282e0a..4a207f7c 100644 --- a/vignettes/model_define.Rmd +++ b/vignettes/model_define.Rmd @@ -207,8 +207,8 @@ attack_rate_data <- data.frame( seroModel <- createSeroJumpModel( - data_sero = data_sero, - data_known = NULL, + data_sero = data_sero, + data_known = NULL, biomarkers = biomarkers, exposureTypes = exposureTypes, exposureFitted = exposureFitted, diff --git a/vignettes/model_summary_w2.RDS b/vignettes/model_summary_w2.RDS index 327beb56..e7cbac82 100644 Binary files a/vignettes/model_summary_w2.RDS and b/vignettes/model_summary_w2.RDS differ diff --git a/vignettes/model_summary_w3.RDS b/vignettes/model_summary_w3.RDS index 3b69f5e7..9a572c6b 100644 Binary files a/vignettes/model_summary_w3.RDS and b/vignettes/model_summary_w3.RDS differ diff --git a/vignettes/play_transvir.Rmd b/vignettes/play_transvir.Rmd deleted file mode 100644 index 15a3d53f..00000000 --- a/vignettes/play_transvir.Rmd +++ /dev/null @@ -1,388 +0,0 @@ ---- -title: "Case Study 2: SARS-CoV-2 inference in The Gambia" -author: "David Hodgson" -date: "`r Sys.Date()`" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Case Study 2: SARS-CoV-2 inference in The Gambia} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - - -# R Code Description - -This document describes the steps and components of the provided R code for creating and running serological models using simulated data. The code defines observational models, antibody kinetics models, and runs inference using MCMC methods. - ---- - -## Step 1: Load Required Libraries -```{r, message=FALSE, warning=FALSE, results='hide'} - -library(devtools) -library(tidyr) - -library(dplyr) -library(magrittr) -library(serojump) -#devtools::load_all() -library(patchwork) - - -# Using more than one core might fail on windows, -if (.Platform$OS.type == "windows") { - mc.cores <- 1 -}else { - mc.cores <- 2 -} # use as many as available, preferably 4.} - - - -``` - -## Step 2: Read Simulated Data - -This data has been generated using `serosim`. - -```{r} - - -wave_full <- readRDS(file = "./vignettes/wave2_export.RDS") - -sero_data_w2 <- wave_full$sero_data -known_inf_w2 <- wave_full$known_inf -inf_prior_w2 <- wave_full$inf_prior - -# Check the entries are sensible -check_sero_no_single_entries(sero_data_w2) -check_sero_timings(sero_data_w2) - - -wave_full <- readRDS(file = "./vignettes/wave3_export.RDS") - -sero_data_w3 <- wave_full$sero_data -known_inf_w3 <- wave_full$known_inf -inf_prior_w3 <- wave_full$inf_prior - -# Check the entries are sensible -check_sero_no_single_entries(sero_data_w3) -check_sero_timings(sero_data_w3) - -#known_inf_w2 <- known_inf_w2_check %>% filter(key_exposure == "inferrable") - -``` - -## Step 3: Define Likelihood and Kinetics Functions - -```{r} - -obsLogLikelihood <- function(titre_val, titre_est, pars) { - ll <- dnorm(titre_val, titre_est, pars[1], log = TRUE) -} - -noInfSerumKinetics <- function(titre_est, timeSince, pars) { - titre_est_log <- titre_est - (pars[1] * titre_est) * (timeSince) - titre_est_log <- max(0, titre_est_log) - titre_est_log -} - - -infTuenisPower2016 <- function(titre_est, timeSince, pars) { - - y1 <- pars[1] - t1 <- pars[2] - r <- pars[3] - alpha <- pars[4] - - v <- 0.001 - mu <- 1 / t1 * y1 - - if (timeSince < t1) { - titre_est_boost <- exp(mu * timeSince) - } else { - titre_est_boost <- exp(y1) * (1 + (r - 1) * exp(y1)^{r - 1} * v * (timeSince - t1)) ^ {-1 / (r - 1)} - } - - titre_est_log <- titre_est + log(titre_est_boost) * max(0, 1 - titre_est * alpha) - titre_est_log -} - -``` - -## Step 4: Define the Observational and Kinetics Models - -```{r} - - - -# Define the biomarkers and exposure types in the model -biomarkers <- c("spike", "NCP") -exposureTypes <- c("none", "delta", "vax", "predelta") -exposureFitted <- "delta" - -# Define the observational model -observationalModel <- list( - names = c("spike", "NCP"), - model = makeModel( - addObservationalModel("spike", c("sigma"), obsLogLikelihood), - addObservationalModel("NCP", c("sigma_a"), obsLogLikelihood)), - prior = bind_rows( - addPrior("sigma", 0.0001, 2, "exp", 1, NA), - addPrior("sigma_a", 0.0001, 2, "exp", 1, NA) - ) # observational model, -) - -# Define the antibody kinetics model -abkineticsModel <- list( - model = makeModel( - addAbkineticsModel("none_s", "spike", "none", c("wane"), noInfSerumKinetics), - addAbkineticsModel("delta_s", "spike", "delta", c("y1_d", "t1_d", "r_d", "s"), infTuenisPower2016), - addAbkineticsModel("vax_s", "spike", "vax", c("y1_vax", "t1_vax", "r_vax", "s"), infTuenisPower2016), - addAbkineticsModel("predelta_s", "spike", "predelta", c("y1_pd", "t1_pd", "r_pd", "s"), infTuenisPower2016), - addAbkineticsModel("none_ncp", "NCP", "none", c("wane_a"), noInfSerumKinetics), - addAbkineticsModel("delta_ncp", "NCP", "delta", c("y1_d_a", "t1_d_a", "r_d_a", "s_a"), infTuenisPower2016), - addAbkineticsModel("vax_ncp", "NCP", "vax", c("y1_vax_a", "t1_vax_a", "r_vax_a", "s_a"), infTuenisPower2016), - addAbkineticsModel("predelta_ncp", "NCP", "predelta", c("y1_pd_a", "t1_pd_a", "r_pd_a", "s_a"), infTuenisPower2016) - ), - prior = bind_rows( - addPrior("y1_d", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_d", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_d", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_vax", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_vax", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_vax", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_pd", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_pd", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_pd", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("s", 0, 1, "unif", 0, 1), # ab kinetics - addPrior("wane", 0.0, 0.01, "unif", 0.0, 0.01), # observational model - addPrior("y1_d_a", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_d_a", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_d_a", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_vax_a", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_vax_a", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_vax_a", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_pd_a", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_pd_a", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_pd_a", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("s_a", 0, 1, "unif", 0, 1), # ab kinetics - addPrior("wane_a", 0.0, 0.01, "unif", 0.0, 0.01) # observational model - ) -) - - - -model_w2 <- createSeroJumpModel( - data_sero = sero_data_w2, - data_known = known_inf_w2, - biomarkers = biomarkers, - exposureTypes = exposureTypes, - exposureFitted = exposureFitted, - observationalModel = observationalModel, - abkineticsModel = abkineticsModel, - exposurePriorTime = inf_prior_w2, - exposurePriorTimeType = "empirical" -) - - - - -``` - - -## Step 4B: Prerun sanity plots - -Before running the whole model it is good to check the data and the priors. This can be done using a suit of functions `plotPriors` function. - -```{r} - -p1 <- plotSero(model_w2) -p2 <- plotPriorPredictive(model_w2) -p3 <- plotPriorInfection(model_w2) -p1 / p2 -p3 - -``` - -## Step 5: Define the Complete Model - - - -```{r} - - -rj_settings <- list( - numberChainRuns = 4, - iterations = 200000, - burninPosterior = 100000, - thin = 100 - ) - -save_info <- list( - file_name = "transvir_data", - model_name = "wave2_p1" -) - -#model_summary_p1_2 <- runSeroJump(model_w2, rj_settings, save_info = save_info) - -#plotMCMCDiagnosis(model_summary_p1_2, save_info = save_info) -#plotPostFigs(model_summary_p1_2, save_info = save_info) - - - -``` - - -```{r} - - -# Define the biomarkers and exposure types in the model -biomarkers <- c("spike", "NCP") -exposureTypes <- c("none", "omicron", "vax") -exposureFitted <- "omicron" - -# Define the observational model -observationalModel <- list( - names = c("spike", "NCP"), - model = makeModel( - addObservationalModel("spike", c("sigma"), obsLogLikelihood), - addObservationalModel("NCP", c("sigma_a"), obsLogLikelihood)), - - prior = bind_rows( - addPrior("sigma", 0.0001, 2, "exp", 1, NA), - addPrior("sigma_a", 0.0001, 2, "exp", 1, NA) - ) # observational model, -) - -# Define the antibody kinetics model -abkineticsModel <- list( - model = makeModel( - addAbkineticsModel("none_s", "spike", "none", c("wane"), noInfSerumKinetics), - addAbkineticsModel("omicron_s", "spike", "omicron", c("y1_o", "t1_o", "r_o", "s"), infTuenisPower2016), - addAbkineticsModel("vax_s", "spike", "vax", c("y1_vax", "t1_vax", "r_vax", "s"), infTuenisPower2016), - addAbkineticsModel("none_ncp", "NCP", "none", c("wane_a"), noInfSerumKinetics), - addAbkineticsModel("omicron_ncp", "NCP", "omicron", c("y1_o_a", "t1_o_a", "r_o_a", "s_a"), infTuenisPower2016), - addAbkineticsModel("vax_ncp", "NCP", "vax", c("y1_vax_a", "t1_vax_a", "r_vax_a", "s_a"), infTuenisPower2016) - ), - prior = bind_rows( - addPrior("y1_o", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_o", 7, 21,"unif", 7, 21), # ab kinetics - addPrior("r_o", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_vax", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_vax", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_vax", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("s", 0, 1, "unif", 0, 1), # ab kinetics - addPrior("wane", 0.0, 0.01, "unif", 0.0, 0.01), # observational model - addPrior("y1_o_a", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_o_a", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_o_a", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("y1_vax_a", 0, 6, "unif", 0, 6), # ab kinetics - addPrior("t1_vax_a", 7, 21, "unif", 7, 21), # ab kinetics - addPrior("r_vax_a", 1, 5, "unif", 1, 5), # ab kinetics - addPrior("s_a", 0, 1, "unif", 0, 1), # ab kinetics - addPrior("wane_a", 0.0, 0.01, "unif", 0.0, 0.01) # observational model - ) -) - - -model_w3 <- createSeroJumpModel( - data_sero = sero_data_w3, - data_known = known_inf_w3, - biomarkers = biomarkers, - exposureTypes = exposureTypes, - exposureFitted = exposureFitted, - observationalModel = observationalModel, - abkineticsModel = abkineticsModel, - exposurePriorTime = inf_prior_w3, - exposurePriorTimeType = "empirical" -) - - -``` - -## Step 5B: Prerun sanity plots - -Before running the whole model it is good to check the data and the priors. This can be done using a suit of functions `plotPriors` function. - -```{r} - -p1 <- plotSero(model_w3) -p2 <- plotPriorPredictive(model_w3) -p3 <- plotPriorInfection(model_w3) -p1 / p2 -p3 - -``` - -```{r, message=FALSE, warning=FALSE, results='hide'} - - -rj_settings <- list( - numberChainRuns = 4, - iterations = 200000, - burninPosterior = 100000, - thin = 100 - ) - -save_info_w2 <- list( - file_name = "transvir_data", - model_name = "wave_2_non" -) - -save_info_w3 <- list( - file_name = "transvir_data", - model_name = "wave_3_non" -) - -# Run these but take a while -#model_summary_w2 <- runSeroJump(model_w2, rj_settings, save_info = save_info_w2) -#model_summary_w3 <- runSeroJump(model_w3, rj_settings, save_info = save_info_w3) - - -model_summary_w2 <- readRDS("./vignettes/model_summary_w2.RDS") -model_summary_w3 <- readRDS("./vignettes/model_summary_w3.RDS") - -plotMCMCDiagnosis(model_summary_w2, save_info = save_info_w2) -# takes ages to run these so comment out! -#plotPostFigs(model_summary_w2, save_info = save_info_w2) - -plotMCMCDiagnosis(model_summary_w3, save_info = save_info_w3) -# takes ages to run these so comment out! -#plotPostFigs(model_summary_w3, save_info = save_info_w3) - -``` - - -```{R} - -# Check out number 5 - -model_summary_w3$post$fit_states %>% filter(id == 5) -model_summary_w3$post$fit_obs %>% filter(id == 5) %>% head - -model_summary_w3$fit$data_t$titre_list[[5]] -model_summary_w3$fit$model$infoModel$exposureInfo[[3]]$known_inf[5] -model_summary_w3$fit$data_t$raw_exp - -model_summary_w3$fit$data_t$N -model_summary_w3$fit$data_t$exp_prior -model_summary_w3$fit$data_t$exp_list[[5]] - -# Does exp_list line up? -model_summary_w3$post$fit_states %>% filter(id == 1) -model_summary_w3$post$fit_obs %>% filter(id == 1) %>% head # 1 and 185 -model_summary_w3$fit$data_t$exp_list[[2]] -model_summary_w3$fit$data_t$times_list[[1]] -model_summary_w3$fit$data_t$initialTitreTime[1] -model_summary_w3$fit$data_t$endTitreTime[1] - - - -model_w2$data$exp_list %>% map(~sum(.)) %>% unlist - -model_w2$data$exp_list[[11]] - - -model_w2$data$raw_exp - -```` \ No newline at end of file