From 6247111f4fe04b9a2a55f891ab5da7952591b5dc Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 14 Mar 2024 17:46:33 -0700 Subject: [PATCH] Draft paper --- .Rproj.user/BAB4038F/pcs/files-pane.pper | 2 +- .Rproj.user/BAB4038F/pcs/source-pane.pper | 2 +- .../BAB4038F/pcs/windowlayoutstate.pper | 4 +- .Rproj.user/BAB4038F/pcs/workbench-pane.pper | 2 +- .Rproj.user/BAB4038F/sources/prop/INDEX | 36 ++ NAMESPACE | 93 +++--- R/{alpha2mu-base.R => Fmu-base.R} | 6 +- R/{alpha2mu-chronic.R => Fmu-chronic.R} | 6 +- R/{alpha2mu-immune.R => Fmu-immune.R} | 6 +- R/{alpha2mu-interface.R => Fmu-interface.R} | 8 +- R/{moi.R => MMinfinity.R} | 22 -- R/{modified_beta.R => Omega-beta.R} | 109 ++++++- R/Omega-interface.R | 56 ++++ R/{blood_volume.R => RBC.R} | 0 R/alpha2density.R | 40 +-- R/aoi.R | 6 + R/aoy.R | 4 +- R/cohort_detect.R | 119 ------- R/convolve.R | 12 +- R/{cohort_counts.R => counts.R} | 168 +++++----- ...ort_parasites_clones.R => density_clone.R} | 50 +-- ...arasites_complex.R => density_parasites.R} | 74 ++--- R/detect_parasites.R | 99 ++++++ R/detection-interface.R | 51 --- R/detection-nb.R | 77 ----- R/detection-pois.R | 78 ----- R/detection.R | 175 ++++++++++ R/dynamics.R | 21 -- R/infection_dynamics.R | 61 ++++ R/mu2density-beta.R | 78 ----- R/mu2density-interface.R | 56 ---- R/parasite_dens_simple.R | 46 --- R/prevalence.R | 17 - R/sample-interface.R | 99 ++++++ R/sample-nb.R | 47 +++ R/sample-pois.R | 43 +++ _pkgdown.yml | 133 ++++---- docs/404.html | 1 + docs/articles/Dynamics.html | 3 +- docs/articles/MoI.html | 273 +++++++++------- .../figure-html/unnamed-chunk-6-1.png | Bin 27354 -> 31786 bytes .../figure-html/unnamed-chunk-8-1.png | Bin 114208 -> 31786 bytes docs/articles/index.html | 3 + docs/articles/plotCounts.html | 13 +- docs/authors.html | 1 + docs/index.html | 13 +- docs/pkgdown.yml | 3 +- docs/reference/FoI.html | 1 + docs/reference/MoIDistPlot.html | 1 + docs/reference/Wda.delta.html | 1 + docs/reference/Wda.html | 1 + docs/reference/Wda.none.html | 1 + docs/reference/ageFoI.flat.html | 1 + docs/reference/ageFoI.html | 1 + docs/reference/ageFoI.type2.html | 1 + docs/reference/cdfConvolve2.html | 1 + docs/reference/cdfConvolve2a.html | 1 + docs/reference/cdfConvolve2b.html | 1 + docs/reference/dAoI.html | 1 + docs/reference/dAoIda.html | 1 + docs/reference/dAoY.html | 1 + docs/reference/dAoYN.html | 1 + docs/reference/dAoYda.html | 1 + docs/reference/dDensityPaConvolve2.html | 9 +- docs/reference/dMoIda.html | 1 + docs/reference/dbeta1.html | 1 + docs/reference/dmda.html | 1 + docs/reference/dpda.html | 1 + docs/reference/index.html | 308 ++++++++++-------- docs/reference/log10RBC.html | 1 + docs/reference/log10RBC.static.html | 1 + docs/reference/meanMoI.html | 5 +- docs/reference/momentAoI.html | 1 + docs/reference/momentAoY.html | 1 + docs/reference/nzPois.html | 1 + docs/reference/pAoI.html | 8 +- docs/reference/pAoY.html | 1 + docs/reference/pAoYN.html | 1 + docs/reference/pAoY_long.html | 1 + docs/reference/par_Wda_delta.html | 1 + docs/reference/par_Wda_none.html | 1 + docs/reference/par_expSeason.html | 1 + docs/reference/par_flatAge.html | 1 + docs/reference/par_flatSeason.html | 1 + docs/reference/par_flatTrend.html | 1 + docs/reference/par_lRBC_static.html | 1 + docs/reference/par_sigma_abc.html | 1 + docs/reference/par_sinSeason.html | 1 + docs/reference/par_type2Age.html | 1 + docs/reference/pbeta1.html | 1 + docs/reference/qbeta1.html | 1 + docs/reference/rAoI.html | 5 +- docs/reference/rAoY.html | 1 + docs/reference/rAoYN.html | 1 + docs/reference/rRda.html | 7 +- docs/reference/rbeta1.html | 1 + docs/reference/seasonalFoI.exp.html | 1 + docs/reference/seasonalFoI.flat.html | 1 + docs/reference/seasonalFoI.html | 1 + docs/reference/seasonalFoI.sin.html | 1 + docs/reference/solveMMinfty.html | 1 + docs/reference/solve_dAoI.html | 1 + docs/reference/solve_dAoYda.html | 1 + docs/reference/solve_dm.html | 1 + docs/reference/solve_dpda.html | 1 + docs/reference/trendFoI.flat.html | 1 + docs/reference/trendFoI.html | 1 + docs/reference/zda.html | 11 +- docs/search.json | 2 +- docs/sitemap.xml | 150 +++++++++ man/Detect.Rd | 21 -- man/Detect.nb.Rd | 21 -- man/Detect.pois.Rd | 21 -- man/FQ.Rd | 52 +++ man/{alpha2mu.Rd => Fmu.Rd} | 8 +- man/{alpha2mu.W.Rd => Fmu.W.Rd} | 8 +- man/{alpha2mu.base.Rd => Fmu.base.Rd} | 8 +- man/{alpha2mu.chronic.Rd => Fmu.chronic.Rd} | 8 +- man/MoIDistPlot.Rd | 2 +- man/binnedCounts.Rd | 23 -- man/binnedCounts.nb.Rd | 23 -- man/binnedCounts.pois.Rd | 23 -- man/dCounts.Rd | 23 -- man/dCounts.nb.Rd | 23 -- man/dCounts.pois.Rd | 23 -- man/dDensityPaConvolve2.Rd | 6 +- man/dMoIda.Rd | 2 +- man/d_Omega.Rd | 23 ++ man/d_Omega.beta.Rd | 24 ++ man/d_alpha2density.Rd | 6 +- man/{dCountsPa.Rd => d_clone_counts.Rd} | 18 +- man/{d_Pdensity.Rd => d_clone_density.Rd} | 32 +- man/{DetectPa.Rd => d_clone_detect.Rd} | 18 +- man/d_counts.Rd | 23 ++ man/d_counts.nb.Rd | 23 ++ man/d_counts.pois.Rd | 23 ++ man/d_detect.Rd | 21 ++ man/d_detect.nb.Rd | 21 ++ man/d_detect.pois.Rd | 21 ++ man/d_detect_mesh.Rd | 29 ++ man/{MoIPM.Rd => d_moi_count.Rd} | 35 +- man/d_mu2density.Rd | 23 -- man/d_mu2density.beta.Rd | 24 -- man/d_nz_counts_log.Rd | 23 ++ man/d_nz_counts_log_binned.Rd | 23 ++ man/{dCountsBa.Rd => d_parasite_counts.Rd} | 18 +- man/{d_Bdensity.Rd => d_parasite_density.Rd} | 16 +- man/{DetectBda.Rd => d_parasite_detect.Rd} | 40 ++- man/{DetectPM.Rd => d_parasite_detect_moi.Rd} | 35 +- man/dbeta1.Rd | 2 +- man/log10RBC.Rd | 2 +- man/log10RBC.static.Rd | 2 +- man/meanMoI.Rd | 4 +- man/{meanCountsPa.Rd => mean_clone_counts.Rd} | 18 +- ...eanCountsBa.Rd => mean_parasite_counts.Rd} | 18 +- ...t_Pdensity.Rd => moments_clone_density.Rd} | 14 +- ...density.Rd => moments_parasite_density.Rd} | 14 +- man/pAoI.Rd | 3 +- man/pCounts.Rd | 23 -- man/pCounts.nb.Rd | 23 -- man/pCounts.pois.Rd | 23 -- man/{p_mu2density.Rd => p_Omega.Rd} | 12 +- man/{p_mu2density.beta.Rd => p_Omega.beta.Rd} | 12 +- man/p_alpha2density.Rd | 6 +- man/{pCountsPa.Rd => p_clone_counts.Rd} | 18 +- man/p_counts.Rd | 23 ++ man/p_counts.nb.Rd | 23 ++ man/p_counts.pois.Rd | 23 ++ man/p_nz_counts_log.Rd | 23 ++ man/p_nz_counts_log_binned.Rd | 23 ++ man/{pCountsBa.Rd => p_parasite_counts.Rd} | 18 +- man/{p_Bdensity.Rd => p_parasite_density.Rd} | 18 +- man/par_Fmu_W.Rd | 6 +- man/par_Fmu_base.Rd | 6 +- man/par_Fmu_chronic.Rd | 6 +- ...{par_mu2dens_beta.Rd => par_Omega_beta.Rd} | 8 +- man/par_lRBC_static.Rd | 2 +- man/par_nb.Rd | 19 ++ man/par_nbCounts.Rd | 21 -- man/par_pois.Rd | 17 + man/par_poisCounts.Rd | 19 -- man/par_sigma_abc.Rd | 2 +- man/{Bdensity.Rd => parasite_density.Rd} | 16 +- man/pbeta1.Rd | 2 +- man/{q_mu2density.Rd => q_Omega.Rd} | 12 +- man/{q_mu2density.beta.Rd => q_Omega.beta.Rd} | 12 +- man/q_alpha2density.Rd | 6 +- man/qbeta1.Rd | 2 +- man/rAoI.Rd | 2 +- man/rRda.Rd | 8 +- man/r_Omega.Rd | 23 ++ man/r_Omega.beta.Rd | 24 ++ man/r_alpha2density.Rd | 6 +- man/r_mu2density.Rd | 23 -- man/r_mu2density.beta.Rd | 24 -- man/{r_Bdensity.Rd => r_parasite_density.Rd} | 14 +- man/rbeta1.Rd | 2 +- man/{salpha2mu.Rd => sFmu.Rd} | 8 +- man/sigma_mu.Rd | 2 +- man/sigma_mu.abc.Rd | 2 +- man/solveMMinfty.Rd | 2 +- man/{truePRa.Rd => truePR.Rd} | 10 +- man/zda.Rd | 6 +- vignettes/Dynamics.Rmd | 2 +- vignettes/Hybrid.Rmd | 6 +- vignettes/MoI.Rmd | 183 +++++++++++ vignettes/Parasite_Densities.Rmd | 56 ++-- 207 files changed, 2618 insertions(+), 1875 deletions(-) rename R/{alpha2mu-base.R => Fmu-base.R} (89%) rename R/{alpha2mu-chronic.R => Fmu-chronic.R} (83%) rename R/{alpha2mu-immune.R => Fmu-immune.R} (90%) rename R/{alpha2mu-interface.R => Fmu-interface.R} (80%) rename R/{moi.R => MMinfinity.R} (79%) rename R/{modified_beta.R => Omega-beta.R} (62%) create mode 100644 R/Omega-interface.R rename R/{blood_volume.R => RBC.R} (100%) delete mode 100644 R/cohort_detect.R rename R/{cohort_counts.R => counts.R} (53%) rename R/{cohort_parasites_clones.R => density_clone.R} (54%) rename R/{cohort_parasites_complex.R => density_parasites.R} (72%) create mode 100644 R/detect_parasites.R delete mode 100644 R/detection-interface.R delete mode 100644 R/detection-nb.R delete mode 100644 R/detection-pois.R create mode 100644 R/detection.R delete mode 100644 R/dynamics.R create mode 100644 R/infection_dynamics.R delete mode 100644 R/mu2density-beta.R delete mode 100644 R/mu2density-interface.R delete mode 100644 R/parasite_dens_simple.R delete mode 100644 R/prevalence.R create mode 100644 R/sample-interface.R create mode 100644 R/sample-nb.R create mode 100644 R/sample-pois.R delete mode 100644 man/Detect.Rd delete mode 100644 man/Detect.nb.Rd delete mode 100644 man/Detect.pois.Rd create mode 100644 man/FQ.Rd rename man/{alpha2mu.Rd => Fmu.Rd} (81%) rename man/{alpha2mu.W.Rd => Fmu.W.Rd} (77%) rename man/{alpha2mu.base.Rd => Fmu.base.Rd} (76%) rename man/{alpha2mu.chronic.Rd => Fmu.chronic.Rd} (74%) delete mode 100644 man/binnedCounts.Rd delete mode 100644 man/binnedCounts.nb.Rd delete mode 100644 man/binnedCounts.pois.Rd delete mode 100644 man/dCounts.Rd delete mode 100644 man/dCounts.nb.Rd delete mode 100644 man/dCounts.pois.Rd create mode 100644 man/d_Omega.Rd create mode 100644 man/d_Omega.beta.Rd rename man/{dCountsPa.Rd => d_clone_counts.Rd} (70%) rename man/{d_Pdensity.Rd => d_clone_density.Rd} (54%) rename man/{DetectPa.Rd => d_clone_detect.Rd} (67%) create mode 100644 man/d_counts.Rd create mode 100644 man/d_counts.nb.Rd create mode 100644 man/d_counts.pois.Rd create mode 100644 man/d_detect.Rd create mode 100644 man/d_detect.nb.Rd create mode 100644 man/d_detect.pois.Rd create mode 100644 man/d_detect_mesh.Rd rename man/{MoIPM.Rd => d_moi_count.Rd} (52%) delete mode 100644 man/d_mu2density.Rd delete mode 100644 man/d_mu2density.beta.Rd create mode 100644 man/d_nz_counts_log.Rd create mode 100644 man/d_nz_counts_log_binned.Rd rename man/{dCountsBa.Rd => d_parasite_counts.Rd} (70%) rename man/{d_Bdensity.Rd => d_parasite_density.Rd} (72%) rename man/{DetectBda.Rd => d_parasite_detect.Rd} (52%) rename man/{DetectPM.Rd => d_parasite_detect_moi.Rd} (50%) rename man/{meanCountsPa.Rd => mean_clone_counts.Rd} (65%) rename man/{meanCountsBa.Rd => mean_parasite_counts.Rd} (65%) rename man/{moment_Pdensity.Rd => moments_clone_density.Rd} (75%) rename man/{moment_Bdensity.Rd => moments_parasite_density.Rd} (75%) delete mode 100644 man/pCounts.Rd delete mode 100644 man/pCounts.nb.Rd delete mode 100644 man/pCounts.pois.Rd rename man/{p_mu2density.Rd => p_Omega.Rd} (66%) rename man/{p_mu2density.beta.Rd => p_Omega.beta.Rd} (62%) rename man/{pCountsPa.Rd => p_clone_counts.Rd} (71%) create mode 100644 man/p_counts.Rd create mode 100644 man/p_counts.nb.Rd create mode 100644 man/p_counts.pois.Rd create mode 100644 man/p_nz_counts_log.Rd create mode 100644 man/p_nz_counts_log_binned.Rd rename man/{pCountsBa.Rd => p_parasite_counts.Rd} (70%) rename man/{p_Bdensity.Rd => p_parasite_density.Rd} (62%) rename man/{par_mu2dens_beta.Rd => par_Omega_beta.Rd} (69%) create mode 100644 man/par_nb.Rd delete mode 100644 man/par_nbCounts.Rd create mode 100644 man/par_pois.Rd delete mode 100644 man/par_poisCounts.Rd rename man/{Bdensity.Rd => parasite_density.Rd} (75%) rename man/{q_mu2density.Rd => q_Omega.Rd} (64%) rename man/{q_mu2density.beta.Rd => q_Omega.beta.Rd} (60%) create mode 100644 man/r_Omega.Rd create mode 100644 man/r_Omega.beta.Rd delete mode 100644 man/r_mu2density.Rd delete mode 100644 man/r_mu2density.beta.Rd rename man/{r_Bdensity.Rd => r_parasite_density.Rd} (75%) rename man/{salpha2mu.Rd => sFmu.Rd} (81%) rename man/{truePRa.Rd => truePR.Rd} (69%) create mode 100644 vignettes/MoI.Rmd diff --git a/.Rproj.user/BAB4038F/pcs/files-pane.pper b/.Rproj.user/BAB4038F/pcs/files-pane.pper index ff84e24..66c0735 100644 --- a/.Rproj.user/BAB4038F/pcs/files-pane.pper +++ b/.Rproj.user/BAB4038F/pcs/files-pane.pper @@ -5,5 +5,5 @@ "ascending": true } ], - "path": "~/git/pf.memory/R" + "path": "~/git/pf.memory/vignettes" } \ No newline at end of file diff --git a/.Rproj.user/BAB4038F/pcs/source-pane.pper b/.Rproj.user/BAB4038F/pcs/source-pane.pper index 9e0db42..28a3c2e 100644 --- a/.Rproj.user/BAB4038F/pcs/source-pane.pper +++ b/.Rproj.user/BAB4038F/pcs/source-pane.pper @@ -1,3 +1,3 @@ { - "activeTab": 10 + "activeTab": 3 } \ No newline at end of file diff --git a/.Rproj.user/BAB4038F/pcs/windowlayoutstate.pper b/.Rproj.user/BAB4038F/pcs/windowlayoutstate.pper index f7dd6ea..16f05fc 100644 --- a/.Rproj.user/BAB4038F/pcs/windowlayoutstate.pper +++ b/.Rproj.user/BAB4038F/pcs/windowlayoutstate.pper @@ -1,12 +1,12 @@ { "left": { - "splitterpos": 457, + "splitterpos": 372, "topwindowstate": "NORMAL", "panelheight": 1172, "windowheight": 1210 }, "right": { - "splitterpos": 614, + "splitterpos": 385, "topwindowstate": "NORMAL", "panelheight": 1172, "windowheight": 1210 diff --git a/.Rproj.user/BAB4038F/pcs/workbench-pane.pper b/.Rproj.user/BAB4038F/pcs/workbench-pane.pper index 9fd6aca..c85befa 100644 --- a/.Rproj.user/BAB4038F/pcs/workbench-pane.pper +++ b/.Rproj.user/BAB4038F/pcs/workbench-pane.pper @@ -1,5 +1,5 @@ { "TabSet1": 1, - "TabSet2": 5, + "TabSet2": 0, "TabZoom": {} } \ No newline at end of file diff --git a/.Rproj.user/BAB4038F/sources/prop/INDEX b/.Rproj.user/BAB4038F/sources/prop/INDEX index 50533d0..036d775 100644 --- a/.Rproj.user/BAB4038F/sources/prop/INDEX +++ b/.Rproj.user/BAB4038F/sources/prop/INDEX @@ -4,6 +4,15 @@ ~%2Fgit%2Fmozy_ecology.R="24C7EAB6" ~%2Fgit%2Fpf.memory%2FDESCRIPTION="6683BFBF" ~%2Fgit%2Fpf.memory%2FNAMESPACE="534057AC" +~%2Fgit%2Fpf.memory%2FR%2FFmu-base.R="5BAA819E" +~%2Fgit%2Fpf.memory%2FR%2FFmu-chronic.R="36BCD81E" +~%2Fgit%2Fpf.memory%2FR%2FFmu-immune.R="B31465E0" +~%2Fgit%2Fpf.memory%2FR%2FFmu-interface.R="D32BC313" +~%2Fgit%2Fpf.memory%2FR%2FMMinfinity.R="B7C5F496" +~%2Fgit%2Fpf.memory%2FR%2FOmega-beta.R="A060A2F0" +~%2Fgit%2Fpf.memory%2FR%2FOmega-interface.R="5D88E9B4" +~%2Fgit%2Fpf.memory%2FR%2FRBC.R="71153DE9" +~%2Fgit%2Fpf.memory%2FR%2FTheta.R="57BD1419" ~%2Fgit%2Fpf.memory%2FR%2Falpha2density-beta.R="7B0E571F" ~%2Fgit%2Fpf.memory%2FR%2Falpha2density.R="7BF3E52A" ~%2Fgit%2Fpf.memory%2FR%2Falpha2mu-W.R="0615E065" @@ -17,13 +26,27 @@ ~%2Fgit%2Fpf.memory%2FR%2FaoyN.R="6F2904AF" ~%2Fgit%2Fpf.memory%2FR%2Fbeta.R="FBD39C0C" ~%2Fgit%2Fpf.memory%2FR%2Fblood_volume.R="CFD4D0B3" +~%2Fgit%2Fpf.memory%2FR%2Fclonal_counts.R="2ABD17C1" +~%2Fgit%2Fpf.memory%2FR%2Fclonal_densities.Rmd="1A7B5D93" +~%2Fgit%2Fpf.memory%2FR%2Fclonal_density.R="91FB5CE3" +~%2Fgit%2Fpf.memory%2FR%2Fclonal_detection.R="7644269F" +~%2Fgit%2Fpf.memory%2FR%2Fclone_counts.R="4BB8024B" +~%2Fgit%2Fpf.memory%2FR%2Fclone_density.R="B7D443C0" +~%2Fgit%2Fpf.memory%2FR%2Fclone_detection.R="746DA46A" ~%2Fgit%2Fpf.memory%2FR%2Fcohort_counts.R="44AB2D5D" ~%2Fgit%2Fpf.memory%2FR%2Fcohort_detect.R="80E3C356" ~%2Fgit%2Fpf.memory%2FR%2Fcohort_parasites_clones.R="D759A9B3" ~%2Fgit%2Fpf.memory%2FR%2Fcohort_parasites_complex.R="42884925" ~%2Fgit%2Fpf.memory%2FR%2Fcohort_parasites_simple.R="6C8EA019" ~%2Fgit%2Fpf.memory%2FR%2Fconvolve.R="912073C6" +~%2Fgit%2Fpf.memory%2FR%2Fcount_parasites.R="4B4677E9" ~%2Fgit%2Fpf.memory%2FR%2Fcounts.R="6DB6CAA1" +~%2Fgit%2Fpf.memory%2FR%2Fcounts_clone.R="47B7018F" +~%2Fgit%2Fpf.memory%2FR%2Fcounts_parasites.R="1C0FAD32" +~%2Fgit%2Fpf.memory%2FR%2Fdensity_clone.R="81AE25DE" +~%2Fgit%2Fpf.memory%2FR%2Fdensity_parasites.R="51C0BF39" +~%2Fgit%2Fpf.memory%2FR%2Fdetect_clone.R="DE4F2A82" +~%2Fgit%2Fpf.memory%2FR%2Fdetect_parasites.R="BDBFDDB0" ~%2Fgit%2Fpf.memory%2FR%2Fdetection-interface.R="6B78DF9F" ~%2Fgit%2Fpf.memory%2FR%2Fdetection-nb.R="8A490595" ~%2Fgit%2Fpf.memory%2FR%2Fdetection-pois.R="EAFCEBC2" @@ -38,30 +61,43 @@ ~%2Fgit%2Fpf.memory%2FR%2Fhost_cohorts.R="84C0B865" ~%2Fgit%2Fpf.memory%2FR%2Fhybrid.R="0E8F467C" ~%2Fgit%2Fpf.memory%2FR%2Fimmune_tracking.R="A048ED65" +~%2Fgit%2Fpf.memory%2FR%2Finfection_dynamics.R="E4269552" ~%2Fgit%2Fpf.memory%2FR%2Fmodified_beta.R="60B42952" ~%2Fgit%2Fpf.memory%2FR%2Fmoi.R="C75BDA96" ~%2Fgit%2Fpf.memory%2FR%2Fmu2density-beta.R="3D56436C" +~%2Fgit%2Fpf.memory%2FR%2Fmu2density-interface.R="D21B11A3" ~%2Fgit%2Fpf.memory%2FR%2Fmu2density.R="72434DC4" +~%2Fgit%2Fpf.memory%2FR%2Fomega-interface.R="3EC86BE4" ~%2Fgit%2Fpf.memory%2FR%2Fpar_dens_complex.R="DB0E72E9" ~%2Fgit%2Fpf.memory%2FR%2Fpar_dens_simple.R="D0F27E38" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_cohorts.R="6EB5B99B" +~%2Fgit%2Fpf.memory%2FR%2Fparasite_counts.R="D26138E7" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_dens_complex.R="328463D5" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_dens_simple.R="919ADC01" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_densities.R="2D02006A" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_densities_complex.R="A563775B" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_densities_simple.R="20F45A82" +~%2Fgit%2Fpf.memory%2FR%2Fparasite_density.R="9D367F2B" +~%2Fgit%2Fpf.memory%2FR%2Fparasite_detection.R="DC442C1E" ~%2Fgit%2Fpf.memory%2FR%2Fparasite_simple.R="09250A2A" ~%2Fgit%2Fpf.memory%2FR%2Fparasites_simple.R="DE5F9651" ~%2Fgit%2Fpf.memory%2FR%2Fpr.R="CB713F73" ~%2Fgit%2Fpf.memory%2FR%2Fpr.Rmd="1950C552" ~%2Fgit%2Fpf.memory%2FR%2Fprevalence.R="1B2C829C" ~%2Fgit%2Fpf.memory%2FR%2Frbc.R="55313469" +~%2Fgit%2Fpf.memory%2FR%2Fsample-interface.R="AED269A3" +~%2Fgit%2Fpf.memory%2FR%2Fsample-nb.R="74561104" +~%2Fgit%2Fpf.memory%2FR%2Fsample-pois.R="5D82C219" +~%2Fgit%2Fpf.memory%2FR%2Fsampling-interface.R="022079D8" +~%2Fgit%2Fpf.memory%2FR%2Fsampling-nb.R="E683D640" +~%2Fgit%2Fpf.memory%2FR%2Fsampling-pois.R="94A976BD" ~%2Fgit%2Fpf.memory%2FR%2Futils.R="016A8C62" ~%2Fgit%2Fpf.memory%2FREADME.Rmd="02662E0A" ~%2Fgit%2Fpf.memory%2FREADME.md="5CA253FF" ~%2Fgit%2Fpf.memory%2F_pkgdown.yml="33F34E18" ~%2Fgit%2Fpf.memory%2Fdocs%2Findex.html="6399C0D0" ~%2Fgit%2Fpf.memory%2Fdocs%2Freference%2Fout="B693E1D7" +~%2Fgit%2Fpf.memory%2Fman%2Fd_detect.Rd="4AA32B57" ~%2Fgit%2Fpf.memory%2Fman%2Fout="D565CA5D" ~%2Fgit%2Fpf.memory%2Fvignettes%2FAoI-Hybrid.Rmd="11869B4B" ~%2Fgit%2Fpf.memory%2Fvignettes%2FAoI.Rmd="35C9761C" diff --git a/NAMESPACE b/NAMESPACE index c8a8d5a..0dddd0d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,41 +1,34 @@ # Generated by roxygen2: do not edit by hand -S3method(Detect,nb) -S3method(Detect,pois) +S3method(Fmu,W) +S3method(Fmu,base) +S3method(Fmu,chronic) S3method(Wda,delta) S3method(Wda,none) S3method(ageFoI,flat) S3method(ageFoI,type2) -S3method(alpha2mu,W) -S3method(alpha2mu,base) -S3method(alpha2mu,chronic) -S3method(binnedCounts,nb) -S3method(binnedCounts,pois) -S3method(dCounts,nb) -S3method(dCounts,pois) -S3method(d_mu2density,beta) +S3method(d_Omega,beta) +S3method(d_counts,nb) +S3method(d_counts,pois) +S3method(d_detect,nb) +S3method(d_detect,pois) S3method(log10RBC,static) -S3method(pCounts,nb) -S3method(pCounts,pois) -S3method(p_mu2density,beta) -S3method(q_mu2density,beta) -S3method(r_mu2density,beta) +S3method(p_Omega,beta) +S3method(p_counts,nb) +S3method(p_counts,pois) +S3method(q_Omega,beta) +S3method(r_Omega,beta) S3method(seasonalFoI,exp) S3method(seasonalFoI,flat) S3method(seasonalFoI,sin) S3method(sigma_mu,abc) S3method(trendFoI,flat) -export(Bdensity) -export(Detect) -export(DetectBda) -export(DetectPM) +export(FQ) +export(Fmu) export(FoI) export(MoIDistPlot) -export(MoIPM) export(Wda) export(ageFoI) -export(alpha2mu) -export(binnedCounts) export(cdfConvolve2) export(cdfConvolve2a) export(cdfConvolve2b) @@ -44,40 +37,50 @@ export(dAoIda) export(dAoY) export(dAoYN) export(dAoYda) -export(dCounts) -export(dCountsBa) -export(dCountsPa) export(dDensityPaConvolve2) export(dMoIda) -export(d_Bdensity) -export(d_Pdensity) +export(d_Omega) export(d_alpha2density) -export(d_mu2density) +export(d_clone_counts) +export(d_clone_density) +export(d_counts) +export(d_detect) +export(d_detect_mesh) +export(d_moi_count) +export(d_nz_counts_log) +export(d_nz_counts_log_binned) +export(d_parasite_counts) +export(d_parasite_density) +export(d_parasite_detect) +export(d_parasite_detect_moi) export(dbeta1) export(dmda) export(dpda) export(log10RBC) -export(meanCountsBa) -export(meanCountsPa) export(meanMoI) +export(mean_clone_counts) +export(mean_parasite_counts) export(momentAoI) export(momentAoY) -export(moment_Bdensity) -export(moment_Pdensity) +export(moments_clone_density) +export(moments_parasite_density) export(nzPois) export(pAoI) export(pAoY) export(pAoYN) export(pAoY_long) -export(pCounts) -export(pCountsBa) -export(pCountsPa) -export(p_Bdensity) +export(p_Omega) export(p_alpha2density) -export(p_mu2density) +export(p_clone_counts) +export(p_counts) +export(p_nz_counts_log) +export(p_nz_counts_log_binned) +export(p_parasite_counts) +export(p_parasite_density) export(par_Fmu_W) export(par_Fmu_base) export(par_Fmu_chronic) +export(par_Omega_beta) export(par_Wda_delta) export(par_Wda_none) export(par_expSeason) @@ -85,25 +88,25 @@ export(par_flatAge) export(par_flatSeason) export(par_flatTrend) export(par_lRBC_static) -export(par_mu2dens_beta) -export(par_nbCounts) -export(par_poisCounts) +export(par_nb) +export(par_pois) export(par_sigma_abc) export(par_sinSeason) export(par_type2Age) +export(parasite_density) export(pbeta1) +export(q_Omega) export(q_alpha2density) -export(q_mu2density) export(qbeta1) export(rAoI) export(rAoY) export(rAoYN) export(rRda) -export(r_Bdensity) +export(r_Omega) export(r_alpha2density) -export(r_mu2density) +export(r_parasite_density) export(rbeta1) -export(salpha2mu) +export(sFmu) export(seasonalFoI) export(sigma_mu) export(solveMMinfty) @@ -112,5 +115,5 @@ export(solve_dAoYda) export(solve_dm) export(solve_dpda) export(trendFoI) -export(truePRa) +export(truePR) export(zda) diff --git a/R/alpha2mu-base.R b/R/Fmu-base.R similarity index 89% rename from R/alpha2mu-base.R rename to R/Fmu-base.R index cee1737..1378eb0 100644 --- a/R/alpha2mu-base.R +++ b/R/Fmu-base.R @@ -2,12 +2,12 @@ #' Compute expected log10 parasite densities, `mu`, as a function of the age of infection `alpha` #' @description Compute mean log10 parasites for a model with no immunity #' -#' @inheritParams alpha2mu +#' @inheritParams Fmu #' #' @return mean log10 parasite densities #' @export #' -alpha2mu.base = function(alpha, W, par_Fmu){with(par_Fmu,{ +Fmu.base = function(alpha, W, par_Fmu){with(par_Fmu,{ B = tildel + (tildeb-tildel)*exp(-(Sa*(alpha-peak))) ix = which(alpha0)) B[ix] = tildel+(tildeb-tildel)*alpha[ix]/peak @@ -16,7 +16,7 @@ alpha2mu.base = function(alpha, W, par_Fmu){with(par_Fmu,{ B })} -#' Set up parameters for [alpha2mu.base] +#' Set up parameters for [Fmu.base] #' #' @param peak The age of infection (in days) when parasite densities peak #' @param liver The age of infection (in days) when parasites emerge from the liver diff --git a/R/alpha2mu-chronic.R b/R/Fmu-chronic.R similarity index 83% rename from R/alpha2mu-chronic.R rename to R/Fmu-chronic.R index 43db3ff..f83197f 100644 --- a/R/alpha2mu-chronic.R +++ b/R/Fmu-chronic.R @@ -1,16 +1,16 @@ #' Compute expected log10 parasite densities, `mu`, as a function of the age of infection `alpha` #' @description Compute mean log10 parasites for a model with no immunity #' -#' @inheritParams alpha2mu +#' @inheritParams Fmu #' #' @return mean log10 parasite densities #' @export #' -alpha2mu.chronic = function(alpha, W, par_Fmu){with(par_Fmu,{ +Fmu.chronic = function(alpha, W, par_Fmu){with(par_Fmu,{ B = tildel + (tildeb-tildel)*exp(-(Sa*(alpha))) })} -#' Set up parameters for [alpha2mu.chronic] +#' Set up parameters for [Fmu.chronic] #' #' @param tildeb The maximum expected log10 parasite densities #' @param tildel The minimum expected log10 parasite densities diff --git a/R/alpha2mu-immune.R b/R/Fmu-immune.R similarity index 90% rename from R/alpha2mu-immune.R rename to R/Fmu-immune.R index d3ba75d..9638820 100644 --- a/R/alpha2mu-immune.R +++ b/R/Fmu-immune.R @@ -2,12 +2,12 @@ #' Compute expected log10 parasite densities, `mu`, as a function of the age of infection `alpha` #' @description Compute mean log10 parasites for a model with no immunity #' -#' @inheritParams alpha2mu +#' @inheritParams Fmu #' #' @return mean log10 parasite densities #' @export #' -alpha2mu.W = function(alpha, W, par_Fmu){with(par_Fmu,{ +Fmu.W = function(alpha, W, par_Fmu){with(par_Fmu,{ B = tildel + (tildeb-tildel)*exp(-Sa*(alpha-peak)-Sw*W) ix = which(alpha<=peak) if(length(ix>0)) B[ix] = tildel+(tildeb-tildel)*exp(-Sw*W)*alpha[ix]/peak @@ -16,7 +16,7 @@ alpha2mu.W = function(alpha, W, par_Fmu){with(par_Fmu,{ B })} -#' Set up parameters for [alpha2mu.W] +#' Set up parameters for [Fmu.W] #' #' @param peak The age of infection (in days) when parasite densities peak #' @param liver The age of infection (in days) when parasites emerge from the liver diff --git a/R/alpha2mu-interface.R b/R/Fmu-interface.R similarity index 80% rename from R/alpha2mu-interface.R rename to R/Fmu-interface.R index e7c62c2..71cba48 100644 --- a/R/alpha2mu-interface.R +++ b/R/Fmu-interface.R @@ -7,8 +7,8 @@ #' @return mean log10 parasite densities, a [numeric] vector of length(alpha) #' @export #' -alpha2mu = function(alpha, W, par_Fmu){ - UseMethod("alpha2mu", par_Fmu) +Fmu = function(alpha, W, par_Fmu){ + UseMethod("Fmu", par_Fmu) } #' Compute mean, expected parasite densities `mu` for multiple values of the age of infection `alpha` @@ -20,8 +20,8 @@ alpha2mu = function(alpha, W, par_Fmu){ #' @return mean log10 parasite densities, a [numeric] vector of length(alpha) #' @export #' -salpha2mu = function(alpha, W, par_Fmu){ - sapply(alpha, alpha2mu, W=W, par_Fmu=par_Fmu) +sFmu = function(alpha, W, par_Fmu){ + sapply(alpha, Fmu, W=W, par_Fmu=par_Fmu) } diff --git a/R/moi.R b/R/MMinfinity.R similarity index 79% rename from R/moi.R rename to R/MMinfinity.R index 4c7cc1d..c800f4f 100644 --- a/R/moi.R +++ b/R/MMinfinity.R @@ -1,24 +1,4 @@ -#' The mean MoI in a host cohort of age \eqn{a} -#' -#' @description -#' The mean multiplicity of infection (MoI) is \deqn{m_\tau(a) = \int_0^a z_\tau(\alpha, a) d \alpha} -#' -#' @inheritParams FoI -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' -#' @return a [numeric] vector of length(a) -#' @export -#' -meanMoI = function(a, FoIpar, tau=0, hhat=1, r=1/200){ - moif = function(a, FoIpar, tau, hhat,r){ - stats::integrate(zda, 0, a, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r)$value - } - if(length(a)==1){return(moif(a,FoIpar,tau,hhat,r))} else{ - (return(sapply(a,moif,FoIpar=FoIpar,tau=tau,hhat=hhat,r=r)))} -} - #' Derivatives for the queuing model \eqn{M/M/\infty} #' #' @description @@ -99,5 +79,3 @@ MoIDistPlot = function(moi, t, clr1 = "red"){ mm = 1:N -1 plot(mm, moi[t,1:N +1], type="h", xlab = "MoI", ylab = expression(M[tau](a)), main = paste ("Age = ", t, "Days")) } - - diff --git a/R/modified_beta.R b/R/Omega-beta.R similarity index 62% rename from R/modified_beta.R rename to R/Omega-beta.R index af77100..831faba 100644 --- a/R/modified_beta.R +++ b/R/Omega-beta.R @@ -1,4 +1,22 @@ +#' Modified beta distribution, density function +#' +#' @description +#' The beta distribution, parameterized by the mean and variance, modified to return +#' a number between 0 and bvm (the number of red blood cells) +#' +#' +#' @inheritParams d_Omega +#' +#' @return a [numeric] vector of length(xi) +#' @export +d_Omega.beta = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + with(par_Omega,{ + xi1 = xi/bvm + mu1 = mu/bvm + dbeta1(xi1, mu1, pSig)/bvm +})} + #' Density function for the beta distribution, an alternative parameterization #' @description @@ -19,6 +37,59 @@ dbeta1 = function(x, mu, stats::dbeta(x, mu*(mu*(1-mu)/var-1), (1-mu)*(mu*(1-mu)/var-1)) } +#' Modified beta distribution, random numbers +#' +#' @description +#' The beta distribution, parameterized by the mean and variance, modified to return +#' a number between 0 and bvm (the number of red blood cells) +#' +#' @inheritParams r_Omega +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +r_Omega.beta = function(n, mu, bvm=13, par_Omega=par_Omega_beta()){ + with(par_Omega,{ + mu1 = mu/bvm + rbeta1(n, mu1, pSig)*bvm +})} + + +#' The random generation function for the beta distribution, an alternative parameterization +#' Title +#' +#' @param n number of observations +#' @param mu the mean value for the distribution (0 <= mu <= 1) +#' @param pSig parameters to dispatch the S3 function [sigma_mu] +#' +#' @return a [numeric] vector of length n +#' @export +#' +rbeta1 = function(n, mu, + pSig=par_sigma_abc()){ + + var = sigma_mu(mu, pSig) + stats::rbeta(n, mu*(mu*(1-mu)/var-1), (1-mu)*(mu*(1-mu)/var-1)) +} + + +#' Modified beta distribution, distribution function +#' +#' @inheritParams p_Omega +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +p_Omega.beta = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + with(par_Omega,{ + # bvm is the upper bound + # xi is log10 parasite densities + mu1 = mu/bvm + xi1 = xi/bvm + pbeta1(xi1, mu1, pSig) +})} + + #' Disribution function for the beta distribution, an alternative parameterization #' #' @param p a vector of probabilities @@ -35,6 +106,20 @@ pbeta1 = function(p, mu, stats::pbeta(p, mu*(mu*(1-mu)/var-1), (1-mu)*(mu*(1-mu)/var-1)) } +#' Modified beta distribution, distribution function +#' +#' @inheritParams q_Omega +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +q_Omega.beta = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + with(par_Omega,{ + mu1 = mu/bvm + qbeta1(xi, mu1, pSig)*bvm +})} + + #' The quantile function for the beta distribution, an alternative parameterization #' #' @param x a vector of quantiles @@ -51,25 +136,19 @@ qbeta1 = function(x, mu, stats::qbeta(x, mu*(mu*(1-mu)/var-1), (1-mu)*(mu*(1-mu)/var-1)) } - -#' The random generation function for the beta distribution, an alternative parameterization -#' Title +#' The quantile function for parasite densities in a simple malaria infection #' -#' @param n number of observations -#' @param mu the mean value for the distribution (0 <= mu <= 1) -#' @param pSig parameters to dispatch the S3 function [sigma_mu] +#' @param par_sigma parameters to compute sigma_mu #' -#' @return a [numeric] vector of length n +#' @return a compound [list] #' @export -#' -rbeta1 = function(n, mu, - pSig=par_sigma_abc()){ - - var = sigma_mu(mu, pSig) - stats::rbeta(n, mu*(mu*(1-mu)/var-1), (1-mu)*(mu*(1-mu)/var-1)) +par_Omega_beta = function(par_sigma = par_sigma_abc()){ + par = list() + class(par) <- "beta" + par$pSig = par_sigma + return(par) } - #' A function to compute the variance of the beta distrution as a function of the mean. #' #' @param mu the mean value for the distribution (0 <= mu <= 1) @@ -111,5 +190,3 @@ par_sigma_abc = function(aa=3.11, bb=2.14, cc=1.74){ par$cc=cc par } - - diff --git a/R/Omega-interface.R b/R/Omega-interface.R new file mode 100644 index 0000000..32a841f --- /dev/null +++ b/R/Omega-interface.R @@ -0,0 +1,56 @@ + +#' The density function for parasite densities in a simple malaria infection +#' +#' @param xi vector of quantiles for \eqn{\log_{10}} parasite densities +#' @param mu the expected value for \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param par_Omega parameters to compute parasite densities as a function of mu +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +d_Omega = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + UseMethod("d_Omega", par_Omega) +} + +#' Random generation of parasite densities from a simple malaria infection +#' +#' @param n the number of observations +#' @param mu the expected value for \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param par_Omega parameters defining parasite densities as a function of the mu +#' +#' @return a [numeric] vector of length(n) +#' @export +#' +r_Omega = function(n, mu, bvm=13, par_Omega=par_Omega_beta()){ + UseMethod("r_Omega", par_Omega) +} + +#' The density function for parasite densities as a function of the mean +#' +#' @param xi a vector of probabilities for \eqn{log_{10}} parasite densities +#' @param mu the expected value for \eqn{log_{10}} parasite densities +#' @param bvm blood volume as \eqn{log_{10}} red blood cells +#' @param par_Omega parameters defining parasite densities as a function of the mu +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +p_Omega = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + UseMethod("p_Omega", par_Omega) +} + +#' The quantile function for parasite densities in a simple malaria infection +#' +#' @param xi a vector of quantiles +#' @param mu the expected value for \eqn{log_{10}} parasite densities +#' @param bvm blood volume as \eqn{log_{10}} red blood cells +#' @param par_Omega parameters defining parasite densities as a function of the mu +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +q_Omega = function(xi, mu, bvm=13, par_Omega=par_Omega_beta()){ + UseMethod("q_Omega", par_Omega) +} diff --git a/R/blood_volume.R b/R/RBC.R similarity index 100% rename from R/blood_volume.R rename to R/RBC.R diff --git a/R/alpha2density.R b/R/alpha2density.R index a67f8ce..4575112 100644 --- a/R/alpha2density.R +++ b/R/alpha2density.R @@ -6,8 +6,8 @@ #' @param W the immune tracking variables #' @param a host cohort age #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] #' #' @return a [numeric] vector of length(x) #' @export @@ -15,10 +15,10 @@ d_alpha2density = function(xi, alpha, W=0, a=0, par_RBC = par_lRBC_static(), par_Fmu = par_Fmu_base(), - par_mu2dens = par_mu2dens_beta()){ + par_Omega = par_Omega_beta()){ bvm = log10RBC(a, par_RBC) - mu = alpha2mu(alpha, W, par_Fmu) - d_mu2density(xi, mu, par_mu2dens, bvm) + mu = Fmu(alpha, W, par_Fmu) + d_Omega(xi, mu, bvm, par_Omega) } #' The distribution function for parasite densities in a simple malaria infection of age alpha @@ -28,8 +28,8 @@ d_alpha2density = function(xi, alpha, W=0, a=0, #' @param W the immune tracking variables #' @param a host cohort age #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [r_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [r_Omega] #' #' @return a [numeric] vector of length(n) #' @export @@ -37,10 +37,10 @@ d_alpha2density = function(xi, alpha, W=0, a=0, r_alpha2density = function(n, alpha, W=0, a=0, par_RBC = par_lRBC_static(), par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta()){ + par_Omega = par_Omega_beta()){ bvm = log10RBC(a, par_RBC) - mu = alpha2mu(alpha, W, par_Fmu) - r_mu2density(n, mu, par_mu2dens, bvm) + mu = Fmu(alpha, W, par_Fmu) + r_Omega(n, mu, bvm, par_Omega) } #' The distribution function for parasite densities in a simple malaria infection of age alpha @@ -50,8 +50,8 @@ r_alpha2density = function(n, alpha, W=0, a=0, #' @param W the immune tracking variables #' @param a host cohort age #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [p_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [p_Omega] #' #' @return a [numeric] vector of length(x) #' @export @@ -59,10 +59,10 @@ r_alpha2density = function(n, alpha, W=0, a=0, p_alpha2density = function(x, alpha, W=0, a=0, par_RBC = par_lRBC_static(), par_Fmu = par_Fmu_base(), - par_mu2dens = par_mu2dens_beta()){ + par_Omega = par_Omega_beta()){ bvm = log10RBC(a, par_RBC) - mu = alpha2mu(alpha, W, par_Fmu) - p_mu2density(x, mu, par_mu2dens, bvm) + mu = Fmu(alpha, W, par_Fmu) + p_Omega(x, mu, bvm, par_Omega) } #' The quantile function for parasite densities in a simple malaria infection of age alpha @@ -72,8 +72,8 @@ p_alpha2density = function(x, alpha, W=0, a=0, #' @param W the immune tracking variables #' @param a host cohort age #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [q_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [q_Omega] #' #' @return a [numeric] vector of length(x) #' @export @@ -81,9 +81,9 @@ p_alpha2density = function(x, alpha, W=0, a=0, q_alpha2density = function(x, alpha, W=0, a=0, par_RBC = par_lRBC_static(), par_Fmu = par_Fmu_base(), - par_mu2dens = par_mu2dens_beta()){ + par_Omega = par_Omega_beta()){ bvm = log10RBC(a, par_RBC) - mu = alpha2mu(alpha, W, par_Fmu) - q_mu2density(x, mu, par_mu2dens, bvm) + mu = Fmu(alpha, W, par_Fmu) + q_Omega(x, mu, bvm, par_Omega) } diff --git a/R/aoi.R b/R/aoi.R index 278468b..d9f2a60 100644 --- a/R/aoi.R +++ b/R/aoi.R @@ -24,6 +24,9 @@ dAoI = function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ #' Compute the distribution function for AoI #' +#' The distribution function for the AoI is given by +#' \deqn{F_A(\alpha | a, \tau, h) = \int_0^\alpha f_A(\alpha, a, \tau | h) d \alpha} +#' #' @inheritParams zda #' #' @return a [numeric] vector of length(alpha) @@ -39,6 +42,9 @@ pAoI = function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ #' Random numbers for the AoI #' +#' @description +#' Draw random numbers for the AoI from a cohort, \eqn{\hat A_\tau(a)} +#' #' @param N the number of observations #' @inheritParams FoI #' @param hhat a local scaling parameter for the FoI diff --git a/R/aoy.R b/R/aoy.R index 5359c4e..92b62f1 100644 --- a/R/aoy.R +++ b/R/aoy.R @@ -30,7 +30,7 @@ pAoY_long= function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ for(m in 1:ix){ aoy = aoy+stats::dpois(m,moi)*(1-(1-py)^m) } - aoy = aoy/truePRa(a,FoIpar,tau,hhat,r) + aoy = aoy/truePR(a,FoIpar,tau,hhat,r) return(aoy) } @@ -46,7 +46,7 @@ dAoY = function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ # The function call dAoYcompute = function(alpha, a, FoIpar, tau, hhat, r){ moi = meanMoI(a,FoIpar,tau,hhat,r) - moi*dAoI(alpha,a,FoIpar,tau,hhat,r)*exp(-moi*pAoI(alpha,a,FoIpar,tau,hhat,r))/truePRa(a,FoIpar,tau,hhat,r) + moi*dAoI(alpha,a,FoIpar,tau,hhat,r)*exp(-moi*pAoI(alpha,a,FoIpar,tau,hhat,r))/truePR(a,FoIpar,tau,hhat,r) } # Use sapply to call dAoYcompute multiple times if(length(alpha)==1) return(dAoYcompute(alpha, a,FoIpar,tau,hhat,r)) diff --git a/R/cohort_detect.R b/R/cohort_detect.R deleted file mode 100644 index b43e17c..0000000 --- a/R/cohort_detect.R +++ /dev/null @@ -1,119 +0,0 @@ - - -#' Detection of infection given parasitemia -#' -#' @param a host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' @param par_RBC parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] -#' @param pWda parameters to dispatch [Wda] -#' @param pC parameters that define a detection function -#' -#' @return a [numeric] vector of length(a) -DetectPa = function(a, FoIpar, tau=0, - hhat=1, r=1/200, - par_RBC = par_lRBC_static(), - Fmu_par=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none(), - pC = par_nbCounts()){ - pD = function(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda, pC){ - Dx = function(x, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, p, pWda, pC){ - d_Pdensity(x, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda)*Detect(x,a,pC) - } - hatb=log10RBC(a,par_mu2dens$pRBC) - stats::integrate(Dx, 0, hatb, a=a, FoIpar=FoIpar, hhat=hhat,tau=tau,r=r,par_RBC, Fmu_par=par_RBC, Fmu_par,par_mu2dens=par_mu2dens, pWda=pWda, pC=pC)$value - } - if(length(a)==1) return(pD(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda, pC)) - return (sapply(a, pD, FoIpar=FoIpar, hhat=tau, hhat=tau, r=r, par_RBC, Fmu_par=par_RBC, Fmu_par, par_mu2dens=par_mu2dens, pWda=pWda, pC=pC)) -} - -#' Detection of infection given parasitemia -#' -#' @param a host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' @param par_RBC parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] -#' @param pWda parameters to dispatch [Wda] -#' @param pC parameters that define a detection function -#' -#' @return binary detection result -#' @export -DetectPM = function(a, FoIpar,tau=0, - hhat=1,r=1/200, - par_RBC = par_lRBC_static(), - Fmu_par=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none(), - pC = par_nbCounts()){ - moi = meanMoI(a, FoIpar, tau, hhat, r) - D = DetectPa(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda, pC) - 1 - exp(-moi*D) -} - -#' Detection of infection given parasitemia -#' -#' @param a host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param dx width of the mesh -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' @param par_RBC parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] -#' @param pWda parameters to dispatch [Wda] -#' @param pC parameters that define a detection function -#' -#' @return binary detection result -#' @export -DetectBda = function(a, FoIpar, dx=0.1,tau=0, - hhat=1,r=1/200, - par_RBC = par_lRBC_static(), - Fmu_par = par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none(), - pC = par_nbCounts()){ - - lRBC = log10RBC(a, par_mu2dens$pRBC) - meshX = seq(0, lRBC, by = dx) - Bx = d_Bdensity(meshX, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda)$PDFm - t(Detect(meshX, a, pC)) -> Bs - sum(Bx*Bs) -} - -#' Detection of infection given parasitemia -#' -#' @param a host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' @param par_RBC parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] -#' @param pWda parameters to dispatch [Wda] -#' @param pC parameters that define a detection function -#' -#' @return detection probability -#' @export -MoIPM = function(a, FoIpar,tau=0, - hhat=1,r=1/200, - par_RBC = par_lRBC_static(), - Fmu_par = par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none(), - pC = par_nbCounts()){ - - moi = meanMoI(a, FoIpar, tau, hhat, r) - D = DetectPa(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_mu2dens, pWda, pC) - moi*D/(1-exp(-moi*D)) -} diff --git a/R/convolve.R b/R/convolve.R index 4cd2230..70bb8c1 100644 --- a/R/convolve.R +++ b/R/convolve.R @@ -8,8 +8,8 @@ #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] value @@ -19,14 +19,14 @@ dDensityPaConvolve2 = function(x, a, FoIpar, hhat=NULL, tau=0, r=1/200, par_RBC = par_lRBC_static(), par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), + par_Omega = par_Omega_beta(), pWda=par_Wda_none()){ px = function(x, log10B, a, FoIpar, hhat, tau, r, - par_RBC, par_Fmu, par_mu2dens, pWda){ + par_RBC, par_Fmu, par_Omega, pWda){ lB2 = log10(10^log10B - 10^x) - d_Pdensity(x,a,FoIpar, hhat, tau, r, par_RBC, par_Fmu, par_mu2dens, pWda)*d_Pdensity(lB2,a, FoIpar, hhat, tau, r, par_RBC, par_Fmu, par_mu2dens, pWda) + d_clone_density(x,a,FoIpar, hhat, tau, r, par_RBC, par_Fmu, par_Omega, pWda)*d_clone_density(lB2,a, FoIpar, hhat, tau, r, par_RBC, par_Fmu, par_Omega, pWda) } - stats::integrate(px, 0, x, log10B=x, a=a, FoIpar=FoIpar, hhat=hhat, tau=tau, r=r, par_RBC=par_RBC, par_Fmu=par_Fmu, par_mu2dens=par_mu2dens, pWda=pWda)$value + stats::integrate(px, 0, x, log10B=x, a=a, FoIpar=FoIpar, hhat=hhat, tau=tau, r=r, par_RBC=par_RBC, par_Fmu=par_Fmu, par_Omega=par_Omega, pWda=pWda)$value } diff --git a/R/cohort_counts.R b/R/counts.R similarity index 53% rename from R/cohort_counts.R rename to R/counts.R index 96b246a..c7dcce5 100644 --- a/R/cohort_counts.R +++ b/R/counts.R @@ -1,5 +1,4 @@ - #' Compute the distribution of parasite counts for simple infections #' #' @param a host cohort age @@ -10,36 +9,34 @@ #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -pCountsPa = function(a, FoIpar, bins=c(1:5, 13), dx=0.1, - hhat=1,tau=0, r=1/200, - RBC_par = par_lRBC_static(), - Fmu_par = par_Fmu_base(), - mu_par = par_mu2dens_beta(), - pWda=par_Wda_none(), - Cpar = par_nbCounts()){ - lRBC = log10RBC(a, RBC_par) - meshX = seq(0, lRBC, by=dx) +p_clone_counts = function(a, FoIpar, bins=c(1:5, 13), dx=0.1, + hhat=1,tau=0, r=1/200, + RBC_par = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + Omega_par = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + bvm = log10RBC(a, RBC_par) + meshX = seq(0, bvm, by=dx) mix = 1:length(meshX) - Pda = d_Pdensity(meshX, a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, mu_par, pWda) + Pda = d_clone_density(meshX, a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, Omega_par, pWda) Pda = Pda/sum(Pda) - cdfP = function(xi, a, Cpar){ - pD = Detect(xi,a,Cpar) - counts = pCounts(bins, xi, a, Cpar) + cdfP = function(xi, bvm, par_sample){ + pD = d_detect(xi, bvm, par_sample) + counts = p_counts(bins, xi, bvm, par_sample) } - Bx=sapply(meshX, cdfP, a=a, Cpar=Cpar) + Bx=sapply(meshX, cdfP, bvm=bvm, par_sample=par_sample) list(bins=bins,cdf=rowSums(Bx*Pda)) } - - #' Compute the density of parasite counts for simple infections #' #' @param a host cohort age @@ -50,67 +47,55 @@ pCountsPa = function(a, FoIpar, bins=c(1:5, 13), dx=0.1, #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -dCountsPa = function(a, FoIpar, bins=1, dx=0.1, - hhat=1,tau=0, r=1/200, - RBC_par = par_lRBC_static(), - Fmu_par=par_Fmu_base(), - mu_par = par_mu2dens_beta(), - pWda=par_Wda_none(), - Cpar = par_nbCounts()){ - DP = DetectPa(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, mu_par, pWda, Cpar) - PC = pCountsPa(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, mu_par, pWda, Cpar) +d_clone_counts = function(a, FoIpar, bins=1, dx=0.1, + hhat=1,tau=0, r=1/200, + RBC_par = par_lRBC_static(), + Fmu_par=par_Fmu_base(), + Omega_par = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + DP = d_clone_detect(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, Omega_par, pWda, par_sample) + PC = p_clone_counts(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, Omega_par, pWda, par_sample) list(bins=PC$bins, pdf=diff(c(DP, PC$cdf))/(1-DP), detect=DP, cdf=PC$cdf, fullpdf = c(DP,diff(c(DP, PC$cdf)))) } - - - - - - -#' Compute the distribution of parasite counts in complex infections +#' Compute the mean parasite counts in simple infections #' #' @param a host cohort age #' @param FoIpar parameters that define an FoI function -#' @param bins a set of break points for computing counts #' @param dx the width of the mesh for computing the CDF of parasite densities #' @param hhat a local scaling parameter for the FoI #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection -#' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -pCountsBa = function(a, FoIpar, bins=1, dx=0.1, - hhat=1,tau=0, r=1/200, - RBC_par = par_lRBC_static(), - Fmu_par=par_Fmu_base(), - mu_par = par_mu2dens_beta(), - pWda=par_Wda_none(), - Cpar = par_nbCounts()){ - moi = meanMoI(a, FoIpar, hhat, tau, r) - D = DetectPa(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, mu_par, pWda, Cpar) - out= pCountsPa(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, mu_par, pWda, Cpar) - list(bins=out$bins, cdf=(1 - exp(-moi*D*out$cdf))/(1-exp(-moi*D)), DM = 1 - exp(-moi*D)) +mean_clone_counts = function(a, FoIpar, dx=0.1, + hhat=1,tau=0, r=1/200, + Fmu_par=par_Fmu_base(), + Omega_par = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + bins = seq(0,7, by=dx) + PC = d_clone_counts(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, Omega_par, pWda, par_sample) + sum(PC$bins*PC$pdf) } - - -#' Compute the density of parasite counts in complex infections +#' Compute the distribution of parasite counts in complex infections #' #' @param a host cohort age #' @param FoIpar parameters that define an FoI function @@ -120,58 +105,59 @@ pCountsBa = function(a, FoIpar, bins=1, dx=0.1, #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -dCountsBa = function(a, FoIpar, bins=1, dx=0.1, +p_parasite_counts = function(a, FoIpar, bins=1, dx=0.1, hhat=1,tau=0, r=1/200, RBC_par = par_lRBC_static(), Fmu_par=par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda=par_Wda_none(), - Cpar = par_nbCounts()){ + par_sample = par_nb()){ moi = meanMoI(a, FoIpar, hhat, tau, r) - D = DetectPa(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, mu_par, pWda, Cpar) - PC = pCountsBa(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, mu_par, pWda, Cpar) - DP = PC$DM - list(bins=PC$bins, pdf=diff(c(DP, PC$cdf))/(1-DP), detect=DP, cdf=PC$cdf, fullpdf = c(DP, diff(c(DP, PC$cdf)))) + D = d_parasite_detect(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, Omega_par, pWda, par_sample) + out= p_clone_counts(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, Omega_par, pWda, par_sample) + list(bins=out$bins, cdf=(1 - exp(-moi*D*out$cdf))/(1-exp(-moi*D)), DM = 1 - exp(-moi*D)) } - -#' Compute the mean parasite counts in simple infections +#' Compute the density of parasite counts in complex infections #' #' @param a host cohort age #' @param FoIpar parameters that define an FoI function +#' @param bins a set of break points for computing counts #' @param dx the width of the mesh for computing the CDF of parasite densities #' @param hhat a local scaling parameter for the FoI #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param RBC_par parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -meanCountsPa = function(a, FoIpar, dx=0.1, - hhat=1,tau=0, r=1/200, - Fmu_par=par_Fmu_base(), - mu_par = par_mu2dens_beta(), - pWda=par_Wda_none(), - Cpar = par_nbCounts()){ - bins = seq(0,7, by=dx) - PC = dCountsPa(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, mu_par, pWda, Cpar) - sum(PC$bins*PC$pdf) +d_parasite_counts = function(a, FoIpar, bins=1, dx=0.1, + hhat=1,tau=0, r=1/200, + RBC_par = par_lRBC_static(), + Fmu_par=par_Fmu_base(), + Omega_par = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + moi = meanMoI(a, FoIpar, hhat, tau, r) + D = d_parasite_detect(a, FoIpar, hhat, tau, r, RBC_par, Fmu_par, Omega_par, pWda, par_sample) + PC = p_parasite_counts(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, Omega_par, pWda, par_sample) + DP = PC$DM + list(bins=PC$bins, pdf=diff(c(DP, PC$cdf))/(1-DP), detect=DP, cdf=PC$cdf, fullpdf = c(DP, diff(c(DP, PC$cdf)))) } - - #' Compute the mean parasite counts in complex infections #' #' @param a host cohort age @@ -180,21 +166,21 @@ meanCountsPa = function(a, FoIpar, dx=0.1, #' @param hhat a local scaling parameter for the FoI #' @param tau the cohort birthday #' @param r the clearance rate for a simple infection -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] -#' @param Cpar parameters that define a detection function +#' @param par_sample parameters that define a detection function #' #' @return a [list] #' @export #' -meanCountsBa = function(a, FoIpar, dx=0.1, +mean_parasite_counts = function(a, FoIpar, dx=0.1, hhat=1,tau=0, r=1/200, Fmu_par=par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda=par_Wda_none(), - Cpar = par_nbCounts()){ + par_sample = par_nb()){ bins = seq(0,7, by = dx) - PC = dCountsBa(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, mu_par, pWda, Cpar) + PC = d_parasite_counts(a, FoIpar, bins, dx, hhat, tau, r, Fmu_par, Omega_par, pWda, par_sample) sum(PC$bins*PC$pdf) } diff --git a/R/cohort_parasites_clones.R b/R/density_clone.R similarity index 54% rename from R/cohort_parasites_clones.R rename to R/density_clone.R index 07767a3..e15a2c7 100644 --- a/R/cohort_parasites_clones.R +++ b/R/density_clone.R @@ -11,24 +11,24 @@ #' @param hhat a local scaling parameter for the FoI #' @param r the clearance rate for a simple infection #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] vector of length(x) #' @export -d_Pdensity = function(xi, a, FoIpar, tau=0, - hhat=1, r=1/200, - par_RBC = par_lRBC_static(), - par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none()){ +d_clone_density = function(xi, a, FoIpar, tau=0, + hhat=1, r=1/200, + par_RBC = par_lRBC_static(), + par_Fmu=par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none()){ - simpleDensities = function(x, a, FoIpar, tau, hhat, r, lRBC, m, W, par_Fmu, par_mu2dens){ + clon_dens = function(x, a, FoIpar, tau, hhat, r, lRBC, m, W, par_Fmu, par_Omega){ Pa = function(alpha, x, W, a, m){ - mu = alpha2mu(alpha, W, par_Fmu) + mu = Fmu(alpha, W, par_Fmu) y = zda(alpha, a, FoIpar, tau, hhat, r) - d_mu2density(x, mu, par_mu2dens, lRBC)*y/m + d_Omega(x, mu, lRBC, par_Omega)*y/m } lowlim = 8 uplim = min(a, 6*365) @@ -39,10 +39,10 @@ d_Pdensity = function(xi, a, FoIpar, tau=0, m = meanMoI(a, FoIpar, tau, hhat, r) W = Wda(a, FoIpar, tau, hhat, pWda) lRBC = log10RBC(a, par_RBC) - if(length(xi)==1) return(simpleDensities(xi, a, FoIpar, tau, hhat, r, - lRBC, m, W, par_Fmu, par_mu2dens)) - return(sapply(xi, simpleDensities, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r, - lRBC=lRBC, m=m, W=W, par_Fmu=par_Fmu, par_mu2dens=par_mu2dens)) + if(length(xi)==1) return(clon_dens(xi, a, FoIpar, tau, hhat, r, + lRBC, m, W, par_Fmu, par_Omega)) + return(sapply(xi, clon_dens, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r, + lRBC=lRBC, m=m, W=W, par_Fmu=par_Fmu, par_Omega=par_Omega)) } #' Compute the moments of P_density @@ -58,22 +58,22 @@ d_Pdensity = function(xi, a, FoIpar, tau=0, #' @param hhat a local scaling parameter for the FoI #' @param r the clearance rate for a simple infection #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] vector of length(x) #' @export -moment_Pdensity = function(a, FoIpar, tau=0, n=1, dt=0.1, - hhat=1, r=1/200, - par_RBC = par_lRBC_static(), - par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none()){ +moments_clone_density = function(a, FoIpar, tau=0, n=1, dt=0.1, + hhat=1, r=1/200, + par_RBC = par_lRBC_static(), + par_Fmu=par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none()){ lRBC = log10RBC(a, par_RBC) xi = seq(0, lRBC, by = dt) - Pd = d_Pdensity(xi, a, FoIpar, tau, hhat, r, - par_RBC, par_Fmu, par_mu2dens, pWda) + Pd = d_clone_density(xi, a, FoIpar, tau, hhat, r, + par_RBC, par_Fmu, par_Omega, pWda) sum(xi^n*Pd*dt) } diff --git a/R/cohort_parasites_complex.R b/R/density_parasites.R similarity index 72% rename from R/cohort_parasites_complex.R rename to R/density_parasites.R index 9d1bb22..447dfb3 100644 --- a/R/cohort_parasites_complex.R +++ b/R/density_parasites.R @@ -2,7 +2,7 @@ #' Compute \eqn{B_\tau(a | h)} #' #' @description -#' This function first computes the PDF for simple infections, [d_Pdensity], and +#' This function first computes the PDF for simple infections, [d_clone_density], and #' then computes the CDF for the full distribution, summed from MoI = 1 up to a large number #' using convolutions. #' @@ -14,21 +14,21 @@ #' @param hhat a local scaling parameter for the FoI #' @param r the clearance rate for a simple infection #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters to compute [d_mu2density] +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] vector of length meshX #' @export #' -Bdensity = function(meshX, +parasite_density = function(meshX, a, FoIpar, tau=0, hhat=1, r=1/200, RBC_par = par_lRBC_static(), Fmu_par = par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda = par_Wda_none()){ - PDFx = d_Pdensity(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, mu_par, pWda) + PDFx = d_clone_density(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, Omega_par, pWda) CDFx = cumsum(PDFx) CDFx = CDFx/max(CDFx) PDFx = c(CDFx[1], diff(CDFx)) @@ -66,37 +66,37 @@ Bdensity = function(meshX, #' Compute the distribution function for \eqn{B_\tau(a)} #' #' @description -#' Call [Bdensity] and return the PDF: +#' Call [parasite_density] and return the PDF: #' \deqn{f_B(\xi; a, \tau |h) = \log_{10} \left( \sum_{M_\tau(a|h)>0} 10^{P_\tau(a |h)}\right)} #' -#' @inheritParams Bdensity +#' @inheritParams parasite_density #' #' @return a [numeric] vector of length meshX #' @export #' -d_Bdensity = function(meshX, +d_parasite_density = function(meshX, a, FoIpar, tau=0, hhat=1, r=1/200, RBC_par = par_lRBC_static(), Fmu_par = par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda = par_Wda_none()){ - Bdensity(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, mu_par, pWda)$PDFm + parasite_density(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, Omega_par, pWda)$PDFm } -#' Call [Bdensity] and return the density vector +#' Call [parasite_density] and return the density vector #' -#' @inheritParams Bdensity +#' @inheritParams parasite_density #' #' @return a numeric vector of length meshX #' @export #' -p_Bdensity = function(meshX, a, FoIpar, tau=0, hhat=1, r=1/200, +p_parasite_density = function(meshX, a, FoIpar, tau=0, hhat=1, r=1/200, RBC_par = par_lRBC_static(), Fmu_par = par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda=par_Wda_none()){ - Bdensity(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, mu_par, pWda)$CDFm + parasite_density(meshX, a, FoIpar, tau, hhat, r, RBC_par, Fmu_par, Omega_par, pWda)$CDFm } #' Random generation for parasite densities in a host cohort @@ -109,19 +109,19 @@ p_Bdensity = function(meshX, a, FoIpar, tau=0, hhat=1, r=1/200, #' @param r the clearance rate for a simple infection #' @param alphamin the minimum value of alpha allowed #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters to compute [d_mu2density] +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] vector of length N #' @export #' -r_Bdensity = function(N, a, FoIpar, tau=0, - hhat=1, r=1/200, alphamin=7, - RBC_par = par_lRBC_static(), - Fmu_par= par_Fmu_base(), - mu_par = par_mu2dens_beta(), - pWda=par_Wda_none()){ +r_parasite_density = function(N, a, FoIpar, tau=0, + hhat=1, r=1/200, alphamin=7, + RBC_par = par_lRBC_static(), + Fmu_par= par_Fmu_base(), + Omega_par = par_Omega_beta(), + pWda=par_Wda_none()){ moi = meanMoI(a, FoIpar, tau, hhat, r) W = Wda(a, FoIpar, tau, hhat, pWda) @@ -129,9 +129,9 @@ r_Bdensity = function(N, a, FoIpar, tau=0, Ny = sum(hatm) hatalpha = rAoI(Ny, a, FoIpar, tau, hhat, r, alphamin) # their expected values - hatmu = alpha2mu(hatalpha, W, Fmu_par) + hatmu = Fmu(hatalpha, W, Fmu_par) bvm = log10RBC(a, RBC_par) - hatx = r_mu2density(Ny, hatmu, mu_par, bvm) + hatx = r_Omega(Ny, hatmu, Omega_par, bvm) lRBC = 10^hatx first = sum(lRBC[1:hatm[1]]) rest = diff(cumsum(lRBC)[cumsum(hatm)]) @@ -149,8 +149,8 @@ r_Bdensity = function(N, a, FoIpar, tau=0, #' @param r the clearance rate for a simple infection #' @param alphamin the minimum value of alpha allowed #' @param RBC_par parameters to compute [log10RBC] -#' @param Fmu_par parameters to compute [alpha2mu] -#' @param mu_par parameters defining parasite densities as a function of the mu +#' @param Fmu_par parameters to compute [Fmu] +#' @param Omega_par parameters defining parasite densities as a function of the mu #' @param pWda parameters to dispatch [Wda] #' #' @return a R by M [matrix] @@ -159,16 +159,16 @@ r_Bdensity = function(N, a, FoIpar, tau=0, rRda = function(M, R, a, FoIpar, tau=0, hhat=1, r=1/200, alphamin=7, RBC_par = par_lRBC_static(), Fmu_par = par_Fmu_base(), - mu_par = par_mu2dens_beta(), + Omega_par = par_Omega_beta(), pWda=par_Wda_none()){ W = Wda(a, FoIpar, tau, hhat, pWda) # MoI, excluding zeros Ny = R*M hatalpha = rAoI(Ny, a, FoIpar, tau, hhat, r, alphamin) # their expected values - hatmu = alpha2mu(hatalpha, W, Fmu_par) + hatmu = Fmu(hatalpha, W, Fmu_par) bvm = log10RBC(a, RBC_par) - hatx = r_mu2density(Ny, hatmu, mu_par, bvm) + hatx = r_Omega(Ny, hatmu, Omega_par, bvm) lRBC = 10^hatx matrix(lRBC,nrow=R, ncol=M) } @@ -187,22 +187,22 @@ rRda = function(M, R, a, FoIpar, tau=0, hhat=1, r=1/200, alphamin=7, #' @param hhat a local scaling parameter for the FoI #' @param r the clearance rate for a simple infection #' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] #' @param pWda parameters to dispatch [Wda] #' #' @return a [numeric] vector of length(x) #' @export -moment_Bdensity = function(a, FoIpar, tau=0, n=1, dt=0.1, +moments_parasite_density = function(a, FoIpar, tau=0, n=1, dt=0.1, hhat=1, r=1/200, par_RBC = par_lRBC_static(), par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), + par_Omega = par_Omega_beta(), pWda=par_Wda_none()){ lRBC = log10RBC(a, par_RBC) xi = seq(0, lRBC, by = dt) - Bd = d_Bdensity(xi, a, FoIpar, tau, hhat, r, - par_RBC, par_Fmu, par_mu2dens, pWda) + Bd = d_parasite_density(xi, a, FoIpar, tau, hhat, r, + par_RBC, par_Fmu, par_Omega, pWda) sum(xi^n*Bd) } diff --git a/R/detect_parasites.R b/R/detect_parasites.R new file mode 100644 index 0000000..64f4a4a --- /dev/null +++ b/R/detect_parasites.R @@ -0,0 +1,99 @@ +#' Detection of infection given parasitemia +#' +#' @param xi_mesh a mesh over \eqn{\log_{10}} parasite densities +#' @param xi_density the density distribution for parasites over [xi_mesh] +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param par_sample parameters that define a detection function +#' +#' @return the fraction of infected hosts that would test positive +#' @export +d_detect_mesh = function(xi_mesh, xi_density, bvm=13, par_sample = par_nb()){ + d_detect(xi_mesh, bvm, par_sample) -> pr_pos + sum(pr_pos*xi_density) +} + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param dx width of the mesh +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_parasite_detect = function(a, FoIpar, dx=0.1, tau=0, + hhat=1,r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + + lRBC = log10RBC(a, par_RBC) + xi_mesh = seq(0, lRBC, by = dx) + Bx = d_parasite_density(xi_mesh, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda) + d_detect_mesh(xi_mesh, Bx, lRBC, par_sample) +} + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_parasite_detect_moi = function(a, FoIpar,tau=0, + hhat=1,r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda = par_Wda_none(), + par_sample = par_nb()){ + moi = meanMoI(a, FoIpar, tau, hhat, r) + D = cohort_detect_clone(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample) + 1 - exp(-moi*D) +} + + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return detection probability +#' @export +d_moi_count = function(a, FoIpar,tau=0, + hhat=1,r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + + moi = meanMoI(a, FoIpar, tau, hhat, r) + D = detect_clone_by_cohort(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample) + moi*D/(1-exp(-moi*D)) +} diff --git a/R/detection-interface.R b/R/detection-interface.R deleted file mode 100644 index ffc02a0..0000000 --- a/R/detection-interface.R +++ /dev/null @@ -1,51 +0,0 @@ -#' Detection of infection given parasitemia -#' -#' @param xi mean \eqn{\log_{10}} parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -Detect = function(xi, a=0, Cpar=par_nbCounts()){ - UseMethod("Detect", Cpar) -} - -#' density function of counts -#' -#' @param hatxi mean \eqn{\log_{10}} parasite counts -#' @param xi mean \eqn{\log_{10}} parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -dCounts = function(hatxi, xi, a=0, Cpar=par_nbCounts()){ - UseMethod("dCounts", Cpar) -} - -#' cumulative density function of counts -#' -#' @param hatxi mean log10 parasite densities -#' @param xi mean \eqn{\log_{10}} parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -pCounts = function(hatxi, xi, a=0, Cpar=par_nbCounts()){ - UseMethod("pCounts", Cpar) -} - -#' Detection of infection given parasitemia -#' -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param bins breakpoints for summarizing outputs -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -binnedCounts = function(xi, a, bins, Cpar=par_nbCounts()){ - UseMethod("binnedCounts", Cpar) -} - diff --git a/R/detection-nb.R b/R/detection-nb.R deleted file mode 100644 index 22fe7e0..0000000 --- a/R/detection-nb.R +++ /dev/null @@ -1,77 +0,0 @@ - -#' Detection of infection given parasitemia -#' -#' @param q the fraction of blood examined -#' @param sz the negative binomial size parameter -#' @param bvm blood volume as log10 red blood cells -#' -#' @return binary detection result -#' @export -#' -par_nbCounts = function(q=6, sz=0.31, bvm = par_lRBC_static()){ - par = list() - class(par) <- "nb" - par$q=q - par$sz=sz - par$bvm = bvm - par -} - -#' Detection of infection given parasitemia -#' -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -Detect.nb = function(xi, a=0, Cpar=par_nbCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - 1-stats::dnbinom(0, mu=10^(xi-lRBC+q), size=sz) -})} - - - -#' Detection of infection given parasitemia -#' -#' @param hatxi mean log10 parasite counts -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -dCounts.nb = function(hatxi, xi, a=0, Cpar=par_nbCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - stats::dnbinom(round(10^hatxi), mu=10^(xi-lRBC+q), size=sz) -})} - -#' Detection of infection given parasitemia -#' -#' @param hatxi mean log10 parasite counts -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -pCounts.nb = function(hatxi, xi, a=0, Cpar=par_nbCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - pnbinom(10^hatxi, mu=10^(xi-lRBC+q), size=sz) -})} - -#' Detection of infection given parasitemia -#' -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param bins break points for binning counts data -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -binnedCounts.nb = function(xi, a, bins, Cpar=par_nbCounts()){ - if(is.null(bins)) bins=c(1:5,13) - p0 = Detect(xi,a,Cpar) - p1 = pCounts(bins, xi, a, Cpar) - diff(c(1-p0,p1))/p0 -} diff --git a/R/detection-pois.R b/R/detection-pois.R deleted file mode 100644 index 997e276..0000000 --- a/R/detection-pois.R +++ /dev/null @@ -1,78 +0,0 @@ - -#' Detection of infection given parasitemia - -#' @param q the fraction of blood volume sampled -#' @param bvm blood volume as log10 red blood cells -#' -#' @return par a [list] -#' @export -par_poisCounts = function(q=6, bvm = par_lRBC_static()){ - par = list() - class(par) <- "pois" - par$q=q - par$bvm = bvm - par -} - -#' Detection of infection given parasitemia -#' -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -Detect.pois = function(xi, a=0, Cpar=par_poisCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - 1-stats::dpois(0, 10^(xi-lRBC+q)) -})} - - - -#' Detection of infection given parasitemia -#' -#' @param hatxi mean log10 parasite densities -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -dCounts.pois = function(hatxi, xi, a=0, Cpar=par_poisCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - stats::dpois(round(10^hatxi), 10^(xi-lRBC+q)) -})} - - - -#' Detection of infection given parasitemia -#' -#' @param hatxi mean log10 parasite counts -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -pCounts.pois = function(hatxi, xi, a=0, Cpar=par_poisCounts()){with(Cpar,{ - lRBC = log10RBC(a, bvm) - ppois(10^hatxi, 10^(xi-lRBC+q)) -})} - - - -#' Detection of infection given parasitemia -#' -#' @param xi mean log10 parasite densities -#' @param a host cohort age -#' @param bins breakpoints for binning data -#' @param Cpar parameters that define a detection function -#' -#' @return binary detection result -#' @export -binnedCounts.pois = function(xi, a, bins, Cpar=par_poisCounts()){ - if(is.null(bins)) bins=c(1:5,13) - p0 = Detect(xi,a,Cpar) - p1 = pCounts(bins, xi, a, Cpar) - diff(c(1-p0,p1))/p0 -} diff --git a/R/detection.R b/R/detection.R new file mode 100644 index 0000000..5daa3e9 --- /dev/null +++ b/R/detection.R @@ -0,0 +1,175 @@ + +#' Detection of infection given parasitemia +#' +#' @param xi_mesh a mesh over \eqn{\log_{10}} parasite densities +#' @param xi_density the density distribution for parasites over xi_mesh +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param par_sample parameters that define a detection function +#' +#' @return the fraction of infected hosts that would test positive +#' @export +d_detect_mesh = function(xi_mesh, xi_density, bvm=13, par_sample = par_nb()){ + d_detect(xi_mesh, bvm, par_sample) -> pr_pos + sum(pr_pos*xi_density) +} + +#' The proportion of zero counts in +#' +#' @param alpha the age of a parasite infection +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param svm the volume of a blood sample +#' @param par_RBC parameters to compute [log10RBC] +#' @param par_Fmu parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return a [numeric] vector of length(xi) +#' @export +#' +FQ = function(alpha, a, FoIpar, + tau=0, hhat=1, r=1/200, svm = 1e6, + par_RBC = par_lRBC_static(), + par_Fmu = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda = par_Wda_none(), + par_sample = par_nb() + ){ + + frac_zero = function(mu, bvm, pO, pS){ + ff = function(x, mu, bvm, pO, pS){ + d_detect(x, bvm, pS)*d_Omega(x, mu, bvm, pO) + } + stats::integrate(ff, 0, bvm, mu=mu, bvm=bvm, pO=pO, pS=pS)$val + } + + bvm = log10RBC(a, par_RBC) + W = Wda(a, FoIpar, tau, hhat, pWda) + mu = Fmu(alpha, W, par_Fmu) + probs = sapply(mu, frac_zero, bvm=bvm, pO=par_Omega, pS=par_sample) + return(probs) +} + + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return a [numeric] vector of length(a) +d_clone_detect = function(a, FoIpar, tau=0, + hhat=1, r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par=par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + pD = function(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample){ + Dx = function(x, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, p, pWda, par_sample){ + d_clone_density(x, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda)*d_detect(x,a,par_sample) + } + hatb=log10RBC(a,par_Omega$pRBC) + stats::integrate(Dx, 0, hatb, a=a, FoIpar=FoIpar, hhat=hhat,tau=tau,r=r,par_RBC, Fmu_par=par_RBC, Fmu_par,par_Omega=par_Omega, pWda=pWda, par_sample=par_sample)$value + } + if(length(a)==1) return(pD(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample)) + return (sapply(a, pD, FoIpar=FoIpar, hhat=tau, hhat=tau, r=r, par_RBC, Fmu_par=par_RBC, Fmu_par, par_Omega=par_Omega, pWda=pWda, par_sample=par_sample)) +} + + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param dx width of the mesh +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_parasite_detect = function(a, FoIpar, tau=0, + hhat=1, r=1/200, dx=0.1, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + + lRBC = log10RBC(a, par_RBC) + xi_mesh = seq(0, lRBC, by = dx) + Bx = d_parasite_density(xi_mesh, a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda) + d_detect_mesh(xi_mesh, Bx, lRBC, par_sample) +} + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_parasite_detect_moi = function(a, FoIpar,tau=0, + hhat=1,r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda = par_Wda_none(), + par_sample = par_nb()){ + moi = meanMoI(a, FoIpar, tau, hhat, r) + D = d_clone_detect(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample) + 1 - exp(-moi*D) +} + + +#' Detection of infection given parasitemia +#' +#' @param a host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' @param par_RBC parameters to compute [log10RBC] +#' @param Fmu_par parameters to compute [Fmu] +#' @param par_Omega parameters to compute [d_Omega] +#' @param pWda parameters to dispatch [Wda] +#' @param par_sample parameters that define a detection function +#' +#' @return detection probability +#' @export +d_moi_count = function(a, FoIpar,tau=0, + hhat=1,r=1/200, + par_RBC = par_lRBC_static(), + Fmu_par = par_Fmu_base(), + par_Omega = par_Omega_beta(), + pWda=par_Wda_none(), + par_sample = par_nb()){ + + moi = meanMoI(a, FoIpar, tau, hhat, r) + D = d_clone_detect(a, FoIpar, tau, hhat, r, par_RBC, Fmu_par, par_Omega, pWda, par_sample) + moi*D/(1-exp(-moi*D)) +} diff --git a/R/dynamics.R b/R/dynamics.R deleted file mode 100644 index b069d6a..0000000 --- a/R/dynamics.R +++ /dev/null @@ -1,21 +0,0 @@ - -#' Compute infection density in a cohort of humans, \eqn{z_\tau(\alpha, a)} -#' -#' @description -#' Given a function describing the FoI (\eqn{h_\tau(a)}), and a parameter -#' describing the clearance rate of infections (\eqn{r}), -#' the density of parasites of age \eqn{\alpha} in a cohort of humans of -#' age \eqn{a} is \deqn{z_\tau(\alpha, a) = e^{-r \alpha} h_\tau(a-\alpha)} -#' -#' @param alpha the age of an infection, \eqn{\alpha} -#' @inheritParams FoI -#' @param hhat scaling parameter for [FoI] -#' @param r the clearance rate for a simple infection -#' -#' @return a [numeric] vector of length(alpha) -#' @seealso [pf.memory::FoI()] -#' @export -#' -zda = function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ - hhat*FoI(a-alpha, FoIpar, tau)*exp(-r*alpha) -} diff --git a/R/infection_dynamics.R b/R/infection_dynamics.R new file mode 100644 index 0000000..98b8020 --- /dev/null +++ b/R/infection_dynamics.R @@ -0,0 +1,61 @@ + +#' Compute infection density in a cohort of humans, \eqn{z_\tau(\alpha, a |h)} +#' +#' @description +#' Given a function describing the FoI (\eqn{h_\tau(a)}), and a parameter +#' describing the clearance rate of infections (\eqn{r}), +#' the density of parasite clones of age \eqn{\alpha} distributed among a cohort of humans of +#' age \eqn{a} is \deqn{z_\tau(\alpha, a) = e^{-r \alpha} h_\tau(a-\alpha)} +#' +#' @param alpha the age of an infection, \eqn{\alpha} +#' @inheritParams FoI +#' @param hhat scaling parameter for [FoI] +#' @param r the clearance rate for a simple infection +#' +#' @return a [numeric] vector of length(alpha) +#' @seealso [pf.memory::FoI()] +#' @export +#' +zda = function(alpha, a, FoIpar, tau=0, hhat=1, r=1/200){ + hhat*FoI(a-alpha, FoIpar, tau)*exp(-r*alpha) +} + +#' The mean MoI in a host cohort of age \eqn{a} +#' +#' @description +#' The mean multiplicity of infection (MoI) is \deqn{m_\tau(a|h) = \int_0^a z_\tau(\alpha, a|h) d \alpha} +#' +#' @inheritParams FoI +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' +#' @return a [numeric] vector of length(a) +#' @export +#' +meanMoI = function(a, FoIpar, tau=0, hhat=1, r=1/200){ + moif = function(a, FoIpar, tau, hhat,r){ + stats::integrate(zda, 0, a, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r)$value + } + if(length(a)==1){return(moif(a,FoIpar,tau,hhat,r))} else{ + (return(sapply(a,moif,FoIpar=FoIpar,tau=tau,hhat=hhat,r=r)))} +} + + +#' Compute the true PR in a cohort as a function of age and exposure +#' +#' @description +#' The true PR is \deqn{p_\tau(a|h) = 1 - e^{-m_\tau(a|h)}} +#' +#' @param a the host cohort age +#' @param FoIpar parameters that define an FoI function +#' @param tau the cohort birthday +#' @param hhat a local scaling parameter for the FoI +#' @param r the clearance rate for a simple infection +#' +#' @return a [numeric] vector of length(a) +#' @export +#' +truePR = function(a, FoIpar, tau=0, hhat=1, r=1/200){ + 1-exp(-meanMoI(a, FoIpar, tau, hhat, r)) +} + diff --git a/R/mu2density-beta.R b/R/mu2density-beta.R deleted file mode 100644 index e7d718b..0000000 --- a/R/mu2density-beta.R +++ /dev/null @@ -1,78 +0,0 @@ - -#' Modified beta distribution, density function -#' -#' @description -#' The beta distribution, parameterized by the mean and variance, modified to return -#' a number between 0 and bvm (the number of red blood cells) -#' -#' -#' @inheritParams d_mu2density -#' -#' @return a [numeric] vector of length(xi) -#' @export -d_mu2density.beta = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - with(par_mu2dens,{ - xi1 = xi/bvm - mu1 = mu/bvm - dbeta1(xi1, mu1, pSig)/bvm -})} - -#' Modified beta distribution, random numbers -#' -#' @description -#' The beta distribution, parameterized by the mean and variance, modified to return -#' a number between 0 and bvm (the number of red blood cells) -#' -#' @inheritParams r_mu2density -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -r_mu2density.beta = function(n, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - with(par_mu2dens,{ - mu1 = mu/bvm - rbeta1(n, mu1, pSig)*bvm -})} - - -#' Modified beta distribution, distribution function -#' -#' @inheritParams p_mu2density -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -p_mu2density.beta = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - with(par_mu2dens,{ - # bvm is the upper bound - # xi is log10 parasite densities - mu1 = mu/bvm - xi1 = xi/bvm - pbeta1(xi1, mu1, pSig) -})} - -#' Modified beta distribution, distribution function -#' -#' @inheritParams q_mu2density -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -q_mu2density.beta = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - with(par_mu2dens,{ - mu1 = mu/bvm - qbeta1(xi, mu1, pSig)*bvm -})} - -#' The quantile function for parasite densities in a simple malaria infection -#' -#' @param par_sigma parameters to compute sigma_mu -#' -#' @return a compound [list] -#' @export -par_mu2dens_beta = function(par_sigma = par_sigma_abc()){ - par = list() - class(par) <- "beta" - par$pSig = par_sigma - return(par) -} diff --git a/R/mu2density-interface.R b/R/mu2density-interface.R deleted file mode 100644 index 78f69ea..0000000 --- a/R/mu2density-interface.R +++ /dev/null @@ -1,56 +0,0 @@ - -#' The density function for parasite densities in a simple malaria infection -#' -#' @param xi vector of quantiles for \eqn{log_{10}} parasite densities -#' @param mu the expected value for \eqn{log_{10}} parasite densities -#' @param par_mu2dens parameters to compute parasite densities as a function of mu -#' @param bvm blood volume as \eqn{log_{10}} red blood cells -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -d_mu2density = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - UseMethod("d_mu2density", par_mu2dens) -} - -#' Random generation of parasite densities from a simple malaria infection -#' -#' @param n the number of observations -#' @param mu the expected value for \eqn{log_{10}} parasite densities -#' @param par_mu2dens parameters defining parasite densities as a function of the mu -#' @param bvm blood volume as \eqn{log_{10}} red blood cells -#' -#' @return a [numeric] vector of length(n) -#' @export -#' -r_mu2density = function(n, mu, par_mu2dens=par_mu2dens_beta() , bvm=13){ - UseMethod("r_mu2density", par_mu2dens) -} - -#' The density function for parasite densities as a function of the mean -#' -#' @param xi a vector of probabilities for \eqn{log_{10}} parasite densities -#' @param mu the expected value for \eqn{log_{10}} parasite densities -#' @param par_mu2dens parameters defining parasite densities as a function of the mu -#' @param bvm blood volume as \eqn{log_{10}} red blood cells -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -p_mu2density = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - UseMethod("p_mu2density", par_mu2dens) -} - -#' The quantile function for parasite densities in a simple malaria infection -#' -#' @param xi a vector of quantiles -#' @param mu the expected value for \eqn{log_{10}} parasite densities -#' @param par_mu2dens parameters defining parasite densities as a function of the mu -#' @param bvm blood volume as \eqn{log_{10}} red blood cells -#' -#' @return a [numeric] vector of length(xi) -#' @export -#' -q_mu2density = function(xi, mu, par_mu2dens=par_mu2dens_beta(), bvm=13){ - UseMethod("q_mu2density", par_mu2dens) -} diff --git a/R/parasite_dens_simple.R b/R/parasite_dens_simple.R deleted file mode 100644 index d92a5c2..0000000 --- a/R/parasite_dens_simple.R +++ /dev/null @@ -1,46 +0,0 @@ - -#' Compute \eqn{P_\tau(a |h)} -#' -#' @description -#' Compute \deqn{P_\tau(a| h) \sim f_P(\xi; a, \tau |h ) = \int_0^a \Omega(\xi|F_\mu(\alpha)) \; f_A(\alpha; a, \tau | h) d\alpha} -#' -#' @param xi log10 -#' @param a host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' @param par_RBC parameters to compute [log10RBC] -#' @param par_Fmu parameters to compute [alpha2mu] -#' @param par_mu2dens parameters to compute [d_mu2density] -#' @param pWda parameters to dispatch [Wda] -#' -#' @return a [numeric] vector of length(x) -#' @export -d_Pdensity = function(xi, a, FoIpar, tau=0, - hhat=1, r=1/200, - par_RBC = par_lRBC_static(), - par_Fmu=par_Fmu_base(), - par_mu2dens = par_mu2dens_beta(), - pWda=par_Wda_none()){ - - simpleDensities = function(x, a, FoIpar, tau, hhat, r, lRBC, m, W, par_Fmu, par_mu2dens){ - Pa = function(alpha, x, W, a, m){ - mu = alpha2mu(alpha, W, par_Fmu) - y = zda(alpha, a, FoIpar, tau, hhat, r) - d_mu2density(x, mu, par_mu2dens, lRBC)*y/m - } - lowlim = 8 - uplim = min(a, 6*365) - dff = stats::integrate(dAoI, lowlim, a, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r)$value - stats::integrate(Pa, lowlim, uplim, x=x, W=W, a=a, m=m)$value/dff - } - - m = meanMoI(a, FoIpar, tau, hhat, r) - W = Wda(a, FoIpar, tau, hhat, pWda) - lRBC = log10RBC(a, par_RBC) - if(length(xi)==1) return(simpleDensities(xi, a, FoIpar, tau, hhat, r, - lRBC, m, W, par_Fmu, par_mu2dens)) - return(sapply(xi, simpleDensities, a=a, FoIpar=FoIpar, tau=tau, hhat=hhat, r=r, - lRBC=lRBC, m=m, W=W, par_Fmu=par_Fmu, par_mu2dens=par_mu2dens)) -} diff --git a/R/prevalence.R b/R/prevalence.R deleted file mode 100644 index 9623937..0000000 --- a/R/prevalence.R +++ /dev/null @@ -1,17 +0,0 @@ - -#' Compute the true PR in a cohort as a function of age and exposure -#' -#' @param a the host cohort age -#' @param FoIpar parameters that define an FoI function -#' @param tau the cohort birthday -#' @param hhat a local scaling parameter for the FoI -#' @param r the clearance rate for a simple infection -#' -#' @return a [numeric] vector of length(a) -#' @export -#' -truePRa = function(a, FoIpar, tau=0, hhat=1, r=1/200){ - 1-exp(-meanMoI(a, FoIpar, tau, hhat, r)) -} - - diff --git a/R/sample-interface.R b/R/sample-interface.R new file mode 100644 index 0000000..7b39860 --- /dev/null +++ b/R/sample-interface.R @@ -0,0 +1,99 @@ +#' The probability of detecting parasites +#' +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_detect = function(xi, bvm=13, pars=par_nb()){ + UseMethod("d_detect", pars) +} + +#' The PDF for counting \eqn{x} parasites +#' +#' @param x raw parasite counts +#' @param xi mean \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_counts = function(x, xi, bvm=13, pars=par_nb()){ + UseMethod("d_counts", pars) +} + +#' The CDF for counting \eqn{x} parasites +#' +#' @param x raw parasite counts +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +p_counts = function(x, xi, bvm=13, pars=par_nb()){ + UseMethod("p_counts", pars) +} + +#' The PDF for non-zero counts, \eqn{\log_{10}} transformed +#' +#' @param hatxi \eqn{\log_{10}} parasite counts +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_nz_counts_log = function(hatxi, xi, bvm=13, pars=par_nb()){ + nz = 1-d_detect(xi, bvm, pars) + dc = d_counts(10^hatxi, xi, bvm, pars) + return(dc/nz) +} + +#' The CDF for non-zero counts, \eqn{\log_{10}} transformed +#' +#' @param hatxi \eqn{\log_{10}} parasite counts +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +p_nz_counts_log = function(hatxi, xi, bvm=13, pars=par_nb()){ + nz = 1-d_detect(xi, bvm, pars) + dc = p_counts(10^hatxi, xi, bvm, pars) + return(dc/nz) +} + +#' The binned PDF for non-zero counts, \eqn{\log_{10}} transformed +#' +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bins breakpoints for summarizing outputs as \eqn{\log_{10}} counts +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +d_nz_counts_log_binned = function(xi, bins=NULL, bvm=13, pars=par_nb()){ + if(is.null(bins)) bins = c(1:5,13) + p0 = d_detect(xi, bvm, pars) + p1 = p_counts(10^bins, xi, bvm, pars) + diff(c(1-p0,p1))/p0 +} + +#' The binned PDF for non-zero counts, \eqn{\log_{10}} transformed +#' +#' @param xi \eqn{\log_{10}} parasite densities +#' @param bins breakpoints for summarizing outputs as \eqn{\log_{10}} counts +#' @param bvm blood volume as \eqn{\log_{10}} red blood cells +#' @param pars parameters that define a detection function +#' +#' @return binary detection result +#' @export +p_nz_counts_log_binned = function(xi, bins=NULL, bvm=13, pars=par_nb()){ + if(is.null(bins)) bins = c(1:5,13) + p0 = d_detect(xi, bvm, pars) + p1 = p_counts(10^bins, xi, bvm, pars)-p0 + p1/p0 +} diff --git a/R/sample-nb.R b/R/sample-nb.R new file mode 100644 index 0000000..0fa6c6b --- /dev/null +++ b/R/sample-nb.R @@ -0,0 +1,47 @@ + +#' Parameters for negative binomial sampling +#' +#' @param sz the negative binomial size parameter +#' @param s sample volume as log10 RBCs +#' +#' @return binary detection result +#' @export +#' +par_nb = function(sz=0.31, s=6){ + par = list() + class(par) <- "nb" + par$sz=sz + par$s=6 + par +} + +#' Detection of infection given parasitemia +#' +#' @inheritParams d_detect +#' +#' @return binary detection result +#' @export +d_detect.nb = function(xi, bvm=13, pars=par_nb()){with(pars,{ + 1-stats::dnbinom(0, mu=10^(xi+s-bvm), size=sz) +})} + +#' Negative binomial PDF for raw parasite counts +#' +#' @inheritParams d_counts +#' +#' @return binary detection result +#' @export +d_counts.nb = function(x, xi, bvm=13, pars=par_nb()){with(pars,{ + stats::dnbinom(x, mu=10^(xi+s-bvm), size=sz) +})} + +#' Detection of infection given parasitemia +#' +#' @inheritParams p_counts +#' +#' @return binary detection result +#' @export +p_counts.nb = function(x, xi, bvm=13, pars=par_nb()){with(pars,{ + stats::pnbinom(x, mu=10^(xi+s-bvm), size=sz) +})} + diff --git a/R/sample-pois.R b/R/sample-pois.R new file mode 100644 index 0000000..65933a1 --- /dev/null +++ b/R/sample-pois.R @@ -0,0 +1,43 @@ + +#' Parameters for Poisson sampling +#' @param s sample volume as log10 RBCs +#' @return par a [list] +#' @export +par_pois = function(s=6){ + par = list() + class(par) <- "pois" + par$s=s + par +} + +#' Detection of infection given parasitemia +#' +#' @inheritParams d_detect +#' +#' @return binary detection result +#' @export +d_detect.pois = function(xi, bvm=13, pars=par_pois()){with(pars,{ + 1-stats::dpois(0, 10^(xi+s-bvm)) +})} + +#' Detection of infection given parasitemia +#' +#' @inheritParams d_counts +#' +#' @return binary detection result +#' @export +d_counts.pois = function(x, xi, bvm=13, pars=par_pois()){with(pars,{ + stats::dpois(x, 10^(xi+s-bvm)) +})} + +#' Detection of infection given parasitemia +#' +#' @inheritParams p_counts +#' +#' @return binary detection result +#' @export +p_counts.pois = function(x, xi, bvm=13, pars=par_pois()){with(pars,{ + q = 10^(s-bvm) + stats::ppois(x, q*10^xi) +})} + diff --git a/_pkgdown.yml b/_pkgdown.yml index 1d5c025..0ab4695 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -13,6 +13,8 @@ navbar: href: articles/Dynamics.html - text: Hybrid Models href: articles/Hybrid.html + - text: MoI + href: articles/MoI.html - text: Parasite menu: - text: Parasite Densities @@ -40,7 +42,7 @@ reference: Dynamics of MoI, AoI, and the AoY contents: - zda - - truePRa + - truePR - subtitle: Multiplicity of Infection (MoI) desc: | Methods to compute the MoI @@ -88,35 +90,42 @@ reference: - title: Parasite Densities desc: | Expected densities by AoI -- subtitle: mu(alpha) +- subtitle: F_mu(alpha) desc: | Expected log10 parasites (mu) from the AoI (alpha) contents: - - alpha2mu - - salpha2mu - - alpha2mu.W + - Fmu + - sFmu + - Fmu.W - par_Fmu_W - - alpha2mu.base + - Fmu.base - par_Fmu_base - - alpha2mu.chronic + - Fmu.chronic - par_Fmu_chronic - subtitle: P(mu) desc: | log10 parasites distributions from mu contents: - - d_mu2density - - p_mu2density - - q_mu2density - - r_mu2density - - par_mu2dens_beta + - d_Omega + - p_Omega + - q_Omega + - r_Omega + - par_Omega_beta - subtitle: P(mu) desc: | log10 parasites distributions from mu contents: - - d_mu2density.beta - - p_mu2density.beta - - q_mu2density.beta - - r_mu2density.beta + - d_Omega.beta + - dbeta1 + - p_Omega.beta + - pbeta1 + - q_Omega.beta + - qbeta1 + - r_Omega.beta + - rbeta1 + - sigma_mu + - sigma_mu.abc + - par_sigma_abc - subtitle: P(alpha) desc: | log10 parasites from AoI (alpha) @@ -129,15 +138,17 @@ reference: desc: | Parasite density distributions by host cohort age contents: - - d_Pdensity + - d_clone_density + - moments_clone_density - subtitle: Complex Infections desc: | Expected densities by AoI contents: - - Bdensity - - d_Bdensity - - p_Bdensity - - r_Bdensity + - parasite_density + - d_parasite_density + - p_parasite_density + - r_parasite_density + - moments_parasite_density - rRda - subtitle: Convolutions desc: | @@ -147,43 +158,55 @@ reference: - cdfConvolve2 - cdfConvolve2a - cdfConvolve2b -- title: Parasite Detection -- subtitle: Observed prevalence +- title: Sampling +- subtitle: Generic Functions desc: | Parasite positivity contents: - - Detect - - Detect.nb - - Detect.pois - - DetectBda - - DetectPM - - DetectPa - - par_nbCounts - - par_poisCounts -- subtitle: Observed multiplicity of Infection + - d_detect + - d_counts + - p_counts + - d_nz_counts_log + - p_nz_counts_log + - d_nz_counts_log_binned + - p_nz_counts_log_binned +- subtitle: Poisson Sampling + contents: + - par_pois + - d_detect.pois + - p_counts.pois + - d_counts.pois +- subtitle: Negative Binomial Sampling + contents: + - par_nb + - d_detect.nb + - p_counts.nb + - d_counts.nb +- title: Parasite Detection and Counts +- subtitle: Observed Prevalence + desc: | + Detection and observed prevalence + contents: + - d_detect_mesh + - d_clone_detect + - d_parasite_detect_moi + - d_parasite_detect + - FQ +- subtitle: Observed MoI desc: | - Unique parasite types + Number of Clones Counted contents: - - MoIPM + - d_moi_count - subtitle: Counts desc: | Parasite counts contents: - - pCounts - - pCounts.nb - - pCounts.pois - - dCounts - - dCountsPa - - pCountsPa - - meanCountsPa - - dCounts.nb - - dCounts.pois - - dCountsBa - - pCountsBa - - meanCountsBa - - binnedCounts - - binnedCounts.nb - - binnedCounts.pois + - d_clone_counts + - p_clone_counts + - mean_clone_counts + - d_parasite_counts + - p_parasite_counts + - mean_parasite_counts - title: Force of Infection desc: | Methods to set up FoI trace functions @@ -237,14 +260,4 @@ reference: - log10RBC - log10RBC.static - par_lRBC_static -- subtitle: beta distribution - desc: | - A modified beta distribution - contents: - - dbeta1 - - pbeta1 - - qbeta1 - - rbeta1 - - sigma_mu - - sigma_mu.abc - - par_sigma_abc + diff --git a/docs/404.html b/docs/404.html index 0a2a4b9..8571752 100644 --- a/docs/404.html +++ b/docs/404.html @@ -42,6 +42,7 @@ FoI Dynamics Hybrid Models + MoI