├── vignettes ├── .gitignore ├── figures │ ├── gen_dist_mev_plot-1.png │ └── gen_dist_compare_ebov-1.png ├── variant-surveillance-decision-tree-01.png ├── variant-surveillance-decision-tree-02.png ├── variant-surveillance-decision-tree-03.png ├── variant-surveillance-decision-tree-04.png ├── variant-surveillance-decision-tree-05.png └── variant-surveillance-decision-tree-06.png ├── docs ├── _config.yml ├── reference │ ├── Rplot001.png │ └── figures │ │ ├── lifecycle-stable.svg │ │ ├── lifecycle-defunct.svg │ │ ├── lifecycle-archived.svg │ │ ├── lifecycle-maturing.svg │ │ ├── lifecycle-deprecated.svg │ │ ├── lifecycle-superseded.svg │ │ ├── lifecycle-experimental.svg │ │ └── lifecycle-questioning.svg ├── articles │ ├── variant-surveillance-decision-tree-01.png │ ├── variant-surveillance-decision-tree-02.png │ ├── variant-surveillance-decision-tree-03.png │ ├── variant-surveillance-decision-tree-04.png │ ├── variant-surveillance-decision-tree-05.png │ ├── variant-surveillance-decision-tree-06.png │ ├── V4_FullExamples_files │ │ ├── figure-html │ │ │ ├── gen_dist_mev_plot-1.png │ │ │ └── gen_dist_compare_ebov-1.png │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.10 │ │ │ └── header-attrs.js │ ├── L4_IllustrativeExamples_files │ │ └── figure-html │ │ │ ├── gen_dist_mev_plot-1.png │ │ │ └── gen_dist_compare_ebov-1.png │ ├── V2_SampleSize_files │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.10 │ │ │ └── header-attrs.js │ ├── V1_FalseDicoveryRate_files │ │ ├── header-attrs-2.1 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.10 │ │ │ └── header-attrs.js │ └── V3_SensitivitySpecificity_files │ │ ├── header-attrs-2.1 │ │ └── header-attrs.js │ │ └── header-attrs-2.10 │ │ └── header-attrs.js ├── pkgdown.yml ├── link.svg ├── bootstrap-toc.css └── docsearch.js ├── .gitignore ├── man-roxygen ├── alpha.R ├── p_a.R ├── power.R ├── N.R ├── sensitivity.R ├── specificity.R ├── R_a.R ├── R_b.R ├── alternative.R ├── rho.R └── overdispersion.R ├── data └── genDistSim.rda ├── tests ├── testthat.R └── testthat │ ├── test-true_pairs_stsl.R │ ├── test-obs_pairs_stsl.R │ ├── test-samplesize.R │ ├── test-prob_trans_stsl.R │ ├── test-true_pairs_mtml.R │ ├── test-true_pairs_mtsl.R │ ├── test-obs_pairs_mtml.R │ ├── test-obs_pairs_mtsl.R │ ├── test-prob_trans_mtml.R │ ├── test-prob_trans_mtsl.R │ ├── test-true_pairs.R │ ├── test-exp_links.R │ ├── test-truediscoveryrate.R │ ├── test-falsediscoveryrate.R │ ├── test-gen_dists.R │ ├── test-sens_spec_roc.R │ ├── test-sens_spec_calc.R │ ├── test-get_optim_roc.R │ ├── test-optim_roc_threshold.R │ ├── test-relR_power.R │ ├── _snaps │ ├── gen_dists.md │ ├── get_optim_roc.md │ ├── true_pairs_stsl.md │ ├── true_pairs_mtml.md │ ├── true_pairs_mtsl.md │ ├── sens_spec_calc.md │ ├── sens_spec_roc.md │ ├── prob_trans_stsl.md │ ├── prob_trans_mtml.md │ ├── prob_trans_mtsl.md │ ├── obs_pairs_stsl.md │ ├── obs_pairs_mtml.md │ ├── obs_pairs_mtsl.md │ ├── true_pairs.md │ ├── truediscoveryrate.md │ ├── exp_links.md │ └── falsediscoveryrate.md │ ├── test-relR_power_simulated.R │ ├── test-translink_samplesize.R │ ├── test-vartrack_prob_prev.R │ ├── test-vartrack_samplesize_prev.R │ ├── test-varfreq_expected_mbias.R │ ├── test-translink_expected_links_true.R │ ├── test-translink_expected_links_obs.R │ ├── test-translink_prob_transmit.R │ ├── test-relR_samplesize_basic.R │ ├── test-translink_expected_links_true_stsl.R │ ├── test-gendist_sensspec_cutoff.R │ ├── test-vartrack_samplesize_detect.R │ ├── test-translink_expected_links_obs_stsl.R │ ├── test-gendist_distribution.R │ ├── test-translink_tdr.R │ ├── test-vartrack_prob_detect.R │ ├── test-translink_fdr.R │ ├── test-gendist_roc_format.R │ ├── test-translink_expected_links_true_mtml.R │ ├── test-translink_expected_links_true_mtsl.R │ ├── test-translink_expected_links_obs_mtml.R │ ├── test-translink_expected_links_obs_mtsl.R │ ├── test-vartrack_prob_detect_xsect.R │ ├── test-varfreq_obs_freq.R │ ├── test-varfreq_cdf_logistic.R │ ├── test-translink_prob_transmit_mtml.R │ ├── test-translink_prob_transmit_mtsl.R │ ├── test-translink_prob_transmit_stsl.R │ ├── test-vartrack_prob_prev_xsect.R │ ├── test-vartrack_samplesize_detect_xsect.R │ └── test-varfreq_freq_logistic.R ├── CRAN-SUBMISSION ├── cran-comments.md ├── R ├── phylosamp-package.R ├── genDistSim.R ├── utils.R ├── varfreq_obs_freq.R ├── varfreq_expected_mbias.R ├── varfreq_freq_logistic.R ├── varfreq_cdf_logistic.R ├── vartrack_prob_detect_xsect.R ├── translink_expected_links_true_stsl.R ├── vartrack_samplesize_detect_xsect.R ├── true_pairs_stsl.R ├── vartrack_prob_prev_xsect.R ├── optim_roc_threshold.R ├── translink_expected_links_true_mtsl.R ├── vartrack_prob_prev.R ├── get_optim_roc.R ├── vartrack_samplesize_prev_xsect.R ├── true_pairs_mtsl.R ├── vartrack_samplesize_prev.R ├── translink_expected_links_true_mtml.R ├── translink_expected_links_obs_stsl.R ├── true_pairs_mtml.R └── obs_pairs_stsl.R ├── .Rbuildignore ├── NEWS.md ├── man ├── genDistSim.Rd ├── figures │ ├── lifecycle-stable.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-archived.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-superseded.svg │ ├── lifecycle-experimental.svg │ └── lifecycle-questioning.svg ├── varfreq_obs_freq.Rd ├── varfreq_expected_mbias.Rd ├── phylosamp-package.Rd ├── varfreq_freq_logistic.Rd ├── varfreq_cdf_logistic.Rd ├── true_pairs_stsl.Rd ├── true_pairs_mtsl.Rd ├── obs_pairs_stsl.Rd ├── true_pairs_mtml.Rd ├── obs_pairs_mtsl.Rd ├── optim_roc_threshold.Rd ├── prob_trans_mtsl.Rd ├── true_pairs.Rd ├── vartrack_prob_detect_xsect.Rd ├── prob_trans_stsl.Rd ├── samplesize.Rd ├── gendist_distribution.Rd ├── relR_power_simulated.Rd ├── vartrack_prob_prev_xsect.Rd ├── vartrack_samplesize_detect_xsect.Rd ├── obs_pairs_mtml.Rd ├── gen_dists.Rd ├── prob_trans_mtml.Rd ├── vartrack_samplesize_prev_xsect.Rd ├── relR_samplesize_basic.Rd ├── relR_samplesize_opterr.Rd ├── vartrack_prob_prev.Rd ├── translink_expected_links_true_stsl.Rd ├── get_optim_roc.Rd ├── relR_power.Rd ├── translink_expected_links_true_mtsl.Rd ├── vartrack_samplesize_prev.Rd ├── relR_samplesize_solve.Rd └── gendist_sensspec_cutoff.Rd ├── DESCRIPTION ├── inst └── CITATION └── NAMESPACE /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.R 2 | *.html -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.Rhistory 3 | .pre-commit-config.yaml 4 | .Rproj.user 5 | -------------------------------------------------------------------------------- /man-roxygen/alpha.R: -------------------------------------------------------------------------------- 1 | ##' @param alpha Numeric. The desired alpha level. Default: 0.05 2 | -------------------------------------------------------------------------------- /data/genDistSim.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/data/genDistSim.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(phylosamp) 3 | 4 | test_check("phylosamp") 5 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 1.0.1 2 | Date: 2023-05-23 21:59:50 UTC 3 | SHA: d4bc92fd4f39d362ba7907b89631bbc7189c249c 4 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 1 note 4 | 5 | * This is a new release. 6 | -------------------------------------------------------------------------------- /man-roxygen/p_a.R: -------------------------------------------------------------------------------- 1 | #' @param p_a Numeric. The proportion of the population in group `a`. Must be 2 | #' between 0 and 1. 3 | -------------------------------------------------------------------------------- /man-roxygen/power.R: -------------------------------------------------------------------------------- 1 | ##' @param power Numeric. The desired power. Must be a value between 0 and 1. 2 | ##' Default: 0.8. 3 | -------------------------------------------------------------------------------- /vignettes/figures/gen_dist_mev_plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/figures/gen_dist_mev_plot-1.png -------------------------------------------------------------------------------- /man-roxygen/N.R: -------------------------------------------------------------------------------- 1 | ##' @param N Numeric (Positive). The size of the infected pool. Only one of 2 | ##' `rho` or `N` should be specified. 3 | -------------------------------------------------------------------------------- /vignettes/figures/gen_dist_compare_ebov-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/figures/gen_dist_compare_ebov-1.png -------------------------------------------------------------------------------- /man-roxygen/sensitivity.R: -------------------------------------------------------------------------------- 1 | ##' @param sensitivity Numeric. The sensitivity of the linkage criteria. 2 | ##' Must be between 0 and 1. Default: 1. 3 | -------------------------------------------------------------------------------- /man-roxygen/specificity.R: -------------------------------------------------------------------------------- 1 | ##' @param specificity Numeric. The specificity of the linkage criteria. 2 | ##' Must be between 0 and 1. Default: 1. 3 | -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-01.png -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-02.png -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-03.png -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-04.png -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-05.png -------------------------------------------------------------------------------- /vignettes/variant-surveillance-decision-tree-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/vignettes/variant-surveillance-decision-tree-06.png -------------------------------------------------------------------------------- /man-roxygen/R_a.R: -------------------------------------------------------------------------------- 1 | #' @param R_a Numeric (Positive). The assumed R among the group in the 2 | #' denominator of the ratio. Input value must be greater than 0. 3 | -------------------------------------------------------------------------------- /man-roxygen/R_b.R: -------------------------------------------------------------------------------- 1 | #' @param R_b Numeric (Positive). The assumed R among the group in the 2 | #' numerator of the ratio. Input value must be greater than 0. 3 | -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-01.png -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-02.png -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-03.png -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-04.png -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-05.png -------------------------------------------------------------------------------- /docs/articles/variant-surveillance-decision-tree-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/variant-surveillance-decision-tree-06.png -------------------------------------------------------------------------------- /man-roxygen/alternative.R: -------------------------------------------------------------------------------- 1 | ##' @param alternative Character. Specifies the alternative hypothesis. 2 | ##' Must be: `two_sided` (Default), `less`, or `greater` 3 | -------------------------------------------------------------------------------- /R/phylosamp-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom lifecycle deprecated 6 | ## usethis namespace: end 7 | NULL 8 | -------------------------------------------------------------------------------- /man-roxygen/rho.R: -------------------------------------------------------------------------------- 1 | ##' @param rho Numeric. The proportion of the infected pool sampled. 2 | ##' Only one of `rho` or `N` should be specified. Values should be between 0 3 | ##' and 1. 4 | -------------------------------------------------------------------------------- /docs/articles/V4_FullExamples_files/figure-html/gen_dist_mev_plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/V4_FullExamples_files/figure-html/gen_dist_mev_plot-1.png -------------------------------------------------------------------------------- /tests/testthat/test-true_pairs_stsl.R: -------------------------------------------------------------------------------- 1 | test_that("true_pairs_stsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(true_pairs_stsl(eta = 1, rho = 1, M = 10), 5) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /docs/articles/V4_FullExamples_files/figure-html/gen_dist_compare_ebov-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/V4_FullExamples_files/figure-html/gen_dist_compare_ebov-1.png -------------------------------------------------------------------------------- /tests/testthat/test-obs_pairs_stsl.R: -------------------------------------------------------------------------------- 1 | test_that("obs_pairs_stsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(obs_pairs_stsl(eta = 1, chi = 1, rho = 1, M = 10), 5) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-samplesize.R: -------------------------------------------------------------------------------- 1 | test_that("sampleize is deprecated", { 2 | expect_snapshot({ 3 | expect_error(samplesize(eta = 0, chi = 0.995, N = 100, R = 1, phi = 0.75)) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-prob_trans_stsl.R: -------------------------------------------------------------------------------- 1 | test_that("prob_trans_stsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(prob_trans_stsl(eta = 1, chi = 1, rho = 1, M = 10), 1) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-true_pairs_mtml.R: -------------------------------------------------------------------------------- 1 | test_that("true_pairs_mtml is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(true_pairs_mtml(eta = 1, rho = 1, M = 10, R = 1), 10) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-true_pairs_mtsl.R: -------------------------------------------------------------------------------- 1 | test_that("true_pairs_mtsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(true_pairs_mtsl(eta = 1, rho = 1, M = 10, R = 1), 10) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /docs/articles/L4_IllustrativeExamples_files/figure-html/gen_dist_mev_plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/L4_IllustrativeExamples_files/figure-html/gen_dist_mev_plot-1.png -------------------------------------------------------------------------------- /tests/testthat/test-obs_pairs_mtml.R: -------------------------------------------------------------------------------- 1 | test_that("obs_pairs_mtml is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(obs_pairs_mtml(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 10) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-obs_pairs_mtsl.R: -------------------------------------------------------------------------------- 1 | test_that("obs_pairs_mtsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(obs_pairs_mtsl(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 10) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-prob_trans_mtml.R: -------------------------------------------------------------------------------- 1 | test_that("prob_trans_mtml is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(prob_trans_mtml(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 1) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-prob_trans_mtsl.R: -------------------------------------------------------------------------------- 1 | test_that("prob_trans_mtsl is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(prob_trans_mtsl(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 1) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^data-raw$ 4 | ^figures$ 5 | ^doc$ 6 | ^docs$ 7 | ^Meta$ 8 | ^_pkgdown\.yml$ 9 | ^pkgdown$ 10 | ^man-roxygen$ 11 | ^cran-comments\.md$ 12 | ^CRAN-SUBMISSION$ 13 | -------------------------------------------------------------------------------- /docs/articles/L4_IllustrativeExamples_files/figure-html/gen_dist_compare_ebov-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HopkinsIDD/phylosamp/HEAD/docs/articles/L4_IllustrativeExamples_files/figure-html/gen_dist_compare_ebov-1.png -------------------------------------------------------------------------------- /tests/testthat/test-true_pairs.R: -------------------------------------------------------------------------------- 1 | test_that("true_pairs is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(true_pairs(eta = 1, rho = 1, M = 10, R = NULL, assumption = "stsl"), 4 | 5) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # phylosamp 1.0.1 2 | 3 | * Added a `NEWS.md` file to track changes to the package. 4 | * Added `relR_*` functions to the package to allow for sample size and power calculations when estimating differential transmission between groups -------------------------------------------------------------------------------- /tests/testthat/test-exp_links.R: -------------------------------------------------------------------------------- 1 | test_that("exp_links is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(exp_links(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, assumption = "stsl"), 4 | 5) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-truediscoveryrate.R: -------------------------------------------------------------------------------- 1 | test_that("truediscoveryrate is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(truediscoveryrate(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, 4 | assumption = "stsl"), 1) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-falsediscoveryrate.R: -------------------------------------------------------------------------------- 1 | test_that("falsediscoveryrate is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(falsediscoveryrate(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, 4 | assumption = "stsl"), 0) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-gen_dists.R: -------------------------------------------------------------------------------- 1 | test_that("gen_dists is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(gen_dists(mut_rate = 1, mean_gens_pdf = c(0.2, 0.2, 0.2, 0.2, 4 | 0.2), max_dist = 0)[, "linked_prob"][[1]], 1) 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-sens_spec_roc.R: -------------------------------------------------------------------------------- 1 | test_that("sens_spec_roc is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(sens_spec_roc(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 4 | 0.08, 0.15, 0.75), max_link_gens = 1)[2, "sensitivity"][[1]], 0.7357589, 5 | tolerance = 0.01) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-sens_spec_calc.R: -------------------------------------------------------------------------------- 1 | test_that("sens_spec_calc is deprecated", { 2 | expect_snapshot({ 3 | expect_equal(sens_spec_calc(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 4 | 0.08, 0.15, 0.75), max_link_gens = 1)[1, "sensitivity"][[1]], 0.7357589, 5 | tolerance = 0.01) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-get_optim_roc.R: -------------------------------------------------------------------------------- 1 | test_that("get_optim_roc is deprecated", { 2 | expect_snapshot({ 3 | x <- as.data.frame(matrix(c(1, 0, 0, 2, 0.75, 0.25, 3, 1, 1), ncol = 3, byrow = TRUE, 4 | dimnames = list(NULL, c("cutoff", "sensitivity", "specificity")), )) 5 | 6 | expect_equal(get_optim_roc(x)$cutoff, 2) 7 | }) 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-optim_roc_threshold.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("optim_roc_threshold finds point nearest (0,1) corner", { 3 | 4 | x <- as.data.frame(matrix(c(1, 0, 0, 2, 0.75, 0.25, 3, 1, 1), ncol = 3, byrow = TRUE, 5 | dimnames = list(NULL, c("cutoff", "sensitivity", "specificity")), )) 6 | 7 | expect_equal(optim_roc_threshold(x)$cutoff, 2) 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-relR_power.R: -------------------------------------------------------------------------------- 1 | test_that("Simple power works without overdispersion", { 2 | p <- relR_power(665, 1.5, 2, 0.5, 1000) 3 | expect_equal(round(p, 1), 0.8) 4 | }) 5 | 6 | test_that("Simple power works with overdispersion", { 7 | p <- relR_power(983, 1.5, 2, 0.5, 1000, overdispersion = 350) 8 | expect_equal(round(p, 1), 0.8) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/gen_dists.md: -------------------------------------------------------------------------------- 1 | # gen_dists is deprecated 2 | 3 | Code 4 | expect_equal(gen_dists(mut_rate = 1, mean_gens_pdf = c(0.2, 0.2, 0.2, 0.2, 0.2), 5 | max_dist = 0)[, "linked_prob"][[1]], 1) 6 | Warning 7 | `gen_dists()` was deprecated in phylosamp 1.0.0. 8 | i Please use `gendist_distribution()` instead. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/test-relR_power_simulated.R: -------------------------------------------------------------------------------- 1 | test_that("Function works under Poisson assumption", { 2 | p <- relR_power_simulated(665, 1.5, 2, 0.5, 1000) 3 | expect_equal(round(p, 1), 0.8) 4 | }) 5 | 6 | 7 | test_that("Function works under Negative Binomial assumption", { 8 | p <- relR_power_simulated(983, 1.5, 2, 0.5, 1000, overdispersion = 350) 9 | expect_equal(round(p, 1), 0.8) 10 | }) 11 | 12 | -------------------------------------------------------------------------------- /man-roxygen/overdispersion.R: -------------------------------------------------------------------------------- 1 | ##' @param overdispersion Numeric (Positive). An overdispersion parameter, set 2 | ##' if the assumed distribution of the number of edges is negative binomial. 3 | ##' If `NULL` the assumed distribution is Poisson (equivalent to an 4 | ##' overdispersion parameter of infinity) Default: `NULL` Note that this is 5 | ##' equivalent to setting the overdispersion parameter to `Inf`. 6 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/get_optim_roc.md: -------------------------------------------------------------------------------- 1 | # get_optim_roc is deprecated 2 | 3 | Code 4 | x <- as.data.frame(matrix(c(1, 0, 0, 2, 0.75, 0.25, 3, 1, 1), ncol = 3, byrow = TRUE, 5 | dimnames = list(NULL, c("cutoff", "sensitivity", "specificity")), )) 6 | expect_equal(get_optim_roc(x)$cutoff, 2) 7 | Warning 8 | `get_optim_roc()` was deprecated in phylosamp 1.0.0. 9 | i Please use `optim_roc_threshold()` instead. 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/true_pairs_stsl.md: -------------------------------------------------------------------------------- 1 | # true_pairs_stsl is deprecated 2 | 3 | Code 4 | expect_equal(true_pairs_stsl(eta = 1, rho = 1, M = 10), 5) 5 | Warning 6 | `true_pairs_stsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_true_stsl()` instead. 8 | The `eta` argument of `true_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_true_stsl()` instead. 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/true_pairs_mtml.md: -------------------------------------------------------------------------------- 1 | # true_pairs_mtml is deprecated 2 | 3 | Code 4 | expect_equal(true_pairs_mtml(eta = 1, rho = 1, M = 10, R = 1), 10) 5 | Warning 6 | `true_pairs_mtml()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_true_mtml()` instead. 8 | The `eta` argument of `true_pairs_mtml()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_true_mtml()` instead. 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/true_pairs_mtsl.md: -------------------------------------------------------------------------------- 1 | # true_pairs_mtsl is deprecated 2 | 3 | Code 4 | expect_equal(true_pairs_mtsl(eta = 1, rho = 1, M = 10, R = 1), 10) 5 | Warning 6 | `true_pairs_mtsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_true_mtsl()` instead. 8 | The `eta` argument of `true_pairs_mtsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_true_mtsl()` instead. 10 | 11 | -------------------------------------------------------------------------------- /R/genDistSim.R: -------------------------------------------------------------------------------- 1 | ##' Simulations of the genetic distance distribution 2 | ##' 3 | ##' This data object contains the genetic distance distributions 4 | ##' for 168 values of \eqn{R} between 1.3 and 18. The distributions represent the 5 | ##' the average of 1000 simulations for each value, which can be used as a 6 | ##' reasonable proxy for the generation distribution for large outbreaks. 7 | ##' 8 | ##' @format dataframe 9 | ##' 10 | ##' @author Shirlee Wohl, John Giles, and Justin Lessler 11 | ##' 12 | ##' @examples 13 | ##' data(genDistSim) 14 | ##' 15 | "genDistSim" 16 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/sens_spec_calc.md: -------------------------------------------------------------------------------- 1 | # sens_spec_calc is deprecated 2 | 3 | Code 4 | expect_equal(sens_spec_calc(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 5 | 0.08, 0.15, 0.75), max_link_gens = 1)[1, "sensitivity"][[1]], 0.7357589, 6 | tolerance = 0.01) 7 | Warning 8 | `sens_spec_calc()` was deprecated in phylosamp 1.0.0. 9 | i Please use `gendist_sensspec_cutoff()` instead. 10 | `gen_dists()` was deprecated in phylosamp 1.0.0. 11 | i Please use `gendist_distribution()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_samplesize.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_samplesize fails when sensitivity 0", { 3 | 4 | expect_error(translink_samplesize(sensitivity = 0, specificity = 0.995, N = 100, 5 | R = 1, tdr = 0.75)) 6 | 7 | }) 8 | 9 | 10 | test_that("translink_samplesize fails when parameters invalid", { 11 | 12 | expect_error(translink_samplesize(sensitivity = 0.99, specificity = 0.995, N = 100, 13 | R = 1, tdr = 2)) 14 | 15 | expect_error(translink_samplesize(sensitivity = 0.99, specificity = 0.995, N = 100, 16 | R = 1, tdr = -2)) 17 | }) 18 | -------------------------------------------------------------------------------- /docs/articles/V2_SampleSize_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V2_SampleSize_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V4_FullExamples_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V4_FullExamples_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V1_FalseDicoveryRate_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V1_FalseDicoveryRate_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V3_SensitivitySpecificity_files/header-attrs-2.1/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/V3_SensitivitySpecificity_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_prob_prev.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_prob_prev input arguments are valid", { 2 | 3 | expect_error(vartrack_prob_prev(p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "fake"), 4 | "sampling frequency argument") 5 | expect_error(vartrack_prob_prev(p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "cont"), 6 | "not yet implemented") 7 | }) 8 | 9 | test_that("vartrack_prob_prev return object is valid double", { 10 | 11 | expect_type(vartrack_prob_prev(p_v1 = 0.1, n = 30, omega = 0.9, precision = 0.1, c_ratio = 1.5, sampling_freq = "xsect"), "double") 12 | }) 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/sens_spec_roc.md: -------------------------------------------------------------------------------- 1 | # sens_spec_roc is deprecated 2 | 3 | Code 4 | expect_equal(sens_spec_roc(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 5 | 0.08, 0.15, 0.75), max_link_gens = 1)[2, "sensitivity"][[1]], 0.7357589, 6 | tolerance = 0.01) 7 | Warning 8 | `sens_spec_roc()` was deprecated in phylosamp 1.0.0. 9 | i Please use `gendist_roc_format()` instead. 10 | `sens_spec_calc()` was deprecated in phylosamp 1.0.0. 11 | i Please use `gendist_sensspec_cutoff()` instead. 12 | `gen_dists()` was deprecated in phylosamp 1.0.0. 13 | i Please use `gendist_distribution()` instead. 14 | 15 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_samplesize_prev.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_samplesize_prev input arguments are valid", { 2 | 3 | expect_error(vartrack_samplesize_prev(p_v1 = 0.1, prob = 0.9, precision = 0.1, omega = 0.9, c_ratio = 1.5, sampling_freq = "fake"), 4 | "sampling frequency argument") 5 | expect_error(vartrack_samplesize_prev(p_v1 = 0.1, omega = 0.9, c_ratio = 1.5, sampling_freq = "cont"), 6 | "not yet implemented") 7 | }) 8 | 9 | test_that("vartrack_samplesize_prev return object is valid double", { 10 | 11 | expect_type(vartrack_samplesize_prev(p_v1 = 0.1, prob = 0.9, omega = 0.9, precision = 0.1, c_ratio = 1.5, sampling_freq = "xsect"), "double") 12 | }) 13 | 14 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.19.2 2 | pkgdown: 2.0.6 3 | pkgdown_sha: ~ 4 | articles: 5 | L1_FalseDiscoveryRate: L1_FalseDiscoveryRate.html 6 | L2_SampleSize: L2_SampleSize.html 7 | L3_SensitivitySpecificity: L3_SensitivitySpecificity.html 8 | L4_IllustrativeExamples: L4_IllustrativeExamples.html 9 | V1_CoefficientDetectionBias: V1_CoefficientDetectionBias.html 10 | V2_SampleSizeCrossSectional: V2_SampleSizeCrossSectional.html 11 | V3_ProbCrossSectional: V3_ProbCrossSectional.html 12 | V4_SampleSizePeriodic: V4_SampleSizePeriodic.html 13 | V5_ProbDetectPeriodic: V5_ProbDetectPeriodic.html 14 | V6_IllustrativeExample: V6_IllustrativeExample.html 15 | last_built: 2023-05-23T19:43Z 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/prob_trans_stsl.md: -------------------------------------------------------------------------------- 1 | # prob_trans_stsl is deprecated 2 | 3 | Code 4 | expect_equal(prob_trans_stsl(eta = 1, chi = 1, rho = 1, M = 10), 1) 5 | Warning 6 | `prob_trans_stsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_prob_transmit_stsl()` instead. 8 | The `eta` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_prob_transmit_stsl()` instead. 10 | The `chi` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_prob_transmit_stsl()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/prob_trans_mtml.md: -------------------------------------------------------------------------------- 1 | # prob_trans_mtml is deprecated 2 | 3 | Code 4 | expect_equal(prob_trans_mtml(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 1) 5 | Warning 6 | `prob_trans_mtml()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_prob_transmit_mtml()` instead. 8 | The `eta` argument of `prob_trans_mtml()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_prob_transmit_mtml()` instead. 10 | The `chi` argument of `prob_trans_mtml()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_prob_transmit_mtml()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/prob_trans_mtsl.md: -------------------------------------------------------------------------------- 1 | # prob_trans_mtsl is deprecated 2 | 3 | Code 4 | expect_equal(prob_trans_mtsl(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 1) 5 | Warning 6 | `prob_trans_mtsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_prob_transmit_mtsl()` instead. 8 | The `eta` argument of `prob_trans_mtsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_prob_transmit_mtsl()` instead. 10 | The `chi` argument of `prob_trans_mtsl()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_prob_transmit_mtsl()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/obs_pairs_stsl.md: -------------------------------------------------------------------------------- 1 | # obs_pairs_stsl is deprecated 2 | 3 | Code 4 | expect_equal(obs_pairs_stsl(eta = 1, chi = 1, rho = 1, M = 10), 5) 5 | Warning 6 | `obs_pairs_stsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_obs_stsl()` instead. 8 | The `eta` argument of `obs_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_obs_stsl()` instead. 10 | The `chi` argument of `obs_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_expected_links_obs_stsl()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/obs_pairs_mtml.md: -------------------------------------------------------------------------------- 1 | # obs_pairs_mtml is deprecated 2 | 3 | Code 4 | expect_equal(obs_pairs_mtml(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 10) 5 | Warning 6 | `obs_pairs_mtml()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_obs_mtml()` instead. 8 | The `eta` argument of `obs_pairs_mtml()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_obs_mtml()` instead. 10 | The `chi` argument of `obs_pairs_mtml()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_expected_links_obs_mtml()` instead. 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/obs_pairs_mtsl.md: -------------------------------------------------------------------------------- 1 | # obs_pairs_mtsl is deprecated 2 | 3 | Code 4 | expect_equal(obs_pairs_mtsl(eta = 1, chi = 1, rho = 1, M = 10, R = 1), 10) 5 | Warning 6 | `obs_pairs_mtsl()` was deprecated in phylosamp 1.0.0. 7 | i Please use `translink_expected_links_obs_mtsl()` instead. 8 | The `eta` argument of `obs_pairs_mtsl()` is deprecated as of phylosamp 1.0.0. 9 | i Please use the `sensitivity` argument of `translink_expected_links_obs_mtsl()` instead. 10 | The `chi` argument of `obs_pairs_mtsl()` is deprecated as of phylosamp 1.0.0. 11 | i Please use the `specificity` argument of `translink_expected_links_obs_mtsl()` instead. 12 | 13 | -------------------------------------------------------------------------------- /man/genDistSim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genDistSim.R 3 | \docType{data} 4 | \name{genDistSim} 5 | \alias{genDistSim} 6 | \title{Simulations of the genetic distance distribution} 7 | \format{ 8 | dataframe 9 | } 10 | \usage{ 11 | genDistSim 12 | } 13 | \description{ 14 | This data object contains the genetic distance distributions 15 | for 168 values of \eqn{R} between 1.3 and 18. The distributions represent the 16 | the average of 1000 simulations for each value, which can be used as a 17 | reasonable proxy for the generation distribution for large outbreaks. 18 | } 19 | \examples{ 20 | data(genDistSim) 21 | 22 | } 23 | \author{ 24 | Shirlee Wohl, John Giles, and Justin Lessler 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /tests/testthat/test-varfreq_expected_mbias.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("varfreq_expected_mbias input arguments are valid", { 3 | 4 | expect_error(varfreq_expected_mbias(p_v1 = 0, c_ratio = 1)) 5 | 6 | expect_error(varfreq_expected_mbias(p_v1 = TRUE, c_ratio = 1)) 7 | 8 | expect_error(varfreq_expected_mbias(p_v1 = 0.1, c_ratio = -0.1)) 9 | 10 | expect_error(varfreq_expected_mbias(p_v1 = 0.1, c_ratio = "invalid")) 11 | }) 12 | 13 | test_that("varfreq_expected_mbias return object is valid double", { 14 | 15 | expect_type(varfreq_expected_mbias(p_v1 = 0.2, c_ratio = 1.5), "double") 16 | 17 | }) 18 | 19 | test_that("varfreq_expected_mbias there is no bias if c_ratio is 1", { 20 | 21 | expect_equal(varfreq_expected_mbias(p_v1 = 0.44, c_ratio = 1), 1) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_true.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_true returns M*rho or M/2 * rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_true(sensitivity = 1, rho = 1, M = 10, 5 | R = NULL, assumption = "stsl"), 5) 6 | 7 | expect_equal(translink_expected_links_true(sensitivity = 1, rho = 1, M = 10, 8 | R = 1, assumption = "mtsl"), 10) 9 | 10 | expect_equal(translink_expected_links_true(sensitivity = 1, rho = 1, M = 10, 11 | R = 1, assumption = "mtml"), 10) 12 | }) 13 | 14 | test_that("translink_expected_links_true fails when parameters invalid", { 15 | 16 | expect_error(translink_expected_links_true(sensitivity = 1, rho = 1, M = 10, 17 | R = 1, assumption = "bananas")) 18 | 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_obs.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_obs returns M*rho or M/2 * rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_obs(sensitivity = 1, specificity = 1, rho = 1, 5 | M = 10, R = NULL, assumption = "stsl"), 5) 6 | 7 | expect_equal(translink_expected_links_obs(sensitivity = 1, specificity = 1, rho = 1, 8 | M = 10, R = 1, assumption = "mtsl"), 10) 9 | 10 | expect_equal(translink_expected_links_obs(sensitivity = 1, specificity = 1, rho = 1, 11 | M = 10, R = 1, assumption = "mtml"), 10) 12 | }) 13 | 14 | test_that("translink_expected_links_obs fails when parameters invalid", { 15 | 16 | expect_error(translink_expected_links_obs(sensitivity = 1, specificity = 1, rho = 1, 17 | M = 10, R = 1, assumption = "bananas")) 18 | 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_prob_transmit.R: -------------------------------------------------------------------------------- 1 | test_that("translink_prob_transmit input arguments are valid", { 2 | 3 | expect_error(translink_prob_transmit(sensitivity = 0.9, specificity = 0.9, rho = 0.4, M = 100, R = 1, assumption = "fake"), 4 | "assumption argument") 5 | 6 | }) 7 | 8 | test_that("translink_prob_transmit return object is valid double", { 9 | 10 | expect_type(translink_prob_transmit(sensitivity = 0.9, specificity = 0.9, rho = 0.4, M = 100, R = 1, assumption = "stsl"), 11 | "double") 12 | expect_type(translink_prob_transmit(sensitivity = 0.9, specificity = 0.9, rho = 0.4, M = 100, R = 1, assumption = "mtsl"), 13 | "double") 14 | expect_type(translink_prob_transmit(sensitivity = 0.9, specificity = 0.9, rho = 0.4, M = 100, R = 1, assumption = "mtml"), 15 | "double") 16 | 17 | }) 18 | 19 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | check_proportion <- function(p) { 2 | name_p <- rlang::enexpr(p) 3 | if (p < 0 | p > 1) { 4 | cli::cli_abort(c("`{name_p}` must be between 0 and 1.", 5 | "x" = "You input `{name_p}` = {p}"), 6 | call = NULL) 7 | } 8 | } 9 | 10 | check_m_N <- function(m, N) { 11 | if (m > N) { 12 | cli::cli_warn( 13 | c( 14 | "Necessary sample size not achievable.", 15 | "i" = "The necessary sample size given the input parameters is {round(m)}", 16 | "x" = "You input {.var N} = {N} as the total size of the outbreak" 17 | ) 18 | ) 19 | return(NA) 20 | } 21 | } 22 | check_positive <- function(x) { 23 | name_x <- rlang::enexpr(x) 24 | if (x <= 0) { 25 | cli::cli_abort(c("`{name_x}` must be positive.", 26 | "x" = "You input `{name_x}` = {x}"), 27 | call = NULL) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental -------------------------------------------------------------------------------- /docs/reference/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning -------------------------------------------------------------------------------- /tests/testthat/test-relR_samplesize_basic.R: -------------------------------------------------------------------------------- 1 | test_that("Function errors properly if k is impossible", { 2 | expect_error(relR_samplesize_basic(1.5, 2, 0.5, 1000, overdispersion = 100)) 3 | }) 4 | 5 | 6 | test_that("Function errors properly without overdispersion", { 7 | R_a <- 1.5 8 | R_b <- 2 9 | d <- 1 10 | p_a <- 0.5 11 | N <- 1000 12 | m <- 1/2 * (sqrt(4 * (1 + R_a / (R_b * d^2)) * 13 | (stats::qnorm(1 - 0.025) + stats::qnorm(0.8))^2 * (N - 1) / 14 | (log(R_b/R_a)^2 * R_a * p_a^2) + 1) + 1) 15 | expect_equal(m, relR_samplesize_basic(1.5, 2, 0.5, 1000)) 16 | }) 17 | 18 | test_that("Function works with overdispersion", { 19 | m <- relR_samplesize_basic(1.5, 2, 0.5, 1000, overdispersion = 350) 20 | expect_equal(round(m), 983) 21 | }) 22 | 23 | test_that("Function works with overdispersion set to Inf", { 24 | m1 <- relR_samplesize_basic(1.5, 2, 0.5, 1000) 25 | m2 <- relR_samplesize_basic(1.5, 2, 0.5, 1000, overdispersion = Inf) 26 | expect_equal(m1, m2) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/true_pairs.md: -------------------------------------------------------------------------------- 1 | # true_pairs is deprecated 2 | 3 | Code 4 | expect_equal(true_pairs(eta = 1, rho = 1, M = 10, R = NULL, assumption = "stsl"), 5 | 5) 6 | Warning 7 | `true_pairs()` was deprecated in phylosamp 1.0.0. 8 | i Please use `translink_expected_links_true()` instead. 9 | The `eta` argument of `true_pairs()` is deprecated as of phylosamp 1.0.0. 10 | i Please use the `sensitivity` argument of `translink_expected_links_true()` instead. 11 | Message 12 | Calculating expected number of links assuming single-transmission and single-linkage 13 | Warning 14 | `true_pairs_stsl()` was deprecated in phylosamp 1.0.0. 15 | i Please use `translink_expected_links_true_stsl()` instead. 16 | The `eta` argument of `true_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 17 | i Please use the `sensitivity` argument of `translink_expected_links_true_stsl()` instead. 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_true_stsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_true_stsl returns (M/2) * rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_true_stsl(sensitivity = 1, rho = 1, M = 10), 5 | 5) 6 | 7 | expect_equal(translink_expected_links_true_stsl(sensitivity = 1, rho = 0.5, M = 10), 8 | 2.5) 9 | }) 10 | 11 | test_that("translink_expected_links_true_stsl returns 0 when sensitivity 0", { 12 | 13 | expect_equal(translink_expected_links_true_stsl(sensitivity = 0, rho = 1, M = 10), 14 | 0) 15 | 16 | }) 17 | 18 | 19 | test_that("translink_expected_links_true_stsl fails when parameters invalid", { 20 | 21 | expect_error(translink_expected_links_true_stsl(sensitivity = 5, rho = 1, M = 10)) 22 | 23 | expect_error(translink_expected_links_true_stsl(sensitivity = 1, rho = 5, M = 10)) 24 | 25 | expect_error(translink_expected_links_true_stsl(sensitivity = 1, rho = 0.5, M = -1)) 26 | 27 | expect_error(translink_expected_links_true_stsl(sensitivity = 0.99, rho = 0, 28 | M = 10)) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-gendist_sensspec_cutoff.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("gendist_sensspec_cutoff finds sensitivity estimate", { 3 | 4 | expect_equal(gendist_sensspec_cutoff(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 5 | 0.08, 0.15, 0.75), max_link_gens = 1)[1, "sensitivity"][[1]], 0.7357589, 6 | tolerance = 0.01) 7 | }) 8 | 9 | test_that("gendist_sensspec_cutoff finds specificity estimate", { 10 | 11 | expect_equal(gendist_sensspec_cutoff(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 12 | 0.08, 0.15, 0.75), max_link_gens = 1)[1, "specificity"][[1]], 0.8662894, 13 | tolerance = 0.01) 14 | }) 15 | 16 | test_that("gendist_sensspec_cutoff returns sensitivity and specificity estimates for a range of cutoff values", 17 | { 18 | 19 | tmp <- gendist_sensspec_cutoff(cutoff = 10, mut_rate = 1, mean_gens_pdf = c(0.02, 20 | 0.08, 0.15, 0.75), max_link_gens = 1) 21 | 22 | expect_identical(as.integer(c(1, 3)), dim(tmp)) 23 | expect_true(tmp[, "cutoff"] == 10) 24 | expect_equal(as.numeric(tmp[, "sensitivity"]), 0.999, tolerance = 0.01) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_samplesize_detect.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_samplesize_detect input arguments are valid", { 2 | 3 | expect_error(vartrack_samplesize_detect(prob = 0.2, p_v1 = 0.1, omega = 0.9, c_ratio = 1.5, sampling_freq = "fake"), 4 | "sampling frequency argument") 5 | expect_error(vartrack_samplesize_detect(prob = 0.3, omega = 0.9, c_ratio = 1, sampling_freq = "xsect"), 6 | "the xsect method") 7 | expect_error(vartrack_samplesize_detect(prob = 0.9, p_v1 = 0.1, omega = 0.9, c_ratio = 1.5, sampling_freq = "cont"), 8 | "the cont method") 9 | }) 10 | 11 | test_that("vartrack_samplesize_detect return object is valid double", { 12 | 13 | expect_type(vartrack_samplesize_detect(p_v1 = 0.1, prob = 0.9, omega = 0.9, c_ratio = 1.5, sampling_freq = "xsect"), "double") 14 | expect_type(vartrack_samplesize_detect(prob = 0.9, t = 2, omega = 0.8, p0_v1 = 0.02, r_v1 = 0.002, c_ratio = 1, sampling_freq = "cont"), "double") 15 | expect_type(vartrack_samplesize_detect(prob = 0.9, p_v1 = 0.022, omega = 0.8, p0_v1 = 0.02, r_v1 = 0.002, c_ratio = 1, sampling_freq = "cont"), "double") 16 | }) 17 | 18 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_obs_stsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_obs_stsl returns (M/2) * rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_obs_stsl(sensitivity = 1, specificity = 1, 5 | rho = 1, M = 10), 5) 6 | 7 | expect_equal(translink_expected_links_obs_stsl(sensitivity = 1, specificity = 1, 8 | rho = 0.5, M = 10), 2.5) 9 | }) 10 | 11 | test_that("translink_expected_links_obs_stsl fails when parameters invalid", { 12 | 13 | expect_error(translink_expected_links_obs_stsl(sensitivity = 5, specificity = 1, 14 | rho = 1, M = 10)) 15 | 16 | expect_error(translink_expected_links_obs_stsl(sensitivity = 1, specificity = 5, 17 | rho = 0.5, M = 10)) 18 | 19 | expect_error(translink_expected_links_obs_stsl(sensitivity = 1, specificity = 1, 20 | rho = 5, M = 10)) 21 | 22 | expect_error(translink_expected_links_obs_stsl(sensitivity = 1, specificity = 1, 23 | rho = 0.5, M = -1)) 24 | 25 | expect_error(translink_expected_links_obs_stsl(sensitivity = 0.99, specificity = 0.99, 26 | rho = 0, M = 10)) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-gendist_distribution.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("gendist_distribution returns linked_prob==1 when max_dist 0 and mean_gens_pdf[1]>0", { 3 | 4 | expect_equal(gendist_distribution(mut_rate = 1, mean_gens_pdf = c(0.2, 0.2, 0.2, 5 | 0.2, 0.2), max_dist = 0)[, "linked_prob"][[1]], 1) 6 | 7 | expect_equal(gendist_distribution(mut_rate = 2, mean_gens_pdf = c(1), max_dist = 0)[, 8 | "linked_prob"][[1]], 1) 9 | }) 10 | 11 | test_that("gendist_distribution fails when parameters invalid", { 12 | 13 | expect_error(gendist_distribution(mut_rate = -1, mean_gens_pdf = c(0.5, 0.5), 14 | max_link_gens = 1)) 15 | 16 | expect_error(gendist_distribution(mut_rate = 1, mean_gens_pdf = 0)) 17 | 18 | expect_error(gendist_distribution(mut_rate = 1, mean_gens_pdf = c(0.2, -0.2, 19 | 0.6))) 20 | 21 | expect_error(gendist_distribution(mut_rate = 1, mean_gens_pdf = c(0.2, -0.2, 22 | 0.6), max_gens = 0)) 23 | 24 | expect_error(gendist_distribution(mut_rate = 1, mean_gens_pdf = c(0.2, -0.2, 25 | 0.6), max_dist = -1)) 26 | 27 | expect_error(gendist_distribution(mut_rate = 1, mean_gens_pdf = c(0.2, -0.2, 28 | 0.6), max_link_gens = 0)) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_tdr.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_tdr returns 1 when sensitivity perfect", { 3 | 4 | expect_equal(translink_tdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 5 | R = NULL, assumption = "stsl"), 1) 6 | 7 | expect_equal(translink_tdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 8 | R = 1, assumption = "mtsl"), 1) 9 | 10 | expect_equal(translink_tdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 11 | R = 1, assumption = "mtml"), 1) 12 | }) 13 | 14 | 15 | test_that("translink_tdr returns 0 when sensitivity 0", { 16 | 17 | expect_equal(translink_tdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 18 | R = NULL, assumption = "stsl"), 0) 19 | 20 | expect_equal(translink_tdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 21 | R = 1, assumption = "mtsl"), 0) 22 | 23 | expect_equal(translink_tdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 24 | R = 1, assumption = "mtml"), 0) 25 | }) 26 | 27 | test_that("translink_tdr fails when parameters invalid", { 28 | 29 | expect_error(translink_tdr(sensitivity = 0.9, specificity = 0.9, rho = 1, M = 10, 30 | R = 1, assumption = "bananas")) 31 | }) 32 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_prob_detect.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_prob_detect input arguments are valid", { 2 | 3 | expect_error(vartrack_prob_detect(p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "fake"), 4 | "sampling frequency argument") 5 | expect_error(vartrack_prob_detect(n = 30, t = 2, omega = 1, p0_v1 = 0.1, r_v1 = .02, c_ratio = 1, sampling_freq = "xsect"), 6 | "the xsect method") 7 | expect_error(vartrack_prob_detect(p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "cont"), 8 | "the cont method") 9 | expect_error(vartrack_prob_detect(t = 2, p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "cont"), 10 | "the cont method") 11 | }) 12 | 13 | test_that("vartrack_prob_detect return object is valid double", { 14 | 15 | expect_type(vartrack_prob_detect(p_v1 = 0.1, n = 30, omega = 0.9, c_ratio = 1.5, sampling_freq = "xsect"), "double") 16 | expect_type(vartrack_prob_detect(n = 30, t = 2, omega = 1, p0_v1 = 0.1, r_v1 = .02, c_ratio = 1, sampling_freq = "cont"), "double") 17 | expect_type(vartrack_prob_detect(n = 30, p_v1 = 0.11, omega = 1, p0_v1 = 0.1, r_v1 = .02, c_ratio = 1, sampling_freq = "cont"), "double") 18 | }) 19 | 20 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_fdr.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_fdr returns 1 when sensitivity perfect", { 3 | 4 | expect_equal(translink_fdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 5 | R = NULL, assumption = "stsl"), 0) 6 | 7 | expect_equal(translink_fdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 8 | R = 1, assumption = "mtsl"), 0) 9 | 10 | expect_equal(translink_fdr(sensitivity = 1, specificity = 1, rho = 1, M = 10, 11 | R = 1, assumption = "mtml"), 0) 12 | 13 | }) 14 | 15 | 16 | test_that("translink_fdr returns 0 when sensitivity 0", { 17 | 18 | expect_equal(translink_fdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 19 | R = NULL, assumption = "stsl"), 1) 20 | 21 | expect_equal(translink_fdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 22 | R = 1, assumption = "mtsl"), 1) 23 | 24 | expect_equal(translink_fdr(sensitivity = 0, specificity = 0.99, rho = 1, M = 10, 25 | R = 1, assumption = "mtml"), 1) 26 | }) 27 | 28 | test_that("translink_fdr fails when parameters invalid", { 29 | 30 | expect_error(translink_fdr(sensitivity = 0.9, specificity = 0.9, rho = 1, M = 10, 31 | R = 1, assumption = "bananas")) 32 | }) 33 | -------------------------------------------------------------------------------- /man/varfreq_obs_freq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varfreq_obs_freq.R 3 | \name{varfreq_obs_freq} 4 | \alias{varfreq_obs_freq} 5 | \title{Calculate observed variant prevalence} 6 | \usage{ 7 | varfreq_obs_freq(p_v1, c_ratio) 8 | } 9 | \arguments{ 10 | \item{p_v1}{actual variant prevalence (proportion)} 11 | 12 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2} 13 | } 14 | \value{ 15 | scalar of observed prevalence of variant 1 16 | } 17 | \description{ 18 | This function calculates the observed variant prevalence from the coefficient of detection ratio 19 | and the actual variant prevalence. This function assumes that variant 1 is the variant of concern. 20 | This function is specific to the two-variant system. 21 | } 22 | \examples{ 23 | varfreq_obs_freq(p_v1 = 0.1, c_ratio = 1.1) 24 | 25 | } 26 | \seealso{ 27 | Other variant frequency functions: 28 | \code{\link{varfreq_cdf_logistic}()}, 29 | \code{\link{varfreq_expected_mbias}()}, 30 | \code{\link{varfreq_freq_logistic}()} 31 | } 32 | \author{ 33 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 34 | } 35 | \concept{variant frequency functions} 36 | -------------------------------------------------------------------------------- /R/varfreq_obs_freq.R: -------------------------------------------------------------------------------- 1 | ##' Calculate observed variant prevalence 2 | ##' 3 | ##' This function calculates the observed variant prevalence from the coefficient of detection ratio 4 | ##' and the actual variant prevalence. This function assumes that variant 1 is the variant of concern. 5 | ##' This function is specific to the two-variant system. 6 | ##' 7 | ##' @param p_v1 actual variant prevalence (proportion) 8 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2 9 | ##' @return scalar of observed prevalence of variant 1 10 | ##' 11 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 12 | ##' 13 | ##' @examples 14 | ##' varfreq_obs_freq(p_v1 = 0.1, c_ratio = 1.1) 15 | ##' 16 | ##' @family variant frequency functions 17 | ##' 18 | ##' @export 19 | 20 | 21 | varfreq_obs_freq <- function(p_v1, c_ratio) { 22 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) 23 | stop("Variant prevalence must be numeric and between 0 and 1.") 24 | if (!all(is.numeric(c_ratio), c_ratio > 0)) 25 | stop("Coefficient of detection ratio must be numeric and greater than 0") 26 | 27 | obs <- p_v1/(p_v1 + (1/c_ratio) * (1 - p_v1)) 28 | return(obs) 29 | } 30 | -------------------------------------------------------------------------------- /tests/testthat/test-gendist_roc_format.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("gendist_roc_format finds sensitivity estimate", { 3 | 4 | expect_equal(gendist_roc_format(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 5 | 0.08, 0.15, 0.75), max_link_gens = 1)[2, "sensitivity"][[1]], 0.7357589, 6 | tolerance = 0.01) 7 | }) 8 | 9 | test_that("gendist_roc_format finds specificity estimate", { 10 | 11 | expect_equal(gendist_roc_format(cutoff = 2, mut_rate = 1, mean_gens_pdf = c(0.02, 12 | 0.08, 0.15, 0.75), max_link_gens = 1)[2, "specificity"][[1]], 0.1337106, 13 | tolerance = 0.01) 14 | }) 15 | 16 | test_that("gendist_roc_format returns sensitivity and specificity estimates for a range of cutoff values", 17 | { 18 | 19 | tmp <- gendist_roc_format(cutoff = 10, mut_rate = 1, mean_gens_pdf = c(0.02, 20 | 0.08, 0.15, 0.75), max_link_gens = 1) 21 | 22 | expect_identical(as.integer(c(3, 3)), dim(tmp)) 23 | expect_identical(as.numeric(tmp[1, c("sensitivity", "specificity")]), c(0, 24 | 0)) 25 | expect_identical(as.numeric(tmp[3, c("sensitivity", "specificity")]), c(1, 26 | 1)) 27 | expect_equal(as.numeric(tmp[2, "sensitivity"]), 0.999, tolerance = 0.01) 28 | }) 29 | -------------------------------------------------------------------------------- /R/varfreq_expected_mbias.R: -------------------------------------------------------------------------------- 1 | ##' Calculate multiplicative bias (observed / actual) in variant prevalence 2 | ##' 3 | ##' This function calculates the multiplicative bias of the observed variant proportion 4 | ##' relative to the actual variant proportion. This function assumes that variant 1 is the variant of concern. 5 | ##' This function is specific to the two-variant system. 6 | ##' 7 | ##' @param p_v1 actual variant prevalence (proportion) 8 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2 9 | ##' @return scalar giving the multiplicative bias of variant 1 10 | ##' 11 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 12 | ##' 13 | ##' @examples 14 | ##' varfreq_expected_mbias(p_v1 = 0.1, c_ratio = 1.1) 15 | ##' 16 | ##' @family variant frequency functions 17 | ##' 18 | ##' @export 19 | 20 | 21 | varfreq_expected_mbias <- function(p_v1, c_ratio) { 22 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) stop("Variant prevalence must be numeric and between 0 and 1.") 23 | if (!all(is.numeric(c_ratio), c_ratio > 0)) stop("Coefficient of detection ratio must be numeric and greater than 0") 24 | 25 | bias <- p_v1 + ((1 / c_ratio) * (1 - p_v1)) 26 | return(1 / bias) 27 | } 28 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_true_mtml.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_true_mtml returns M*rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_true_mtml(sensitivity = 1, rho = 1, M = 10, 5 | R = 1), 10) 6 | 7 | expect_equal(translink_expected_links_true_mtml(sensitivity = 1, rho = 0.5, M = 10, 8 | R = 1), 5) 9 | }) 10 | 11 | test_that("translink_expected_links_true_mtml returns 0 when sensitivity 0", { 12 | 13 | expect_equal(translink_expected_links_true_mtml(sensitivity = 0, rho = 1, M = 10, 14 | R = 1), 0) 15 | 16 | }) 17 | 18 | test_that("translink_expected_links_true_mtml fails when parameters invalid", { 19 | 20 | expect_error(translink_expected_links_true_mtml(sensitivity = 5, rho = 1, M = 10, 21 | R = 1)) 22 | 23 | expect_error(translink_expected_links_true_mtml(sensitivity = 1, rho = 5, M = 10, 24 | R = 1)) 25 | 26 | expect_error(translink_expected_links_true_mtml(sensitivity = 1, rho = 0.5, M = -1, 27 | R = 1)) 28 | 29 | expect_error(translink_expected_links_true_mtml(sensitivity = 0.99, rho = 0, 30 | M = 10, R = 1)) 31 | 32 | expect_warning(translink_expected_links_true_mtml(sensitivity = 0.99, rho = 0.5, 33 | M = 10, R = 2)) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_true_mtsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_true_mtsl returns M*rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_true_mtsl(sensitivity = 1, rho = 1, M = 10, 5 | R = 1), 10) 6 | 7 | expect_equal(translink_expected_links_true_mtsl(sensitivity = 1, rho = 0.5, M = 10, 8 | R = 1), 5) 9 | }) 10 | 11 | test_that("translink_expected_links_true_mtsl returns 0 when sensitivity 0", { 12 | 13 | expect_equal(translink_expected_links_true_mtsl(sensitivity = 0, rho = 1, M = 10, 14 | R = 1), 0) 15 | 16 | }) 17 | 18 | test_that("translink_expected_links_true_mtsl fails when parameters invalid", { 19 | 20 | expect_error(translink_expected_links_true_mtsl(sensitivity = 5, rho = 1, M = 10, 21 | R = 1)) 22 | 23 | expect_error(translink_expected_links_true_mtsl(sensitivity = 1, rho = 5, M = 10, 24 | R = 1)) 25 | 26 | expect_error(translink_expected_links_true_mtsl(sensitivity = 1, rho = 0.5, M = -1, 27 | R = 1)) 28 | 29 | expect_error(translink_expected_links_true_mtsl(sensitivity = 0.99, rho = 0, 30 | M = 10, R = 1)) 31 | 32 | expect_warning(translink_expected_links_true_mtsl(sensitivity = 0.99, rho = 0.5, 33 | M = 10, R = 2)) 34 | }) 35 | -------------------------------------------------------------------------------- /man/varfreq_expected_mbias.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varfreq_expected_mbias.R 3 | \name{varfreq_expected_mbias} 4 | \alias{varfreq_expected_mbias} 5 | \title{Calculate multiplicative bias (observed / actual) in variant prevalence} 6 | \usage{ 7 | varfreq_expected_mbias(p_v1, c_ratio) 8 | } 9 | \arguments{ 10 | \item{p_v1}{actual variant prevalence (proportion)} 11 | 12 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2} 13 | } 14 | \value{ 15 | scalar giving the multiplicative bias of variant 1 16 | } 17 | \description{ 18 | This function calculates the multiplicative bias of the observed variant proportion 19 | relative to the actual variant proportion. This function assumes that variant 1 is the variant of concern. 20 | This function is specific to the two-variant system. 21 | } 22 | \examples{ 23 | varfreq_expected_mbias(p_v1 = 0.1, c_ratio = 1.1) 24 | 25 | } 26 | \seealso{ 27 | Other variant frequency functions: 28 | \code{\link{varfreq_cdf_logistic}()}, 29 | \code{\link{varfreq_freq_logistic}()}, 30 | \code{\link{varfreq_obs_freq}()} 31 | } 32 | \author{ 33 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 34 | } 35 | \concept{variant frequency functions} 36 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_obs_mtml.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_obs_mtml returns M*rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_obs_mtml(sensitivity = 1, specificity = 1, 5 | rho = 1, M = 10, R = 1), 10) 6 | 7 | expect_equal(translink_expected_links_obs_mtml(sensitivity = 1, specificity = 1, 8 | rho = 0.5, M = 10, R = 1), 5) 9 | }) 10 | 11 | test_that("translink_expected_links_obs_mtml fails when parameters invalid", { 12 | 13 | expect_error(translink_expected_links_obs_mtml(sensitivity = 5, specificity = 1, 14 | rho = 1, M = 10, R = 1)) 15 | 16 | expect_error(translink_expected_links_obs_mtml(sensitivity = 1, specificity = 5, 17 | rho = 0.5, M = 10, R = 1)) 18 | 19 | expect_error(translink_expected_links_obs_mtml(sensitivity = 1, specificity = 1, 20 | rho = 5, M = 10, R = 1)) 21 | 22 | expect_error(translink_expected_links_obs_mtml(sensitivity = 1, specificity = 1, 23 | rho = 0.5, M = -1, R = 1)) 24 | 25 | expect_error(translink_expected_links_obs_mtml(sensitivity = 0.99, specificity = 0.99, 26 | rho = 0, M = 10, R = 1)) 27 | 28 | expect_warning(translink_expected_links_obs_mtml(sensitivity = 0.99, specificity = 0.99, 29 | rho = 0.5, M = 10, R = 2)) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_expected_links_obs_mtsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_expected_links_obs_mtsl returns M*rho when sensitivity perfect", { 3 | 4 | expect_equal(translink_expected_links_obs_mtsl(sensitivity = 1, specificity = 1, 5 | rho = 1, M = 10, R = 1), 10) 6 | 7 | expect_equal(translink_expected_links_obs_mtsl(sensitivity = 1, specificity = 1, 8 | rho = 0.5, M = 10, R = 1), 5) 9 | }) 10 | 11 | test_that("translink_expected_links_obs_mtsl fails when parameters invalid", { 12 | 13 | expect_error(translink_expected_links_obs_mtsl(sensitivity = 5, specificity = 1, 14 | rho = 1, M = 10, R = 1)) 15 | 16 | expect_error(translink_expected_links_obs_mtsl(sensitivity = 1, specificity = 5, 17 | rho = 0.5, M = 10, R = 1)) 18 | 19 | expect_error(translink_expected_links_obs_mtsl(sensitivity = 1, specificity = 1, 20 | rho = 5, M = 10, R = 1)) 21 | 22 | expect_error(translink_expected_links_obs_mtsl(sensitivity = 1, specificity = 1, 23 | rho = 0.5, M = -1, R = 1)) 24 | 25 | expect_error(translink_expected_links_obs_mtsl(sensitivity = 0.99, specificity = 0.99, 26 | rho = 0, M = 10, R = 1)) 27 | 28 | expect_warning(translink_expected_links_obs_mtsl(sensitivity = 0.99, specificity = 0.99, 29 | rho = 0.5, M = 10, R = 2)) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/truediscoveryrate.md: -------------------------------------------------------------------------------- 1 | # truediscoveryrate is deprecated 2 | 3 | Code 4 | expect_equal(truediscoveryrate(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, 5 | assumption = "stsl"), 1) 6 | Warning 7 | `truediscoveryrate()` was deprecated in phylosamp 1.0.0. 8 | i Please use `translink_tdr()` instead. 9 | The `eta` argument of `truediscoveryrate()` is deprecated as of phylosamp 1.0.0. 10 | i Please use the `sensitivity` argument of `translink_tdr()` instead. 11 | The `chi` argument of `truediscoveryrate()` is deprecated as of phylosamp 1.0.0. 12 | i Please use the `specificity` argument of `translink_tdr()` instead. 13 | Message 14 | Calculating true discovery rate assuming single-transmission and single-linkage 15 | Warning 16 | `prob_trans_stsl()` was deprecated in phylosamp 1.0.0. 17 | i Please use `translink_prob_transmit_stsl()` instead. 18 | The `eta` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 19 | i Please use the `sensitivity` argument of `translink_prob_transmit_stsl()` instead. 20 | The `chi` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 21 | i Please use the `specificity` argument of `translink_prob_transmit_stsl()` instead. 22 | 23 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/exp_links.md: -------------------------------------------------------------------------------- 1 | # exp_links is deprecated 2 | 3 | Code 4 | expect_equal(exp_links(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, assumption = "stsl"), 5 | 5) 6 | Warning 7 | `exp_links()` was deprecated in phylosamp 1.0.0. 8 | i Please use `translink_expected_links_obs()` instead. 9 | The `eta` argument of `exp_links()` is deprecated as of phylosamp 1.0.0. 10 | i Please use the `sensitivity` argument of `translink_expected_links_obs()` instead. 11 | The `chi` argument of `exp_links()` is deprecated as of phylosamp 1.0.0. 12 | i Please use the `specificity` argument of `translink_expected_links_obs()` instead. 13 | Message 14 | Calculating expected number of links assuming single-transmission and single-linkage 15 | Warning 16 | `obs_pairs_stsl()` was deprecated in phylosamp 1.0.0. 17 | i Please use `translink_expected_links_obs_stsl()` instead. 18 | The `eta` argument of `obs_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 19 | i Please use the `sensitivity` argument of `translink_expected_links_obs_stsl()` instead. 20 | The `chi` argument of `obs_pairs_stsl()` is deprecated as of phylosamp 1.0.0. 21 | i Please use the `specificity` argument of `translink_expected_links_obs_stsl()` instead. 22 | 23 | -------------------------------------------------------------------------------- /man/phylosamp-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylosamp-package.R 3 | \docType{package} 4 | \name{phylosamp-package} 5 | \alias{phylosamp} 6 | \alias{phylosamp-package} 7 | \title{phylosamp: Sample Size Calculations for Molecular and Phylogenetic Studies} 8 | \description{ 9 | Implements novel tools for estimating sample sizes needed for phylogenetic studies, including studies focused on estimating the probability of true pathogen transmission between two cases given phylogenetic linkage and studies focused on tracking pathogen variants at a population level. Methods described in Wohl, Giles, and Lessler (2021) and in Wohl, Lee, DiPrete, and Lessler (2023). 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://github.com/HopkinsIDD/phylosamp} 15 | \item Report bugs at \url{https://github.com/HopkinsIDD/phylosamp/issues} 16 | } 17 | 18 | } 19 | \author{ 20 | \strong{Maintainer}: Justin Lessler \email{jlessler@unc.edu} 21 | 22 | Authors: 23 | \itemize{ 24 | \item Shirlee Wohl \email{swohl@scripps.edu} [contributor] 25 | \item Elizabeth C Lee \email{elizabeth.c.lee@jhu.edu} [contributor] 26 | \item Lucy D'Agostino McGowan \email{lucydagostino@gmail.com} (\href{https://orcid.org/0000-0002-6983-2759}{ORCID}) [contributor] 27 | \item John R Giles \email{jrgiles@uw.edu} [contributor] 28 | } 29 | 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_prob_detect_xsect.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_prob_detect_xsect input arguments are valid", { 2 | 3 | expect_error(vartrack_prob_detect_xsect(p_v1 = 0, n = 30, omega = 0.9, c_ratio = 1.5)) 4 | expect_error(vartrack_prob_detect_xsect(p_v1 = "invalid", n = 30, omega = 0.9, c_ratio = 1.5)) 5 | 6 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 0, omega = 0.9, c_ratio = 1.5)) 7 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = "invalid", omega = 0.9, c_ratio = 1.5)) 8 | 9 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 30, omega = 0, c_ratio = 1.5)) 10 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 30, omega = 1.9, c_ratio = 1.5)) 11 | 12 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 30, omega = 0.9, c_ratio = 0)) 13 | expect_error(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 30, omega = 0.9, c_ratio = "invalid")) 14 | }) 15 | 16 | test_that("vartrack_prob_detect_xsect return object is valid double", { 17 | 18 | expect_type(vartrack_prob_detect_xsect(p_v1 = 1/10000, n = 30, omega = 0.9, c_ratio = 1.5), "double") 19 | }) 20 | 21 | 22 | test_that("vartrack_prob_detect_xsect manuscript results remain valid", { 23 | 24 | expect_gt(vartrack_prob_detect_xsect(p_v1 = .02, n = 149, omega = 1, c_ratio = 1), 0.95) 25 | 26 | expect_gt(vartrack_prob_detect_xsect(p_v1 = .02, n = 137, omega = 0.8, c_ratio = (0.8 * 0.975)/(0.6 * 0.95)), 0.95) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-varfreq_obs_freq.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("varfreq_obs_freq input arguments are valid", { 3 | 4 | expect_error(varfreq_obs_freq(p_v1 = 0, c_ratio = 1)) 5 | 6 | expect_error(varfreq_obs_freq(p_v1 = 1.1, c_ratio = 1)) 7 | 8 | expect_error(varfreq_obs_freq(p_v1 = "invalid", c_ratio = 1)) 9 | 10 | expect_error(varfreq_obs_freq(p_v1 = 0.1, c_ratio = -2)) 11 | 12 | expect_error(varfreq_obs_freq(p_v1 = 0.1, c_ratio = FALSE)) 13 | }) 14 | 15 | test_that("varfreq_obs_freq return object is valid double", { 16 | 17 | expect_type(varfreq_obs_freq(p_v1 = 0.2, c_ratio = 1.5), "double") 18 | 19 | }) 20 | 21 | test_that("varfreq_obs_freq observed variant prevalence is equal to actual variant prevalence if c_ratio is 1", 22 | { 23 | 24 | expect_equal(varfreq_obs_freq(p_v1 = 0.8, c_ratio = 1), 0.8) 25 | }) 26 | 27 | test_that("varfreq_obs_freq observed_variant prevalence is greater than actual variant prevalence if c_ratio is above 1", 28 | { 29 | 30 | expect_gt(varfreq_obs_freq(p_v1 = 0.4, c_ratio = 2), 0.4) 31 | 32 | }) 33 | 34 | test_that("varfreq_obs_freq observed variant prevalence is less than actual variant prevalence if c_ratio is below 1", 35 | { 36 | 37 | expect_lt(varfreq_obs_freq(p_v1 = 0.75, c_ratio = 0.3), 0.75) 38 | 39 | }) 40 | 41 | test_that("varfreq_obs_freq manuscript results remain valid", { 42 | 43 | expect_equal(round(varfreq_obs_freq(p_v1 = 0.02, c_ratio = (0.975 * 0.8)/(0.6 * 44 | 0.95)), 3), 0.027) 45 | }) 46 | 47 | -------------------------------------------------------------------------------- /man/varfreq_freq_logistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varfreq_freq_logistic.R 3 | \name{varfreq_freq_logistic} 4 | \alias{varfreq_freq_logistic} 5 | \title{Calculate observed variant prevalence at time t given logistic growth} 6 | \usage{ 7 | varfreq_freq_logistic(t, p0_v1, r_v1, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{t}{time step number (e.g., days) at which to calculate prevalence} 11 | 12 | \item{p0_v1}{initial variant prevalence (# introductions / infected population size)} 13 | 14 | \item{r_v1}{logistic growth rate} 15 | 16 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2; default = 1 (no bias)} 17 | } 18 | \value{ 19 | scalar giving the variant prevalence at time t 20 | } 21 | \description{ 22 | This function calculates the observed variant prevalence after t time steps (e.g., days) 23 | given a logistic growth rate and initial variant prevalence. 24 | } 25 | \examples{ 26 | varfreq_freq_logistic(t = 30, p0_v1 = 1/10000, r_v1 = 0.1, c_ratio = 1) 27 | 28 | } 29 | \seealso{ 30 | Other logistic growth functions: 31 | \code{\link{varfreq_cdf_logistic}()} 32 | 33 | Other variant frequency functions: 34 | \code{\link{varfreq_cdf_logistic}()}, 35 | \code{\link{varfreq_expected_mbias}()}, 36 | \code{\link{varfreq_obs_freq}()} 37 | } 38 | \author{ 39 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 40 | } 41 | \concept{logistic growth functions} 42 | \concept{variant frequency functions} 43 | -------------------------------------------------------------------------------- /man/varfreq_cdf_logistic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varfreq_cdf_logistic.R 3 | \name{varfreq_cdf_logistic} 4 | \alias{varfreq_cdf_logistic} 5 | \title{Calculate cumulative observed variant prevalence at time t given logistic growth} 6 | \usage{ 7 | varfreq_cdf_logistic(t, p0_v1, r_v1, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{t}{time step number (e.g., days) at which to calculate prevalence} 11 | 12 | \item{p0_v1}{initial variant prevalence (# introductions / infected population size)} 13 | 14 | \item{r_v1}{logistic growth rate} 15 | 16 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 17 | } 18 | \value{ 19 | scalar giving the cdf of variant prevalence at time t 20 | } 21 | \description{ 22 | This function calculates the cumulative observed variant prevalence after t time steps (e.g., days) 23 | given a logistic growth rate and initial variant prevalence. 24 | } 25 | \examples{ 26 | varfreq_cdf_logistic(t = 30, p0_v1 = 1/10000, r_v1 = 0.1, c_ratio = 1) 27 | 28 | } 29 | \seealso{ 30 | Other logistic growth functions: 31 | \code{\link{varfreq_freq_logistic}()} 32 | 33 | Other variant frequency functions: 34 | \code{\link{varfreq_expected_mbias}()}, 35 | \code{\link{varfreq_freq_logistic}()}, 36 | \code{\link{varfreq_obs_freq}()} 37 | } 38 | \author{ 39 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 40 | } 41 | \concept{logistic growth functions} 42 | \concept{variant frequency functions} 43 | -------------------------------------------------------------------------------- /R/varfreq_freq_logistic.R: -------------------------------------------------------------------------------- 1 | ##' Calculate observed variant prevalence at time t given logistic growth 2 | ##' 3 | ##' This function calculates the observed variant prevalence after t time steps (e.g., days) 4 | ##' given a logistic growth rate and initial variant prevalence. 5 | ##' 6 | ##' @param t time step number (e.g., days) at which to calculate prevalence 7 | ##' @param p0_v1 initial variant prevalence (# introductions / infected population size) 8 | ##' @param r_v1 logistic growth rate 9 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2; default = 1 (no bias) 10 | ##' @return scalar giving the variant prevalence at time t 11 | ##' 12 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 13 | ##' 14 | ##' @examples 15 | ##' varfreq_freq_logistic(t = 30, p0_v1 = 1/10000, r_v1 = 0.1, c_ratio = 1) 16 | ##' 17 | ##' @family logistic growth functions 18 | ##' @family variant frequency functions 19 | ##' 20 | ##' @export 21 | 22 | 23 | varfreq_freq_logistic <- function(t, p0_v1, r_v1, c_ratio = 1) { 24 | if (!is.numeric(t)) stop("Time step must be numeric.") 25 | if (!all(is.numeric(p0_v1), p0_v1 > 0 & p0_v1 < 1)) stop("Initial variant prevalence must numeric and between 0 and 1.") 26 | if (!all(is.numeric(r_v1), r_v1 != 0)) stop("Growth rate must be numeric and non-zero.") 27 | if (!all(is.numeric(c_ratio), c_ratio > 0)) stop("Coefficient of detection ratio must be numeric and greater than 0") 28 | 29 | a <- (1 / p0_v1) - 1 30 | b <- a * (1 / c_ratio) 31 | g <- 1 / (1 + (b * exp(-r_v1 * t))) 32 | return(g) 33 | } 34 | -------------------------------------------------------------------------------- /R/varfreq_cdf_logistic.R: -------------------------------------------------------------------------------- 1 | ##' Calculate cumulative observed variant prevalence at time t given logistic growth 2 | ##' 3 | ##' This function calculates the cumulative observed variant prevalence after t time steps (e.g., days) 4 | ##' given a logistic growth rate and initial variant prevalence. 5 | ##' 6 | ##' @param t time step number (e.g., days) at which to calculate prevalence 7 | ##' @param p0_v1 initial variant prevalence (# introductions / infected population size) 8 | ##' @param r_v1 logistic growth rate 9 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 10 | ##' @return scalar giving the cdf of variant prevalence at time t 11 | ##' 12 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 13 | ##' 14 | ##' @examples 15 | ##' varfreq_cdf_logistic(t = 30, p0_v1 = 1/10000, r_v1 = 0.1, c_ratio = 1) 16 | ##' 17 | ##' @family logistic growth functions 18 | ##' @family variant frequency functions 19 | ##' 20 | ##' @export 21 | 22 | 23 | varfreq_cdf_logistic <- function(t, p0_v1, r_v1, c_ratio = 1) { 24 | if (!is.numeric(t)) stop("Time step must be numeric.") 25 | if (!all(is.numeric(p0_v1), p0_v1 > 0 & p0_v1 < 1)) stop("Initial variant prevalence must be numeric and between 0 and 1.") 26 | if (!all(is.numeric(r_v1), r_v1 != 0)) stop("Growth rate must be numeric and non-zero.") 27 | if (!all(is.numeric(c_ratio), c_ratio != 0)) stop("Coefficient of detection ratio must be numeric and non-zero") 28 | 29 | a <- (1 / p0_v1) - 1 30 | b <- a * (1 / c_ratio) 31 | G <- (1 / r_v1) * log(b + exp(r_v1 * t)) 32 | 33 | return(G) 34 | } 35 | -------------------------------------------------------------------------------- /man/true_pairs_stsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/true_pairs_stsl.R 3 | \name{true_pairs_stsl} 4 | \alias{true_pairs_stsl} 5 | \title{Expected number of true transmission pairs assuming single-transmission and single-linkage} 6 | \usage{ 7 | true_pairs_stsl(eta, rho, M) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | } 16 | \value{ 17 | scalar or vector giving the expected number of true transmission pairs in the sample 18 | } 19 | \description{ 20 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 21 | This function calculates the expected number of true transmission pairs in a sample of size \code{M}. 22 | The single-transmission and single-linkage method assumes the following: 23 | \enumerate{ 24 | \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 25 | \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 26 | } 27 | } 28 | \examples{ 29 | true_pairs_stsl(eta=0.95, rho=0.2, M=200) 30 | 31 | } 32 | \seealso{ 33 | Other true_pairs: 34 | \code{\link{true_pairs_mtml}()}, 35 | \code{\link{true_pairs_mtsl}()}, 36 | \code{\link{true_pairs}()} 37 | } 38 | \author{ 39 | John Giles, Shirlee Wohl, and Justin Lessler 40 | } 41 | \concept{true_pairs} 42 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/falsediscoveryrate.md: -------------------------------------------------------------------------------- 1 | # falsediscoveryrate is deprecated 2 | 3 | Code 4 | expect_equal(falsediscoveryrate(eta = 1, chi = 1, rho = 1, M = 10, R = NULL, 5 | assumption = "stsl"), 0) 6 | Warning 7 | `falsediscoveryrate()` was deprecated in phylosamp 1.0.0. 8 | i Please use `translink_fdr()` instead. 9 | The `eta` argument of `falsediscoveryrate()` is deprecated as of phylosamp 1.0.0. 10 | i Please use the `sensitivity` argument of `translink_fdr()` instead. 11 | The `chi` argument of `falsediscoveryrate()` is deprecated as of phylosamp 1.0.0. 12 | i Please use the `specificity` argument of `translink_fdr()` instead. 13 | `truediscoveryrate()` was deprecated in phylosamp 1.0.0. 14 | i Please use `translink_tdr()` instead. 15 | The `eta` argument of `truediscoveryrate()` is deprecated as of phylosamp 1.0.0. 16 | i Please use the `sensitivity` argument of `translink_tdr()` instead. 17 | The `chi` argument of `truediscoveryrate()` is deprecated as of phylosamp 1.0.0. 18 | i Please use the `specificity` argument of `translink_tdr()` instead. 19 | `prob_trans_stsl()` was deprecated in phylosamp 1.0.0. 20 | i Please use `translink_prob_transmit_stsl()` instead. 21 | The `eta` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 22 | i Please use the `sensitivity` argument of `translink_prob_transmit_stsl()` instead. 23 | The `chi` argument of `prob_trans_stsl()` is deprecated as of phylosamp 1.0.0. 24 | i Please use the `specificity` argument of `translink_prob_transmit_stsl()` instead. 25 | 26 | -------------------------------------------------------------------------------- /R/vartrack_prob_detect_xsect.R: -------------------------------------------------------------------------------- 1 | ##' Calculate probability of detecting a variant assuming cross-sectional sampling 2 | ##' 3 | ##' This function calculates the probability of detecting the presence of a variant 4 | ##' given a sample size and assuming a single, cross-sectional sample of detected infections. 5 | ##' 6 | ##' @param p_v1 variant prevalence (proportion) 7 | ##' @param n sample size 8 | ##' @param omega probability of sequencing (or other characterization) success 9 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 10 | ##' @return scalar of expected sample size 11 | ##' 12 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 13 | ##' 14 | ##' @examples 15 | ##' vartrack_prob_detect_xsect(p_v1 = 0.02, n = 100, omega = 0.8, c_ratio = 1) 16 | ##' 17 | ##' @family variant detection functions 18 | ##' @family variant tracking functions 19 | ##' 20 | ##' @export 21 | 22 | 23 | vartrack_prob_detect_xsect <- function(p_v1, n, omega, c_ratio = 1) { 24 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) stop("Variant prevalence must be numeric and between 0 and 1.") 25 | if (!all(is.numeric(n), n > 0)) stop("Sample size must be numeric and greater than 0.") 26 | if (!all(is.numeric(omega), omega > 0 & omega <= 1)) stop("Probability of characterization success must be numeric and between 0 and 1.") 27 | if (!all(is.numeric(c_ratio), c_ratio > 0)) stop("Coefficient of detection ratio must be numeric and greater than 0.") 28 | 29 | p_star <- varfreq_obs_freq(p_v1, c_ratio) 30 | n_star <- n * omega 31 | prob <- 1 - ((1-p_star)^n_star) 32 | return(prob) 33 | } 34 | -------------------------------------------------------------------------------- /tests/testthat/test-varfreq_cdf_logistic.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("varfreq_cdf_logistic input arguments are valid", { 3 | 4 | expect_error(varfreq_cdf_logistic(t = "invalid", p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1)) 5 | 6 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = 1.1, r_v1 = 0.1, c_ratio = 1)) 7 | 8 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = "invalid", r_v1 = 0.1, c_ratio = 1)) 9 | 10 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = "invalid", c_ratio = 1)) 11 | 12 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0, c_ratio = 1)) 13 | 14 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = "invalid")) 15 | 16 | expect_error(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 0)) 17 | }) 18 | 19 | test_that("varfreq_cdf_logistic return object is valid double", { 20 | 21 | expect_type(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1), 22 | "double") 23 | }) 24 | 25 | test_that("varfreq_cdf_logistic cdf increases monotonically", { 26 | 27 | expect_gt(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1), 28 | varfreq_cdf_logistic(t = 3, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1)) 29 | 30 | expect_lt(varfreq_cdf_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1.5), 31 | varfreq_cdf_logistic(t = 7, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1.5)) 32 | 33 | }) 34 | 35 | test_that("varfreq_cdf_logistic manuscript values remain valid", { 36 | 37 | expect_equal(round(varfreq_cdf_logistic(t = 14, p0_v1 = 1/10000, r_v1 = 0.1, 38 | c_ratio = 1) - varfreq_cdf_logistic(t = 0, p0_v1 = 1/10000, r_v1 = 0.1, c_ratio = 1), 39 | 8), 0.00305473) 40 | 41 | }) 42 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: phylosamp 2 | Type: Package 3 | Title: Sample Size Calculations for Molecular and Phylogenetic Studies 4 | Version: 1.0.1 5 | Date: 2023-04-25 6 | Authors@R: c(person("Shirlee", "Wohl", role=c("aut", "ctb"), email="swohl@scripps.edu"), 7 | person("Elizabeth C", "Lee", role=c("aut", "ctb"), email="elizabeth.c.lee@jhu.edu"), 8 | person("Lucy", "D'Agostino McGowan", role=c("aut", "ctb"), email = "lucydagostino@gmail.com", 9 | comment = c(ORCID = "0000-0002-6983-2759")), 10 | person("John R", "Giles", role=c("aut", "ctb"), email="jrgiles@uw.edu"), 11 | person("Justin", "Lessler", role=c("aut", "cre"), email="jlessler@unc.edu")) 12 | Maintainer: Justin Lessler 13 | Description: Implements novel tools for estimating sample sizes needed for phylogenetic studies, including 14 | studies focused on estimating the probability of true pathogen transmission between two cases given phylogenetic linkage and studies focused on tracking pathogen variants at a population level. Methods described in Wohl, Giles, and Lessler (2021) and in Wohl, Lee, DiPrete, and Lessler (2023). 15 | License: GPL-2 16 | URL: https://github.com/HopkinsIDD/phylosamp 17 | BugReports: https://github.com/HopkinsIDD/phylosamp/issues 18 | Encoding: UTF-8 19 | LazyData: true 20 | RoxygenNote: 7.2.3 21 | Depends: 22 | R (>= 2.10), 23 | stats 24 | Imports: 25 | cli, 26 | lifecycle, 27 | rlang 28 | Suggests: 29 | cowplot, 30 | ggplot2, 31 | knitr, 32 | purrr, 33 | RColorBrewer, 34 | reshape2, 35 | rmarkdown, 36 | testthat (>= 3.0.0) 37 | VignetteBuilder: knitr 38 | Config/testthat/edition: 3 39 | Roxygen: list(markdown = TRUE) 40 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_prob_transmit_mtml.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_prob_transmit_mtml returns 1 when sensitivity perfect", { 3 | 4 | expect_equal(translink_prob_transmit_mtml(sensitivity = 1, specificity = 1, rho = 1, 5 | M = 10, R = 1), 1) 6 | 7 | expect_equal(translink_prob_transmit_mtml(sensitivity = 1, specificity = 1, rho = 0.5, 8 | M = 10, R = 1), 1) 9 | }) 10 | 11 | test_that("translink_prob_transmit_mtml returns 0 when sensitivity 0", { 12 | 13 | expect_equal(translink_prob_transmit_mtml(sensitivity = 0, specificity = 0.99, 14 | rho = 1, M = 10, R = 1), 0) 15 | 16 | expect_equal(translink_prob_transmit_mtml(sensitivity = 0, specificity = 0.99, 17 | rho = 0.5, M = 10, R = 1), 0) 18 | 19 | expect_equal(translink_prob_transmit_mtml(sensitivity = 0, specificity = 0.5, 20 | rho = 1, M = 10, R = 1), 0) 21 | }) 22 | 23 | test_that("translink_prob_transmit_mtml fails when parameters invalid", { 24 | 25 | expect_error(translink_prob_transmit_mtml(sensitivity = 5, specificity = 1, rho = 1, 26 | M = 10, R = 1)) 27 | 28 | expect_error(translink_prob_transmit_mtml(sensitivity = 1, specificity = 5, rho = 0.5, 29 | M = 10, R = 1)) 30 | 31 | expect_error(translink_prob_transmit_mtml(sensitivity = 1, specificity = 1, rho = 5, 32 | M = 10, R = 1)) 33 | 34 | expect_error(translink_prob_transmit_mtml(sensitivity = 1, specificity = 1, rho = 0.5, 35 | M = -1, R = 1)) 36 | 37 | expect_error(translink_prob_transmit_mtml(sensitivity = 0.99, specificity = 0.99, 38 | rho = 0, M = 10, R = 1)) 39 | 40 | expect_warning(translink_prob_transmit_mtml(sensitivity = 0.99, specificity = 0.99, 41 | rho = 0.5, M = 10, R = 2)) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_prob_transmit_mtsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_prob_transmit_mtsl returns 1 when sensitivity perfect", { 3 | 4 | expect_equal(translink_prob_transmit_mtsl(sensitivity = 1, specificity = 1, rho = 1, 5 | M = 10, R = 1), 1) 6 | 7 | expect_equal(translink_prob_transmit_mtsl(sensitivity = 1, specificity = 1, rho = 0.5, 8 | M = 10, R = 1), 1) 9 | }) 10 | 11 | test_that("translink_prob_transmit_mtsl returns 0 when sensitivity 0", { 12 | 13 | expect_equal(translink_prob_transmit_mtsl(sensitivity = 0, specificity = 0.99, 14 | rho = 1, M = 10, R = 1), 0) 15 | 16 | expect_equal(translink_prob_transmit_mtsl(sensitivity = 0, specificity = 0.99, 17 | rho = 0.5, M = 10, R = 1), 0) 18 | 19 | expect_equal(translink_prob_transmit_mtsl(sensitivity = 0, specificity = 0.5, 20 | rho = 1, M = 10, R = 1), 0) 21 | }) 22 | 23 | test_that("translink_prob_transmit_mtsl fails when parameters invalid", { 24 | 25 | expect_error(translink_prob_transmit_mtsl(sensitivity = 5, specificity = 1, rho = 1, 26 | M = 10, R = 1)) 27 | 28 | expect_error(translink_prob_transmit_mtsl(sensitivity = 1, specificity = 5, rho = 0.5, 29 | M = 10, R = 1)) 30 | 31 | expect_error(translink_prob_transmit_mtsl(sensitivity = 1, specificity = 1, rho = 5, 32 | M = 10, R = 1)) 33 | 34 | expect_error(translink_prob_transmit_mtsl(sensitivity = 1, specificity = 1, rho = 0.5, 35 | M = -1, R = 1)) 36 | 37 | expect_error(translink_prob_transmit_mtsl(sensitivity = 0.99, specificity = 0.99, 38 | rho = 0, M = 10, R = 1)) 39 | 40 | expect_warning(translink_prob_transmit_mtsl(sensitivity = 0.99, specificity = 0.99, 41 | rho = 0.5, M = 10, R = 2)) 42 | }) 43 | -------------------------------------------------------------------------------- /R/translink_expected_links_true_stsl.R: -------------------------------------------------------------------------------- 1 | ##' Calculate expected number of true transmission pairs assuming single-transmission and single-linkage 2 | ##' 3 | ##' This function calculates the expected number of true transmission pairs in a sample of size `M`. 4 | ##' The single-transmission and single-linkage method assumes the following: 5 | ##' \enumerate{ 6 | ##' \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 7 | ##' \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 8 | ##' } 9 | ##' 10 | ##' @param sensitivity scalar or vector giving the sensitivity of the linkage criteria 11 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 12 | ##' @param M scalar or vector giving the number of cases sampled 13 | ##' 14 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 15 | ##' 16 | ##' @author John Giles, Shirlee Wohl, and Justin Lessler 17 | ##' 18 | ##' @examples 19 | ##' translink_expected_links_true_stsl(sensitivity=0.95, rho=0.2, M=200) 20 | ##' 21 | ##' @family transmission linkage functions 22 | ##' 23 | ##' @export 24 | 25 | translink_expected_links_true_stsl <- function(sensitivity, rho, M) { 26 | if (!all(is.numeric(sensitivity), sensitivity >= 0 & sensitivity <= 1)) 27 | stop("sensitivity must be numeric between 0 and 1") 28 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 29 | stop("rho must be numeric > 0 and <= 1") 30 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 31 | stop("Sample size (M) must be integer or numeric greater than 0") 32 | 33 | (M/2) * sensitivity * rho 34 | } 35 | -------------------------------------------------------------------------------- /man/true_pairs_mtsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/true_pairs_mtsl.R 3 | \name{true_pairs_mtsl} 4 | \alias{true_pairs_mtsl} 5 | \title{Expected number of true transmission pairs assuming multiple-transmission and single-linkage} 6 | \usage{ 7 | true_pairs_mtsl(eta, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | 16 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 17 | } 18 | \value{ 19 | scalar or vector giving the expected number of true transmission pairs in the sample 20 | } 21 | \description{ 22 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 23 | This function calculates the expected number true transmission pairs in a sample of size \code{M}. 24 | The multiple-transmission and single-linkage method assumes the following: 25 | \enumerate{ 26 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 27 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 28 | } 29 | } 30 | \examples{ 31 | true_pairs_mtsl(eta=0.95, rho=0.2, M=200, R=1) 32 | 33 | } 34 | \seealso{ 35 | Other true_pairs: 36 | \code{\link{true_pairs_mtml}()}, 37 | \code{\link{true_pairs_stsl}()}, 38 | \code{\link{true_pairs}()} 39 | } 40 | \author{ 41 | John Giles, Shirlee Wohl and Justin Lessler 42 | } 43 | \concept{true_pairs} 44 | -------------------------------------------------------------------------------- /tests/testthat/test-translink_prob_transmit_stsl.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("translink_prob_transmit_stsl returns 1 when sensitivity perfect", { 3 | 4 | expect_equal(translink_prob_transmit_stsl(sensitivity = 1, specificity = 1, rho = 1, 5 | M = 10), 1) 6 | 7 | expect_equal(translink_prob_transmit_stsl(sensitivity = 1, specificity = 1, rho = 0.5, 8 | M = 10), 1) 9 | 10 | expect_equal(translink_prob_transmit_stsl(sensitivity = 1, specificity = 0, rho = 1, 11 | M = 10), 1) 12 | 13 | expect_equal(translink_prob_transmit_stsl(sensitivity = 1, specificity = 0.5, 14 | rho = 1, M = 10), 1) 15 | }) 16 | 17 | test_that("translink_prob_transmit_stsl returns 0 when sensitivity 0", { 18 | 19 | expect_equal(translink_prob_transmit_stsl(sensitivity = 0, specificity = 0, rho = 1, 20 | M = 10), 0) 21 | 22 | expect_equal(translink_prob_transmit_stsl(sensitivity = 0, specificity = 0, rho = 0.5, 23 | M = 10), 0) 24 | 25 | expect_equal(translink_prob_transmit_stsl(sensitivity = 0, specificity = 0.9, 26 | rho = 1, M = 10), 0) 27 | }) 28 | 29 | test_that("translink_prob_transmit_stsl fails when parameters invalid", { 30 | 31 | expect_error(translink_prob_transmit_stsl(sensitivity = 5, specificity = 1, rho = 1, 32 | M = 10)) 33 | 34 | expect_error(translink_prob_transmit_stsl(sensitivity = 1, specificity = 5, rho = 0.5, 35 | M = 10)) 36 | 37 | expect_error(translink_prob_transmit_stsl(sensitivity = 1, specificity = 1, rho = 5, 38 | M = 10)) 39 | 40 | expect_error(translink_prob_transmit_stsl(sensitivity = 1, specificity = 1, rho = 0.5, 41 | M = -1)) 42 | 43 | expect_error(translink_prob_transmit_stsl(sensitivity = 1, specificity = 1, rho = 0, 44 | M = 10)) 45 | }) 46 | -------------------------------------------------------------------------------- /R/vartrack_samplesize_detect_xsect.R: -------------------------------------------------------------------------------- 1 | ##' Calculate sample size needed for variant detection assuming cross-sectional sampling 2 | ##' 3 | ##' This function calculates the sample size needed for detecting the presence of a variant 4 | ##' given a desired probability of detection and assuming a single, cross-sectional sample of detected infections. 5 | ##' 6 | ##' @param p_v1 variant prevalence (proportion) 7 | ##' @param prob desired probability of detection 8 | ##' @param omega probability of sequencing (or other characterization) success 9 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 10 | ##' @return scalar of expected sample size 11 | ##' 12 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 13 | ##' 14 | ##' @examples 15 | ##' vartrack_samplesize_detect_xsect(p_v1 = 0.1, prob = 0.95, omega = 0.8, c_ratio = 1) 16 | ##' 17 | ##' @family variant detection functions 18 | ##' @family variant tracking functions 19 | ##' 20 | ##' @export 21 | 22 | 23 | vartrack_samplesize_detect_xsect <- function(p_v1, prob, omega, c_ratio = 1) { 24 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) 25 | stop("Variant prevalence must be numeric and between 0 and 1.") 26 | if (!all(is.numeric(prob), prob > 0 & prob < 1)) 27 | stop("Desired probability of detection must be numeric and between 0 and 1.") 28 | if (!all(is.numeric(omega), omega > 0 & omega <= 1)) 29 | stop("Sequencing success rate must be numeric and between 0 and 1.") 30 | if (!all(is.numeric(c_ratio), c_ratio > 0)) 31 | stop("Coefficient of detection ratio must be numeric and greater than 0") 32 | 33 | p_star <- varfreq_obs_freq(p_v1, c_ratio) 34 | n <- (log(1 - prob))/(log(1 - p_star)) 35 | n_samples <- n/omega 36 | return(n_samples) 37 | } 38 | -------------------------------------------------------------------------------- /man/obs_pairs_stsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/obs_pairs_stsl.R 3 | \name{obs_pairs_stsl} 4 | \alias{obs_pairs_stsl} 5 | \title{Expected number of observed pairs assuming single-transmission and single-linkage} 6 | \usage{ 7 | obs_pairs_stsl(eta, chi, rho, M) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | } 18 | \value{ 19 | scalar or vector giving the expected number of linked pairs observed in the sample 20 | } 21 | \description{ 22 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 23 | This function calculates the expected number of link pairs observed in a sample of size \code{M}. 24 | The single-transmission and single-linkage method assumes the following: 25 | \enumerate{ 26 | \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 27 | \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 28 | } 29 | } 30 | \examples{ 31 | # perfect sensitivity and specificity 32 | obs_pairs_stsl(eta=1, chi=1, rho=0.5, M=100) 33 | 34 | obs_pairs_stsl(eta=0.99, chi=0.9, rho=1, M=50) 35 | 36 | obs_pairs_stsl(eta=0.99, chi=0.9, rho=0.5, M=100) 37 | 38 | } 39 | \seealso{ 40 | Other obs_pairs: 41 | \code{\link{exp_links}()}, 42 | \code{\link{obs_pairs_mtml}()}, 43 | \code{\link{obs_pairs_mtsl}()} 44 | } 45 | \author{ 46 | John Giles, Shirlee Wohl, and Justin Lessler 47 | } 48 | \concept{obs_pairs} 49 | -------------------------------------------------------------------------------- /R/true_pairs_stsl.R: -------------------------------------------------------------------------------- 1 | ##' Expected number of true transmission pairs assuming single-transmission and single-linkage 2 | ##' 3 | ##' @description 4 | ##' `r lifecycle::badge('deprecated')` 5 | ##' This function calculates the expected number of true transmission pairs in a sample of size `M`. 6 | ##' The single-transmission and single-linkage method assumes the following: 7 | ##' \enumerate{ 8 | ##' \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 9 | ##' \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 10 | ##' } 11 | ##' 12 | ##' @param eta scalar or vector giving the sensitivity of the linkage criteria 13 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 14 | ##' @param M scalar or vector giving the number of cases sampled 15 | ##' 16 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 17 | ##' 18 | ##' @author John Giles, Shirlee Wohl, and Justin Lessler 19 | ##' 20 | ##' @examples 21 | ##' true_pairs_stsl(eta=0.95, rho=0.2, M=200) 22 | ##' 23 | ##' @family true_pairs 24 | ##' 25 | ##' @export 26 | 27 | true_pairs_stsl <- function(eta, rho, M) { 28 | lifecycle::deprecate_soft("1.0.0", "true_pairs_stsl()", "translink_expected_links_true_stsl()") 29 | lifecycle::deprecate_soft("1.0.0", "true_pairs_stsl(eta)", "translink_expected_links_true_stsl(sensitivity)") 30 | 31 | if (!all(is.numeric(eta), eta >= 0 & eta <= 1)) 32 | stop("eta must be numeric between 0 and 1") 33 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 34 | stop("rho must be numeric > 0 and <= 1") 35 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 36 | stop("Sample size (M) must be integer or numeric greater than 0") 37 | 38 | (M/2) * eta * rho 39 | } 40 | -------------------------------------------------------------------------------- /man/true_pairs_mtml.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/true_pairs_mtml.R 3 | \name{true_pairs_mtml} 4 | \alias{true_pairs_mtml} 5 | \title{Expected number of true transmission pairs assuming multiple-transmission and multiple-linkage} 6 | \usage{ 7 | true_pairs_mtml(eta, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | 16 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 17 | } 18 | \value{ 19 | scalar or vector giving the expected number of true transmission pairs in the sample 20 | } 21 | \description{ 22 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 23 | This function calculates the expected number of true transmission pairs in a sample of size \code{M}. 24 | The multiple-transmission and multiple-linkage method assumes the following: 25 | \enumerate{ 26 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 27 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to multiple cases \eqn{j} in the sampled population (\eqn{M}). 28 | \item Linkage events are independent of one another (i.e, linkage of case \eqn{i} to case \eqn{j} has no bearing on linkage of case \eqn{i} to any other sample). 29 | } 30 | } 31 | \examples{ 32 | true_pairs_mtml(eta=0.95, rho=0.2, M=1000, R=1) 33 | 34 | } 35 | \seealso{ 36 | Other true_pairs: 37 | \code{\link{true_pairs_mtsl}()}, 38 | \code{\link{true_pairs_stsl}()}, 39 | \code{\link{true_pairs}()} 40 | } 41 | \author{ 42 | John Giles, Shirlee Wohl and Justin Lessler 43 | } 44 | \concept{true_pairs} 45 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | "Article", 3 | title = "Sample size calculation for phylogenetic case linkage", 4 | author = "Wohl, Shirlee and Giles, John R. and Lessler, Justin", 5 | journal = "{PLOS} Computational Biology", 6 | year = "2021", 7 | volume = "17", 8 | issn = "1553-7358", 9 | pages = "e1009182", 10 | number = "7", 11 | url = "https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1009182", 12 | doi = "10.1371/journal.pcbi.1009182", 13 | textVersion = "Wohl et al. (2021) Sample size calculation for phylogenetic case linkage, PLOS Computational Biology, 17(7), e1009182, https://doi.org/10.1371/journal.pcbi.1009182") 14 | 15 | bibentry( 16 | "Article", 17 | title = "Sample size calculations for variant surveillance in the presence of biological and systematic biases", 18 | author = "Wohl, Shirlee and Lee, Elizabeth C. and DiPrete, Bethany and Lessler, Justin", 19 | journal = "Cell Reports Medicine", 20 | year = "2023", 21 | url = "https://doi.org/10.1016/j.xcrm.2023.101022", 22 | publisher = "Elsevier", 23 | doi = "10.1016/j.xcrm.2023.101022", 24 | textVersion = "Wohl, S., Lee, E. C., DiPrete, B. L., & Lessler, J. (2023). Sample size calculations for pathogen variant surveillance in the presence of biological and systematic biases. Cell Reports Medicine. https://doi.org/10.1016/j.xcrm.2023.101022") 25 | 26 | bibentry( 27 | "Article", 28 | title = "Power and sample size calculations for testing the ratio of reproductive values in phylogenetic samples", 29 | author = "D'Agostino McGowan, Lucy and Wohl, Shirlee and Lessler, Justin", 30 | journal = "arXiv", 31 | year = "2023", 32 | url = "https://doi.org/10.48550/arXiv.2305.12184", 33 | doi = "10.48550/arXiv.2305.12184", 34 | textVersion = "D'Agostino McGowan, L., Wohl, S., & Lessler, J. (2023). Power and sample size calculations for testing the ratio of reproductive values in phylogenetic samples. arXiv. https://doi.org/10.48550/arXiv.2305.12184") -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_prob_prev_xsect.R: -------------------------------------------------------------------------------- 1 | test_that("vartrack_prob_prev_xsect input arguments are valid", { 2 | 3 | expect_error(vartrack_prob_prev_xsect(p_v1 = 0, n = 30, precision = 0.1, omega = 0.9, c_ratio = 1.5)) 4 | expect_error(vartrack_prob_prev_xsect(p_v1 = "invalid", n = 30, precision = 0.1, omega = 0.9, c_ratio = 1.5)) 5 | 6 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 0, precision = 0.1, omega = 0.9, c_ratio = 1.5)) 7 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = "invalid", precision = 0.1, omega = 0.9, c_ratio = 1.5)) 8 | 9 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 1.1, omega = 0.9, c_ratio = 1.5)) 10 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = "invalid", omega = 0.9, c_ratio = 1.5)) 11 | 12 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 0.1, omega = 0, c_ratio = 1.5)) 13 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 0.1, omega = 1.9, c_ratio = 1.5)) 14 | 15 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 0.1, omega = 0.9, c_ratio = 0)) 16 | expect_error(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 0.1, omega = 0.9, c_ratio = "invalid")) 17 | }) 18 | 19 | test_that("vartrack_prob_prev_xsect return object is valid double", { 20 | 21 | expect_type(vartrack_prob_prev_xsect(p_v1 = 1/10000, n = 30, precision = 0.1, omega = 0.9, c_ratio = 1.5), "double") 22 | }) 23 | 24 | 25 | test_that("vartrack_prob_prev_xsect manuscript results remain valid", { 26 | 27 | expect_gt(vartrack_prob_prev_xsect(p_v1 = .1, n = 554, precision = 0.25, omega = 1, c_ratio = 1), 0.95) 28 | 29 | expect_gt(vartrack_prob_prev_xsect(p_v1 = .1, n = 465, precision = 0.25, omega = 1, c_ratio = 1/0.84), 0.95) 30 | 31 | expect_gt(vartrack_prob_prev_xsect(p_v1 = .1, n = 582, precision = 0.25, omega = 0.8, c_ratio = 1/0.84), 0.95) 32 | }) 33 | -------------------------------------------------------------------------------- /man/obs_pairs_mtsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/obs_pairs_mtsl.R 3 | \name{obs_pairs_mtsl} 4 | \alias{obs_pairs_mtsl} 5 | \title{Expected number of observed pairs assuming multiple-transmission and single-linkage} 6 | \usage{ 7 | obs_pairs_mtsl(chi, eta, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 11 | 12 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | 18 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 19 | } 20 | \value{ 21 | scalar or vector giving the expected number of linked pairs observed in the sample 22 | } 23 | \description{ 24 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 25 | This function calculates the expected number of pairs observed in a sample of size \code{M}. 26 | The multiple-transmission and single-linkage method assumes the following: 27 | \enumerate{ 28 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 29 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 30 | } 31 | } 32 | \examples{ 33 | # Perfect sensitivity and specificity 34 | obs_pairs_mtsl(eta=1, chi=1, rho=0.5, M=100, R=1) 35 | 36 | obs_pairs_mtsl(eta=0.99, chi=0.9, rho=1, M=50, R=1) 37 | 38 | obs_pairs_mtsl(eta=0.99, chi=0.9, rho=0.5, M=100, R=1) 39 | 40 | } 41 | \seealso{ 42 | Other obs_pairs: 43 | \code{\link{exp_links}()}, 44 | \code{\link{obs_pairs_mtml}()}, 45 | \code{\link{obs_pairs_stsl}()} 46 | } 47 | \author{ 48 | John Giles, Shirlee Wohl and Justin Lessler 49 | } 50 | \concept{obs_pairs} 51 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(exp_links) 4 | export(falsediscoveryrate) 5 | export(gen_dists) 6 | export(gendist_distribution) 7 | export(gendist_roc_format) 8 | export(gendist_sensspec_cutoff) 9 | export(get_optim_roc) 10 | export(obs_pairs_mtml) 11 | export(obs_pairs_mtsl) 12 | export(obs_pairs_stsl) 13 | export(optim_roc_threshold) 14 | export(prob_trans_mtml) 15 | export(prob_trans_mtsl) 16 | export(prob_trans_stsl) 17 | export(relR_power) 18 | export(relR_power_simulated) 19 | export(relR_samplesize) 20 | export(relR_samplesize_basic) 21 | export(relR_samplesize_ci) 22 | export(samplesize) 23 | export(sens_spec_calc) 24 | export(sens_spec_roc) 25 | export(translink_expected_links_obs) 26 | export(translink_expected_links_obs_mtml) 27 | export(translink_expected_links_obs_mtsl) 28 | export(translink_expected_links_obs_stsl) 29 | export(translink_expected_links_true) 30 | export(translink_expected_links_true_mtml) 31 | export(translink_expected_links_true_mtsl) 32 | export(translink_expected_links_true_stsl) 33 | export(translink_fdr) 34 | export(translink_prob_transmit) 35 | export(translink_prob_transmit_mtml) 36 | export(translink_prob_transmit_mtsl) 37 | export(translink_prob_transmit_stsl) 38 | export(translink_samplesize) 39 | export(translink_tdr) 40 | export(true_pairs) 41 | export(true_pairs_mtml) 42 | export(true_pairs_mtsl) 43 | export(true_pairs_stsl) 44 | export(truediscoveryrate) 45 | export(varfreq_cdf_logistic) 46 | export(varfreq_expected_mbias) 47 | export(varfreq_freq_logistic) 48 | export(varfreq_obs_freq) 49 | export(vartrack_cod_ratio) 50 | export(vartrack_prob_detect) 51 | export(vartrack_prob_detect_cont) 52 | export(vartrack_prob_detect_xsect) 53 | export(vartrack_prob_prev) 54 | export(vartrack_prob_prev_xsect) 55 | export(vartrack_samplesize_detect) 56 | export(vartrack_samplesize_detect_cont) 57 | export(vartrack_samplesize_detect_xsect) 58 | export(vartrack_samplesize_prev) 59 | export(vartrack_samplesize_prev_xsect) 60 | importFrom(lifecycle,deprecated) 61 | -------------------------------------------------------------------------------- /man/optim_roc_threshold.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/optim_roc_threshold.R 3 | \name{optim_roc_threshold} 4 | \alias{optim_roc_threshold} 5 | \title{Find optimal ROC threshold} 6 | \usage{ 7 | optim_roc_threshold(roc) 8 | } 9 | \arguments{ 10 | \item{roc}{a dataframe produced by the \code{gendist_roc_format()} function containing the Receiver Operating Characteristic (ROC) curve} 11 | } 12 | \value{ 13 | vector containing optimal thresholds of sensitivity and specificity 14 | } 15 | \description{ 16 | This function takes the dataframe output of the \code{gendist_roc_format()} function and finds the optimal threshold 17 | of sensitivity and specificity by minimizing the distance to the top left corner of the Receiver Operating Characteristic (ROC) curve 18 | } 19 | \examples{ 20 | # ebola-like pathogen 21 | R <- 1.5 22 | mut_rate <- 1 23 | 24 | # use simulated generation distributions 25 | data("genDistSim") 26 | mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 27 | 28 | # get theoretical genetic distance dist based on mutation rate and generation parameters 29 | dists <- as.data.frame(gendist_distribution(mut_rate = mut_rate, 30 | mean_gens_pdf = mean_gens_pdf, 31 | max_link_gens = 1)) 32 | 33 | # reshape dataframe for plotting 34 | dists <- reshape2::melt(dists, 35 | id.vars = "dist", 36 | variable.name = "status", 37 | value.name = "prob") 38 | 39 | # get sensitivity and specificity using the same paramters 40 | roc_calc <- gendist_roc_format(cutoff = 1:(max(dists$dist)-1), 41 | mut_rate = mut_rate, 42 | mean_gens_pdf = mean_gens_pdf) 43 | 44 | # get the optimal value for the ROC plot 45 | optim_point <- optim_roc_threshold(roc_calc) 46 | 47 | } 48 | \seealso{ 49 | Other ROC functions: 50 | \code{\link{gendist_roc_format}()} 51 | } 52 | \author{ 53 | Shirlee Wohl, John Giles, and Justin Lessler 54 | } 55 | \concept{ROC functions} 56 | -------------------------------------------------------------------------------- /man/prob_trans_mtsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prob_trans_mtsl.R 3 | \name{prob_trans_mtsl} 4 | \alias{prob_trans_mtsl} 5 | \title{Probability of transmission assuming multiple-transmission and single-linkage} 6 | \usage{ 7 | prob_trans_mtsl(chi, eta, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 11 | 12 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | 18 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 19 | } 20 | \value{ 21 | scalar or vector giving the probability of transmission between two cases given linkage by phylogenetic criteria 22 | } 23 | \description{ 24 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 25 | This function calculates the probability that two cases are linked by direct transmission 26 | given that they have been linked by phylogenetic criteria. The multiple-transmission and single-linkage method assumes the following: 27 | \enumerate{ 28 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 29 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 30 | } 31 | } 32 | \examples{ 33 | # Perfect sensitivity and specificity 34 | prob_trans_mtsl(eta=1, chi=1, rho=0.5, M=100, R=1) 35 | 36 | prob_trans_mtsl(eta=0.99, chi=0.9, rho=1, M=50, R=1) 37 | 38 | prob_trans_mtsl(eta=0.99, chi=0.9, rho=0.5, M=100, R=1) 39 | 40 | } 41 | \seealso{ 42 | Other prob_trans: 43 | \code{\link{prob_trans_mtml}()}, 44 | \code{\link{prob_trans_stsl}()} 45 | } 46 | \author{ 47 | John Giles, Shirlee Wohl, and Justin Lessler 48 | } 49 | \concept{prob_trans} 50 | -------------------------------------------------------------------------------- /man/true_pairs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/true_pairs.R 3 | \name{true_pairs} 4 | \alias{true_pairs} 5 | \title{Calculate expected number of true transmission pairs} 6 | \usage{ 7 | true_pairs(eta, rho, M, R = NULL, assumption = "mtml") 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | 16 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen (default=NULL)} 17 | 18 | \item{assumption}{a character vector indicating which assumptions about transmission and linkage criteria. Default = \code{'mtml'}. Accepted arguments are: 19 | \enumerate{ 20 | \item \code{'stsl'} for the single-transmission single-linkage assumption (\code{\link[=prob_trans_stsl]{prob_trans_stsl()}}). 21 | \item \code{'mtsl'} for the multiple-transmission single-linkage assumption (\code{\link[=prob_trans_mtsl]{prob_trans_mtsl()}}). 22 | \item \code{'mtml'} for the multiple-transmission multiple-linkage assumption (\code{\link[=prob_trans_mtml]{prob_trans_mtml()}}). 23 | }} 24 | } 25 | \value{ 26 | scalar or vector giving the expected number of true transmission pairs in the sample 27 | } 28 | \description{ 29 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 30 | This function calculates the expected number true transmission pairs in a sample of size \code{M}. 31 | Assumptions about transmission and linkage (single or multiple) can be specified. 32 | } 33 | \examples{ 34 | true_pairs(eta=0.99, rho=0.75, M=100, R=1) 35 | 36 | } 37 | \seealso{ 38 | Other true_pairs: 39 | \code{\link{true_pairs_mtml}()}, 40 | \code{\link{true_pairs_mtsl}()}, 41 | \code{\link{true_pairs_stsl}()} 42 | } 43 | \author{ 44 | John Giles, Shirlee Wohl, and Justin Lessler 45 | } 46 | \concept{true_pairs} 47 | -------------------------------------------------------------------------------- /man/vartrack_prob_detect_xsect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_prob_detect_xsect.R 3 | \name{vartrack_prob_detect_xsect} 4 | \alias{vartrack_prob_detect_xsect} 5 | \title{Calculate probability of detecting a variant assuming cross-sectional sampling} 6 | \usage{ 7 | vartrack_prob_detect_xsect(p_v1, n, omega, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{p_v1}{variant prevalence (proportion)} 11 | 12 | \item{n}{sample size} 13 | 14 | \item{omega}{probability of sequencing (or other characterization) success} 15 | 16 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 17 | } 18 | \value{ 19 | scalar of expected sample size 20 | } 21 | \description{ 22 | This function calculates the probability of detecting the presence of a variant 23 | given a sample size and assuming a single, cross-sectional sample of detected infections. 24 | } 25 | \examples{ 26 | vartrack_prob_detect_xsect(p_v1 = 0.02, n = 100, omega = 0.8, c_ratio = 1) 27 | 28 | } 29 | \seealso{ 30 | Other variant detection functions: 31 | \code{\link{vartrack_prob_detect_cont}()}, 32 | \code{\link{vartrack_prob_detect}()}, 33 | \code{\link{vartrack_samplesize_detect_cont}()}, 34 | \code{\link{vartrack_samplesize_detect_xsect}()}, 35 | \code{\link{vartrack_samplesize_detect}()} 36 | 37 | Other variant tracking functions: 38 | \code{\link{vartrack_cod_ratio}()}, 39 | \code{\link{vartrack_prob_detect_cont}()}, 40 | \code{\link{vartrack_prob_detect}()}, 41 | \code{\link{vartrack_prob_prev_xsect}()}, 42 | \code{\link{vartrack_prob_prev}()}, 43 | \code{\link{vartrack_samplesize_detect_cont}()}, 44 | \code{\link{vartrack_samplesize_detect_xsect}()}, 45 | \code{\link{vartrack_samplesize_detect}()}, 46 | \code{\link{vartrack_samplesize_prev_xsect}()}, 47 | \code{\link{vartrack_samplesize_prev}()} 48 | } 49 | \author{ 50 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 51 | } 52 | \concept{variant detection functions} 53 | \concept{variant tracking functions} 54 | -------------------------------------------------------------------------------- /R/vartrack_prob_prev_xsect.R: -------------------------------------------------------------------------------- 1 | ##' Calculate confidence in a variant estimate assuming cross-sectional sampling 2 | ##' 3 | ##' This function calculates the probability of accurately estimating variant prevalence 4 | ##' given a given a sample size and desired precision in the variant prevalence estimate, 5 | ##' and assuming a single, cross-sectional sample of detected infections. 6 | ##' 7 | ##' @param p_v1 variant prevalence (proportion) 8 | ##' @param n sample size 9 | ##' @param omega probability of sequencing (or other characterization) success 10 | ##' @param precision desired precision in variant prevalence estimate 11 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 12 | ##' @return scalar of expected sample size 13 | ##' 14 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 15 | ##' 16 | ##' @examples 17 | ##' vartrack_prob_prev_xsect(p_v1 = 0.1, n = 200, precision = 0.1, omega = 0.8, c_ratio = 1) 18 | ##' 19 | ##' @family variant prevalence estimation functions 20 | ##' @family variant tracking functions 21 | ##' 22 | ##' @export 23 | 24 | 25 | vartrack_prob_prev_xsect <- function(p_v1, n, omega, precision, c_ratio = 1) { 26 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) stop("Variant prevalence must be numeric and between 0 and 1.") 27 | if (!all(is.numeric(n), n > 0)) stop("Sample size must be numeric and greater than 0.") 28 | if (!all(is.numeric(omega), omega > 0 & omega <= 1)) stop("Probability of characterization success must be numeric and between 0 and 1.") 29 | if (!all(is.numeric(precision), precision > 0 & precision < 1)) stop("Desired precision must be numeric and between 0 and 1.") 30 | if (!all(is.numeric(c_ratio), c_ratio > 0)) stop("Coefficient of detection ratio must be numeric and greater than 0.") 31 | 32 | p_star <- varfreq_obs_freq(p_v1, c_ratio) 33 | n_star <- n * omega 34 | z <- sqrt( (n_star * ((p_star*precision)^2) ) / (p_star * (1-p_star)) ) 35 | prob <- 1 - (2*(1-stats::pnorm(z))) 36 | return(prob) 37 | } 38 | -------------------------------------------------------------------------------- /R/optim_roc_threshold.R: -------------------------------------------------------------------------------- 1 | ##' Find optimal ROC threshold 2 | ##' 3 | ##' This function takes the dataframe output of the `gendist_roc_format()` function and finds the optimal threshold 4 | ##' of sensitivity and specificity by minimizing the distance to the top left corner of the Receiver Operating Characteristic (ROC) curve 5 | ##' 6 | ##' @param roc a dataframe produced by the `gendist_roc_format()` function containing the Receiver Operating Characteristic (ROC) curve 7 | ##' 8 | ##' @return vector containing optimal thresholds of sensitivity and specificity 9 | ##' 10 | ##' @author Shirlee Wohl, John Giles, and Justin Lessler 11 | ##' 12 | ##' @examples 13 | ##' # ebola-like pathogen 14 | ##' R <- 1.5 15 | ##' mut_rate <- 1 16 | ##' 17 | ##' # use simulated generation distributions 18 | ##' data("genDistSim") 19 | ##' mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 20 | ##' 21 | ##' # get theoretical genetic distance dist based on mutation rate and generation parameters 22 | ##' dists <- as.data.frame(gendist_distribution(mut_rate = mut_rate, 23 | ##' mean_gens_pdf = mean_gens_pdf, 24 | ##' max_link_gens = 1)) 25 | ##' 26 | ##' # reshape dataframe for plotting 27 | ##' dists <- reshape2::melt(dists, 28 | ##' id.vars = "dist", 29 | ##' variable.name = "status", 30 | ##' value.name = "prob") 31 | ##' 32 | ##' # get sensitivity and specificity using the same paramters 33 | ##' roc_calc <- gendist_roc_format(cutoff = 1:(max(dists$dist)-1), 34 | ##' mut_rate = mut_rate, 35 | ##' mean_gens_pdf = mean_gens_pdf) 36 | ##' 37 | ##' # get the optimal value for the ROC plot 38 | ##' optim_point <- optim_roc_threshold(roc_calc) 39 | ##' 40 | ##' @family ROC functions 41 | ##' 42 | ##' @export 43 | ##' 44 | 45 | optim_roc_threshold <- function(roc) { 46 | roc <- roc[-1, ] # remove first row with zero threshold 47 | dist <- sqrt((1 - roc$sensitivity)^2 + (roc$specificity)^2) 48 | as.list(roc[dist == min(dist), ]) 49 | } 50 | -------------------------------------------------------------------------------- /man/prob_trans_stsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prob_trans_stsl.R 3 | \name{prob_trans_stsl} 4 | \alias{prob_trans_stsl} 5 | \title{Probability of transmission assuming single-transmission and single-linkage} 6 | \usage{ 7 | prob_trans_stsl(eta, chi, rho, M) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | } 18 | \value{ 19 | scalar or vector giving the probability of transmission between two cases given linkage by phylogenetic criteria 20 | } 21 | \description{ 22 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 23 | This function calculates the probability that two cases are linked by direct transmission 24 | given that they have been linked by phylogenetic criteria. The single-transmission and single-linkage method assumes the following: 25 | \enumerate{ 26 | \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 27 | \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 28 | } 29 | 30 | For perfect sensitivity, set \code{eta = 1}. 31 | } 32 | \examples{ 33 | # perfect sensitivity and specificity 34 | prob_trans_stsl(eta=1, chi=1, rho=0.2, M=100) 35 | 36 | # perfect sensitivity only 37 | prob_trans_stsl(eta=1, chi=0.95, rho=0.2, M=100) 38 | 39 | prob_trans_stsl(eta=0.99, chi=0.95, rho=0.9, M=50) 40 | 41 | prob_trans_stsl(eta=0.99, chi=0.95, rho=0.05, M=100) 42 | 43 | } 44 | \seealso{ 45 | Other prob_trans: 46 | \code{\link{prob_trans_mtml}()}, 47 | \code{\link{prob_trans_mtsl}()} 48 | } 49 | \author{ 50 | John Giles, Shirlee Wohl, and Justin Lessler 51 | } 52 | \concept{prob_trans} 53 | -------------------------------------------------------------------------------- /man/samplesize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/samplesize.R 3 | \name{samplesize} 4 | \alias{samplesize} 5 | \title{Calculate sample size} 6 | \usage{ 7 | samplesize(eta, chi, N, R = NULL, phi, min_pairs = 1, assumption = "mtml") 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 13 | 14 | \item{N}{scalar or vector giving the final outbreak size} 15 | 16 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 17 | 18 | \item{phi}{scalar or vector giving the desired true discovery rate (1-false discovery rate)} 19 | 20 | \item{min_pairs}{minimum number of linked pairs observed in the sample, defaults to 1 pair (2 samples); this is to ensure reasonable results are obtained} 21 | 22 | \item{assumption}{a character vector indicating which assumptions about transmission and linkage criteria. Default = \code{'mtml'}. Accepted arguments are: 23 | \enumerate{ 24 | \item \code{'stsl'} for the single-transmission single-linkage assumption (\code{\link[=prob_trans_stsl]{prob_trans_stsl()}}). 25 | \item \code{'mtsl'} for the multiple-transmission single-linkage assumption (\code{\link[=prob_trans_mtsl]{prob_trans_mtsl()}}). 26 | \item \code{'mtml'} for the multiple-transmission multiple-linkage assumption (\code{\link[=prob_trans_mtml]{prob_trans_mtml()}}). 27 | }} 28 | } 29 | \value{ 30 | scalar or vector giving the sample size needed to meet the given conditions 31 | } 32 | \description{ 33 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 34 | This function calculates the sample size needed to obtain at least a defined false discovery rate given 35 | a final outbreak size \eqn{N}. 36 | } 37 | \examples{ 38 | samplesize(eta=0.99, chi=0.995, N=100, R=1, phi=0.75) 39 | 40 | } 41 | \author{ 42 | John Giles, Shirlee Wohl, and Justin Lessler 43 | } 44 | \concept{inverse_functions} 45 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /R/translink_expected_links_true_mtsl.R: -------------------------------------------------------------------------------- 1 | ##' Calculate expected number of true transmission pairs assuming multiple-transmission and single-linkage 2 | ##' 3 | ##' This function calculates the expected number true transmission pairs in a sample of size `M`. 4 | ##' The multiple-transmission and single-linkage method assumes the following: 5 | ##' \enumerate{ 6 | ##' \item Each case \eqn{i} is, on average, the infector of `R` cases in the population (\eqn{N}) 7 | ##' \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 8 | ##' } 9 | ##' 10 | ##' @param sensitivity scalar or vector giving the sensitivity of the linkage criteria 11 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 12 | ##' @param M scalar or vector giving the number of cases sampled 13 | ##' @param R scalar or vector giving the effective reproductive number of the pathogen 14 | ##' 15 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 16 | ##' 17 | ##' @author John Giles, Shirlee Wohl and Justin Lessler 18 | ##' 19 | ##' @examples 20 | ##' translink_expected_links_true_mtsl(sensitivity=0.95, rho=0.2, M=200, R=1) 21 | ##' 22 | ##' @family transmission linkage functions 23 | ##' 24 | ##' @export 25 | ##' 26 | ##' 27 | 28 | translink_expected_links_true_mtsl <- function(sensitivity, rho, M, R) { 29 | if (!all(is.numeric(sensitivity), sensitivity >= 0 & sensitivity <= 1)) 30 | stop("sensitivity must be numeric between 0 and 1") 31 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 32 | stop("rho must be numeric > 0 and <= 1") 33 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 34 | stop("Sample size (M) must be integer or numeric greater than 0") 35 | if (!all(is.numeric(R), R > 0)) 36 | stop("Reproductive number (R) must be numeric greater than 0") 37 | if (!all(is.numeric(R), R <= 1)) 38 | warning("Reproductive number (R) is usually less than 1 for finite outbreaks") 39 | 40 | (M * rho * (R + 1) * sensitivity)/2 41 | } 42 | -------------------------------------------------------------------------------- /R/vartrack_prob_prev.R: -------------------------------------------------------------------------------- 1 | ##' Calculate confidence in a variant estimate given a sample size 2 | ##' 3 | ##' This function calculates the probability of accurately estimating variant prevalence 4 | ##' given a sample size and desired precision in the variant prevalence estimate. 5 | ##' Currently, only cross-sectional sampling is supported. 6 | ##' 7 | ##' @param p_v1 variant prevalence (proportion) 8 | ##' @param n sample size 9 | ##' @param omega probability of sequencing (or other characterization) success 10 | ##' @param precision desired precision in variant prevalence estimate 11 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 12 | ##' @param sampling_freq the sampling frequency (must be either 'xsect' in current implementation) 13 | ##' @return scalar of expected sample size 14 | ##' 15 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 16 | ##' 17 | ##' @examples 18 | ##' vartrack_prob_prev(p_v1 = 0.1, n = 200, omega = 0.8, precision = 0.1, 19 | ##' c_ratio = 1, sampling_freq = 'xsect') 20 | ##' 21 | ##' @family variant prevalence estimation functions 22 | ##' @family variant tracking functions 23 | ##' 24 | ##' @export 25 | 26 | 27 | vartrack_prob_prev <- function(p_v1, n, omega, precision, c_ratio = 1, sampling_freq) { 28 | 29 | if (sampling_freq == "xsect") { 30 | message("Calculating confidence in variant estimate assuming single cross-sectional sample") 31 | out <- vartrack_prob_prev_xsect(p_v1 = p_v1, n = n, omega = omega, precision = precision, 32 | c_ratio = c_ratio) 33 | 34 | } else if (sampling_freq == "cont") { 35 | stop("Functionality for calculating confidence in variant estimate given periodic sampling is not yet implemented in the phylosamp package. You can calculate the confidence in variant estimating given a cross-sectional sample by specifying 'xsect' as the sampling frequency") 36 | 37 | } else { 38 | stop("Incorrect sampling frequency argument (please specify 'xsect' or 'cont')") 39 | } 40 | 41 | return(out) 42 | } 43 | -------------------------------------------------------------------------------- /man/gendist_distribution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gendist_distribution.R 3 | \name{gendist_distribution} 4 | \alias{gendist_distribution} 5 | \title{Calculate genetic distance distribution} 6 | \usage{ 7 | gendist_distribution( 8 | mut_rate, 9 | mean_gens_pdf, 10 | max_link_gens = 1, 11 | max_gens = NULL, 12 | max_dist = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{mut_rate}{mean number of mutations per generation, assumed to be Poisson distributed} 17 | 18 | \item{mean_gens_pdf}{the density distribution of the mean number of generations between cases; 19 | the index of this vector is assumed to be the discrete distance between cases} 20 | 21 | \item{max_link_gens}{the maximum generations of separation for linked pairs} 22 | 23 | \item{max_gens}{the maximum number of generations to consider, if \code{NULL} (default) value is set to the highest 24 | number of generations in mean_gens_pdf with a non-zero probability} 25 | 26 | \item{max_dist}{the maximum distance to calculate, if \code{NULL} (default) value is set to max_gens * 99.9th percentile 27 | of mut_rate Poisson distribution} 28 | } 29 | \value{ 30 | a data frame with distances and probabilities 31 | } 32 | \description{ 33 | Function calculates the distribution of genetic distances in a population of viruses 34 | with the given parameters 35 | } 36 | \examples{ 37 | # ebola-like pathogen 38 | R <- 1.5 39 | mut_rate <- 1 40 | 41 | # use simulated generation distributions from the provided 'genDistSim' data object 42 | data('genDistSim') 43 | mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 44 | 45 | # get theoretical genetic distance dist based on mutation rate and generation parameters 46 | gendist_distribution(mut_rate = mut_rate, 47 | mean_gens_pdf = mean_gens_pdf, 48 | max_link_gens = 1) 49 | 50 | } 51 | \seealso{ 52 | Other genetic distance functions: 53 | \code{\link{gendist_roc_format}()}, 54 | \code{\link{gendist_sensspec_cutoff}()} 55 | } 56 | \author{ 57 | Shirlee Wohl and Justin Lessler 58 | } 59 | \concept{genetic distance functions} 60 | -------------------------------------------------------------------------------- /tests/testthat/test-vartrack_samplesize_detect_xsect.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("vartrack_samplesize_detect_xsect input arguments are valid", { 3 | 4 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0, prob = 0.4, omega = 0.9, 5 | c_ratio = 1)) 6 | 7 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 1.1, prob = 0.9, omega = 0.9, 8 | c_ratio = 1)) 9 | 10 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = Inf, prob = 0.7, omega = 0.9, 11 | c_ratio = 1)) 12 | 13 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = -0.2, omega = 0.9, 14 | c_ratio = 1.3)) 15 | 16 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = 1, omega = 0.9, 17 | c_ratio = 1.5)) 18 | 19 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = "invalid", omega = 0.9, 20 | c_ratio = 0.9)) 21 | 22 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = 0.8, omega = "invalid", 23 | c_ratio = 0.9)) 24 | 25 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = 0.8, omega = -0.3, 26 | c_ratio = 0.9)) 27 | 28 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = 0.8, omega = 1.5, 29 | c_ratio = 0.9)) 30 | 31 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.1, prob = 0.3, omega = 0.9, 32 | c_ratio = -0.9)) 33 | 34 | expect_error(vartrack_samplesize_detect_xsect(p_v1 = 0.1, prob = 0.2, omega = 0.9, 35 | c_ratio = "invalid")) 36 | }) 37 | 38 | test_that("vartrack_samplesize_detect_xsect return object is valid double", { 39 | 40 | expect_type(vartrack_samplesize_detect_xsect(p_v1 = 0.2, prob = 0.9, omega = 0.9, 41 | c_ratio = 1.5), "double") 42 | 43 | }) 44 | 45 | test_that("vartrack_samplesize_detect_xsect manuscript results remain valid", { 46 | 47 | expect_equal(ceiling(vartrack_samplesize_detect_xsect(p_v1 = 0.02, prob = 0.95, 48 | omega = 1, c_ratio = 1)), 149) 49 | 50 | expect_equal(ceiling(vartrack_samplesize_detect_xsect(p_v1 = 0.02, prob = 0.95, 51 | omega = 1, c_ratio = (0.8 * 0.975)/(0.6 * 0.95))), 109) 52 | }) 53 | -------------------------------------------------------------------------------- /man/relR_power_simulated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/relR_power_simulated.R 3 | \name{relR_power_simulated} 4 | \alias{relR_power_simulated} 5 | \title{Simulate power for detecting differential transmission} 6 | \usage{ 7 | relR_power_simulated( 8 | m, 9 | R_a, 10 | R_b, 11 | p_a, 12 | N, 13 | alpha = 0.05, 14 | alternative = c("two_sided", "less", "greater"), 15 | sensitivity = 1, 16 | specificity = 1, 17 | overdispersion = NULL, 18 | nsims = 1e+05 19 | ) 20 | } 21 | \arguments{ 22 | \item{m}{the sample size.} 23 | 24 | \item{R_a}{Numeric (Positive). The assumed R among the group in the 25 | denominator of the ratio. Input value must be greater than 0.} 26 | 27 | \item{R_b}{Numeric (Positive). The assumed R among the group in the 28 | numerator of the ratio. Input value must be greater than 0.} 29 | 30 | \item{p_a}{Numeric. The proportion of the population in group \code{a}. Must be 31 | between 0 and 1.} 32 | 33 | \item{N}{Numeric (Positive). The size of the infected pool. Only one of 34 | \code{rho} or \code{N} should be specified.} 35 | 36 | \item{alpha}{Numeric. The desired alpha level. Default: 0.05} 37 | 38 | \item{alternative}{Character. Specifies the alternative hypothesis. 39 | Must be: \code{two_sided} (Default), \code{less}, or \code{greater}} 40 | 41 | \item{sensitivity}{Numeric. The sensitivity of the linkage criteria. 42 | Must be between 0 and 1. Default: 1.} 43 | 44 | \item{specificity}{Numeric. The specificity of the linkage criteria. 45 | Must be between 0 and 1. Default: 1.} 46 | 47 | \item{overdispersion}{Numeric (Positive). An overdispersion parameter, set 48 | if the assumed distribution of the number of edges is negative binomial. 49 | If \code{NULL} the assumed distribution is Poisson (equivalent to an 50 | overdispersion parameter of infinity) Default: \code{NULL} Note that this is 51 | equivalent to setting the overdispersion parameter to \code{Inf}.} 52 | 53 | \item{nsims}{Numeric. The number of simulations. Default: 100000} 54 | } 55 | \value{ 56 | Simulated power 57 | } 58 | \description{ 59 | Simulate power for detecting differential transmission 60 | } 61 | -------------------------------------------------------------------------------- /man/vartrack_prob_prev_xsect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_prob_prev_xsect.R 3 | \name{vartrack_prob_prev_xsect} 4 | \alias{vartrack_prob_prev_xsect} 5 | \title{Calculate confidence in a variant estimate assuming cross-sectional sampling} 6 | \usage{ 7 | vartrack_prob_prev_xsect(p_v1, n, omega, precision, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{p_v1}{variant prevalence (proportion)} 11 | 12 | \item{n}{sample size} 13 | 14 | \item{omega}{probability of sequencing (or other characterization) success} 15 | 16 | \item{precision}{desired precision in variant prevalence estimate} 17 | 18 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 19 | } 20 | \value{ 21 | scalar of expected sample size 22 | } 23 | \description{ 24 | This function calculates the probability of accurately estimating variant prevalence 25 | given a given a sample size and desired precision in the variant prevalence estimate, 26 | and assuming a single, cross-sectional sample of detected infections. 27 | } 28 | \examples{ 29 | vartrack_prob_prev_xsect(p_v1 = 0.1, n = 200, precision = 0.1, omega = 0.8, c_ratio = 1) 30 | 31 | } 32 | \seealso{ 33 | Other variant prevalence estimation functions: 34 | \code{\link{vartrack_prob_prev}()}, 35 | \code{\link{vartrack_samplesize_prev_xsect}()}, 36 | \code{\link{vartrack_samplesize_prev}()} 37 | 38 | Other variant tracking functions: 39 | \code{\link{vartrack_cod_ratio}()}, 40 | \code{\link{vartrack_prob_detect_cont}()}, 41 | \code{\link{vartrack_prob_detect_xsect}()}, 42 | \code{\link{vartrack_prob_detect}()}, 43 | \code{\link{vartrack_prob_prev}()}, 44 | \code{\link{vartrack_samplesize_detect_cont}()}, 45 | \code{\link{vartrack_samplesize_detect_xsect}()}, 46 | \code{\link{vartrack_samplesize_detect}()}, 47 | \code{\link{vartrack_samplesize_prev_xsect}()}, 48 | \code{\link{vartrack_samplesize_prev}()} 49 | } 50 | \author{ 51 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 52 | } 53 | \concept{variant prevalence estimation functions} 54 | \concept{variant tracking functions} 55 | -------------------------------------------------------------------------------- /man/vartrack_samplesize_detect_xsect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_samplesize_detect_xsect.R 3 | \name{vartrack_samplesize_detect_xsect} 4 | \alias{vartrack_samplesize_detect_xsect} 5 | \title{Calculate sample size needed for variant detection assuming cross-sectional sampling} 6 | \usage{ 7 | vartrack_samplesize_detect_xsect(p_v1, prob, omega, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{p_v1}{variant prevalence (proportion)} 11 | 12 | \item{prob}{desired probability of detection} 13 | 14 | \item{omega}{probability of sequencing (or other characterization) success} 15 | 16 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 17 | } 18 | \value{ 19 | scalar of expected sample size 20 | } 21 | \description{ 22 | This function calculates the sample size needed for detecting the presence of a variant 23 | given a desired probability of detection and assuming a single, cross-sectional sample of detected infections. 24 | } 25 | \examples{ 26 | vartrack_samplesize_detect_xsect(p_v1 = 0.1, prob = 0.95, omega = 0.8, c_ratio = 1) 27 | 28 | } 29 | \seealso{ 30 | Other variant detection functions: 31 | \code{\link{vartrack_prob_detect_cont}()}, 32 | \code{\link{vartrack_prob_detect_xsect}()}, 33 | \code{\link{vartrack_prob_detect}()}, 34 | \code{\link{vartrack_samplesize_detect_cont}()}, 35 | \code{\link{vartrack_samplesize_detect}()} 36 | 37 | Other variant tracking functions: 38 | \code{\link{vartrack_cod_ratio}()}, 39 | \code{\link{vartrack_prob_detect_cont}()}, 40 | \code{\link{vartrack_prob_detect_xsect}()}, 41 | \code{\link{vartrack_prob_detect}()}, 42 | \code{\link{vartrack_prob_prev_xsect}()}, 43 | \code{\link{vartrack_prob_prev}()}, 44 | \code{\link{vartrack_samplesize_detect_cont}()}, 45 | \code{\link{vartrack_samplesize_detect}()}, 46 | \code{\link{vartrack_samplesize_prev_xsect}()}, 47 | \code{\link{vartrack_samplesize_prev}()} 48 | } 49 | \author{ 50 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 51 | } 52 | \concept{variant detection functions} 53 | \concept{variant tracking functions} 54 | -------------------------------------------------------------------------------- /man/obs_pairs_mtml.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/obs_pairs_mtml.R 3 | \name{obs_pairs_mtml} 4 | \alias{obs_pairs_mtml} 5 | \title{Expected number of observed pairs assuming multiple-transmission and multiple-linkage} 6 | \usage{ 7 | obs_pairs_mtml(chi, eta, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 11 | 12 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | 18 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 19 | } 20 | \value{ 21 | scalar or vector giving the expected number of linked pairs observed in the sample 22 | } 23 | \description{ 24 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 25 | This function calculates the expected number of pairs observed in a sample of size \code{M}. 26 | The multiple-transmission and multiple-linkage method assumes the following: 27 | \enumerate{ 28 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 29 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to multiple cases \eqn{j} in the sampled population (\eqn{M}). 30 | \item Linkage events are independent of one another (i.e, linkage of case \eqn{i} to case \eqn{j} has no bearing on linkage of case \eqn{i} to any other sample). 31 | } 32 | } 33 | \examples{ 34 | # Perfect sensitivity and specificity 35 | obs_pairs_mtml(eta=1, chi=1, rho=0.5, M=100, R=1) 36 | 37 | obs_pairs_mtml(eta=0.99, chi=0.9, rho=1, M=50, R=1) 38 | 39 | obs_pairs_mtml(eta=0.99, chi=0.9, rho=0.5, M=100, R=1) 40 | 41 | } 42 | \seealso{ 43 | Other obs_pairs: 44 | \code{\link{exp_links}()}, 45 | \code{\link{obs_pairs_mtsl}()}, 46 | \code{\link{obs_pairs_stsl}()} 47 | } 48 | \author{ 49 | John Giles, Shirlee Wohl and Justin Lessler 50 | } 51 | \concept{obs_pairs} 52 | -------------------------------------------------------------------------------- /man/gen_dists.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gen_dists.R 3 | \name{gen_dists} 4 | \alias{gen_dists} 5 | \title{Calculate genetic distance distribution} 6 | \usage{ 7 | gen_dists( 8 | mut_rate, 9 | mean_gens_pdf, 10 | max_link_gens = 1, 11 | max_gens = NULL, 12 | max_dist = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{mut_rate}{mean number of mutations per generation, assumed to be Poisson distributed} 17 | 18 | \item{mean_gens_pdf}{the density distribution of the mean number of generations between cases; 19 | the index of this vector is assumed to be the discrete distance between cases} 20 | 21 | \item{max_link_gens}{the maximum generations of separation for linked pairs} 22 | 23 | \item{max_gens}{the maximum number of generations to consider, if \code{NULL} (default) value is set to the highest 24 | number of generations in mean_gens_pdf with a non-zero probability} 25 | 26 | \item{max_dist}{the maximum distance to calculate, if \code{NULL} (default) value is set to max_gens * 99.9th percentile 27 | of mut_rate Poisson distribution} 28 | } 29 | \value{ 30 | a data frame with distances and probabilities 31 | } 32 | \description{ 33 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 34 | Function calculates the distribution of genetic distances in a population of viruses 35 | with the given parameters 36 | } 37 | \examples{ 38 | # ebola-like pathogen 39 | R <- 1.5 40 | mut_rate <- 1 41 | 42 | # use simulated generation distributions from the provided 'genDistSim' data object 43 | data('genDistSim') 44 | mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 45 | 46 | # get theoretical genetic distance dist based on mutation rate and generation parameters 47 | gen_dists(mut_rate = mut_rate, 48 | mean_gens_pdf = mean_gens_pdf, 49 | max_link_gens = 1) 50 | 51 | } 52 | \seealso{ 53 | Other mutrate_functions: 54 | \code{\link{get_optim_roc}()}, 55 | \code{\link{sens_spec_calc}()}, 56 | \code{\link{sens_spec_roc}()} 57 | } 58 | \author{ 59 | Shirlee Wohl and Justin Lessler 60 | } 61 | \concept{mutrate_functions} 62 | -------------------------------------------------------------------------------- /man/prob_trans_mtml.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prob_trans_mtml.R 3 | \name{prob_trans_mtml} 4 | \alias{prob_trans_mtml} 5 | \title{Probability of transmission assuming multiple-transmission and multiple-linkage} 6 | \usage{ 7 | prob_trans_mtml(eta, chi, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{eta}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{chi}{scalar or vector giving the specificity of the linkage criteria} 13 | 14 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 15 | 16 | \item{M}{scalar or vector giving the number of cases sampled} 17 | 18 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 19 | } 20 | \value{ 21 | scalar or vector giving the probability of transmission between two cases given linkage by phylogenetic criteria 22 | } 23 | \description{ 24 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 25 | This function calculates the probability that two cases are linked by direct transmission 26 | given that they have been linked by phylogenetic criteria. The multiple-transmission and multiple-linkage method assumes the following: 27 | \enumerate{ 28 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 29 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to multiple cases \eqn{j} in the sampled population (\eqn{M}). 30 | \item Linkage events are independent of one another (i.e, linkage of case \eqn{i} to case \eqn{j} has no bearing on linkage of case \eqn{i} to any other sample). 31 | } 32 | } 33 | \examples{ 34 | # Perfect sensitivity and specificity 35 | prob_trans_mtml(eta=1, chi=1, rho=0.5, M=100, R=1) 36 | 37 | prob_trans_mtml(eta=0.99, chi=0.9, rho=1, M=50, R=1) 38 | 39 | prob_trans_mtml(eta=0.99, chi=0.9, rho=0.5, M=100, R=1) 40 | 41 | } 42 | \seealso{ 43 | Other prob_trans: 44 | \code{\link{prob_trans_mtsl}()}, 45 | \code{\link{prob_trans_stsl}()} 46 | } 47 | \author{ 48 | John Giles, Shirlee Wohl, and Justin Lessler 49 | } 50 | \concept{prob_trans} 51 | -------------------------------------------------------------------------------- /R/get_optim_roc.R: -------------------------------------------------------------------------------- 1 | ##' Find optimal ROC threshold 2 | ##' 3 | ##' @description 4 | ##' `r lifecycle::badge('deprecated')` 5 | ##' This function takes the dataframe output of the `sens_spec_roc()` function and finds the optimal threshold 6 | ##' of sensitivity and specificity by minimizing the distance to the top left corner of the Receiver Operating Characteristic (ROC) curve 7 | ##' 8 | ##' @param roc a dataframe produced by the `sens_spec_roc()` function containing the Receiver Operating Characteristic (ROC) curve 9 | ##' 10 | ##' @return vector containing optimal thresholds of sensitivity and specificity 11 | ##' 12 | ##' @author Shirlee Wohl, John Giles, and Justin Lessler 13 | ##' 14 | ##' @examples 15 | ##' # ebola-like pathogen 16 | ##' R <- 1.5 17 | ##' mut_rate <- 1 18 | ##' 19 | ##' # use simulated generation distributions 20 | ##' data(genDistSim) 21 | ##' mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 22 | ##' 23 | ##' # get theoretical genetic distance dist based on mutation rate and generation parameters 24 | ##' dists <- as.data.frame(gen_dists(mut_rate = mut_rate, 25 | ##' mean_gens_pdf = mean_gens_pdf, 26 | ##' max_link_gens = 1)) 27 | ##' 28 | ##' # reshape dataframe for plotting 29 | ##' dists <- reshape2::melt(dists, 30 | ##' id.vars = 'dist', 31 | ##' variable.name = 'status', 32 | ##' value.name = 'prob') 33 | ##' 34 | ##' # get sensitivity and specificity using the same paramters 35 | ##' roc_calc <- sens_spec_roc(cutoff = 1:(max(dists$dist)-1), 36 | ##' mut_rate = mut_rate, 37 | ##' mean_gens_pdf = mean_gens_pdf) 38 | ##' 39 | ##' # get the optimal value for the ROC plot 40 | ##' optim_point <- get_optim_roc(roc_calc) 41 | ##' 42 | ##' @family mutrate_functions 43 | ##' 44 | ##' @export 45 | ##' 46 | 47 | get_optim_roc <- function(roc) { 48 | lifecycle::deprecate_soft("1.0.0", "get_optim_roc()", "optim_roc_threshold()") 49 | 50 | roc <- roc[-1, ] # remove first row with zero threshold 51 | dist <- sqrt((1 - roc$sensitivity)^2 + (roc$specificity)^2) 52 | as.list(roc[dist == min(dist), ]) 53 | } 54 | -------------------------------------------------------------------------------- /man/vartrack_samplesize_prev_xsect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_samplesize_prev_xsect.R 3 | \name{vartrack_samplesize_prev_xsect} 4 | \alias{vartrack_samplesize_prev_xsect} 5 | \title{Calculate sample size needed for variant prevalence estimation under cross-sectional sampling} 6 | \usage{ 7 | vartrack_samplesize_prev_xsect(p_v1, prob, precision, omega, c_ratio = 1) 8 | } 9 | \arguments{ 10 | \item{p_v1}{variant prevalence (proportion)} 11 | 12 | \item{prob}{desired confidence in variant prevalence estimate} 13 | 14 | \item{precision}{desired precision in variant prevalence estimate} 15 | 16 | \item{omega}{probability of sequencing (or other characterization) success} 17 | 18 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 19 | } 20 | \value{ 21 | scalar of sample size 22 | } 23 | \description{ 24 | This function calculates the sample size needed for estimating variant prevalence 25 | given a desired confidence and desired precision in the variant prevalence estimate 26 | and assuming a single, cross-sectional sample of detected infections. 27 | } 28 | \examples{ 29 | vartrack_samplesize_prev_xsect(p_v1 = 0.1, prob = 0.95, precision = 0.25, omega = 0.8, c_ratio = 1) 30 | 31 | } 32 | \seealso{ 33 | Other variant prevalence estimation functions: 34 | \code{\link{vartrack_prob_prev_xsect}()}, 35 | \code{\link{vartrack_prob_prev}()}, 36 | \code{\link{vartrack_samplesize_prev}()} 37 | 38 | Other variant tracking functions: 39 | \code{\link{vartrack_cod_ratio}()}, 40 | \code{\link{vartrack_prob_detect_cont}()}, 41 | \code{\link{vartrack_prob_detect_xsect}()}, 42 | \code{\link{vartrack_prob_detect}()}, 43 | \code{\link{vartrack_prob_prev_xsect}()}, 44 | \code{\link{vartrack_prob_prev}()}, 45 | \code{\link{vartrack_samplesize_detect_cont}()}, 46 | \code{\link{vartrack_samplesize_detect_xsect}()}, 47 | \code{\link{vartrack_samplesize_detect}()}, 48 | \code{\link{vartrack_samplesize_prev}()} 49 | } 50 | \author{ 51 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 52 | } 53 | \concept{variant prevalence estimation functions} 54 | \concept{variant tracking functions} 55 | -------------------------------------------------------------------------------- /man/relR_samplesize_basic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/relR_samplesize_basic.R 3 | \name{relR_samplesize_basic} 4 | \alias{relR_samplesize_basic} 5 | \title{Calculate simple derived sample size for detecting differential transmission} 6 | \usage{ 7 | relR_samplesize_basic( 8 | R_a, 9 | R_b, 10 | p_a, 11 | N, 12 | alpha = 0.05, 13 | alternative = c("two_sided", "less", "greater"), 14 | power = 0.8, 15 | overdispersion = NULL, 16 | allow_impossible_m = FALSE 17 | ) 18 | } 19 | \arguments{ 20 | \item{R_a}{Numeric (Positive). The assumed R among the group in the 21 | denominator of the ratio. Input value must be greater than 0.} 22 | 23 | \item{R_b}{Numeric (Positive). The assumed R among the group in the 24 | numerator of the ratio. Input value must be greater than 0.} 25 | 26 | \item{p_a}{Numeric. The proportion of the population in group \code{a}. Must be 27 | between 0 and 1.} 28 | 29 | \item{N}{Numeric (Positive). The size of the infected pool. Only one of 30 | \code{rho} or \code{N} should be specified.} 31 | 32 | \item{alpha}{Numeric. The desired alpha level. Default: 0.05} 33 | 34 | \item{alternative}{Character. Specifies the alternative hypothesis. 35 | Must be: \code{two_sided} (Default), \code{less}, or \code{greater}} 36 | 37 | \item{power}{Numeric. The desired power. Must be a value between 0 and 1. 38 | Default: 0.8.} 39 | 40 | \item{overdispersion}{Numeric (Positive). An overdispersion parameter, set 41 | if the assumed distribution of the number of edges is negative binomial. 42 | If \code{NULL} the assumed distribution is Poisson (equivalent to an 43 | overdispersion parameter of infinity) Default: \code{NULL} Note that this is 44 | equivalent to setting the overdispersion parameter to \code{Inf}.} 45 | 46 | \item{allow_impossible_m}{Logical. Indicates whether a value for \code{m} can be 47 | returned that is greater than the input \code{N}. Default: \code{FALSE}.} 48 | } 49 | \value{ 50 | The required sample size. \code{NA} if larger than \code{N}. 51 | } 52 | \description{ 53 | Function that does the simple derived sample size calculation with 54 | no corrections. I.e., directly applies the math as if sensitivity 55 | and specificity are perfect. 56 | } 57 | -------------------------------------------------------------------------------- /man/relR_samplesize_opterr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/relR_samplesize_solve.R 3 | \name{relR_samplesize_opterr} 4 | \alias{relR_samplesize_opterr} 5 | \title{Function to calculate the error in estimated sample size for use in optimize function} 6 | \usage{ 7 | relR_samplesize_opterr( 8 | m, 9 | R_a, 10 | R_b, 11 | p_a, 12 | N, 13 | alpha, 14 | alternative, 15 | power, 16 | sensitivity, 17 | specificity, 18 | overdispersion 19 | ) 20 | } 21 | \arguments{ 22 | \item{m}{the sample size.} 23 | 24 | \item{R_a}{Numeric (Positive). The assumed R among the group in the 25 | denominator of the ratio. Input value must be greater than 0.} 26 | 27 | \item{R_b}{Numeric (Positive). The assumed R among the group in the 28 | numerator of the ratio. Input value must be greater than 0.} 29 | 30 | \item{p_a}{Numeric. The proportion of the population in group \code{a}. Must be 31 | between 0 and 1.} 32 | 33 | \item{N}{Numeric (Positive). The size of the infected pool. Only one of 34 | \code{rho} or \code{N} should be specified.} 35 | 36 | \item{alpha}{Numeric. The desired alpha level. Default: 0.05} 37 | 38 | \item{alternative}{Character. Specifies the alternative hypothesis. 39 | Must be: \code{two_sided} (Default), \code{less}, or \code{greater}} 40 | 41 | \item{power}{Numeric. The desired power. Must be a value between 0 and 1. 42 | Default: 0.8.} 43 | 44 | \item{sensitivity}{Numeric. The sensitivity of the linkage criteria. 45 | Must be between 0 and 1. Default: 1.} 46 | 47 | \item{specificity}{Numeric. The specificity of the linkage criteria. 48 | Must be between 0 and 1. Default: 1.} 49 | 50 | \item{overdispersion}{Numeric (Positive). An overdispersion parameter, set 51 | if the assumed distribution of the number of edges is negative binomial. 52 | If \code{NULL} the assumed distribution is Poisson (equivalent to an 53 | overdispersion parameter of infinity) Default: \code{NULL} Note that this is 54 | equivalent to setting the overdispersion parameter to \code{Inf}.} 55 | } 56 | \value{ 57 | Squared error between the input sample size and estimated sample size 58 | } 59 | \description{ 60 | Function to calculate the error in estimated sample size for use in optimize function 61 | } 62 | -------------------------------------------------------------------------------- /man/vartrack_prob_prev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_prob_prev.R 3 | \name{vartrack_prob_prev} 4 | \alias{vartrack_prob_prev} 5 | \title{Calculate confidence in a variant estimate given a sample size} 6 | \usage{ 7 | vartrack_prob_prev(p_v1, n, omega, precision, c_ratio = 1, sampling_freq) 8 | } 9 | \arguments{ 10 | \item{p_v1}{variant prevalence (proportion)} 11 | 12 | \item{n}{sample size} 13 | 14 | \item{omega}{probability of sequencing (or other characterization) success} 15 | 16 | \item{precision}{desired precision in variant prevalence estimate} 17 | 18 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 19 | 20 | \item{sampling_freq}{the sampling frequency (must be either 'xsect' in current implementation)} 21 | } 22 | \value{ 23 | scalar of expected sample size 24 | } 25 | \description{ 26 | This function calculates the probability of accurately estimating variant prevalence 27 | given a sample size and desired precision in the variant prevalence estimate. 28 | Currently, only cross-sectional sampling is supported. 29 | } 30 | \examples{ 31 | vartrack_prob_prev(p_v1 = 0.1, n = 200, omega = 0.8, precision = 0.1, 32 | c_ratio = 1, sampling_freq = 'xsect') 33 | 34 | } 35 | \seealso{ 36 | Other variant prevalence estimation functions: 37 | \code{\link{vartrack_prob_prev_xsect}()}, 38 | \code{\link{vartrack_samplesize_prev_xsect}()}, 39 | \code{\link{vartrack_samplesize_prev}()} 40 | 41 | Other variant tracking functions: 42 | \code{\link{vartrack_cod_ratio}()}, 43 | \code{\link{vartrack_prob_detect_cont}()}, 44 | \code{\link{vartrack_prob_detect_xsect}()}, 45 | \code{\link{vartrack_prob_detect}()}, 46 | \code{\link{vartrack_prob_prev_xsect}()}, 47 | \code{\link{vartrack_samplesize_detect_cont}()}, 48 | \code{\link{vartrack_samplesize_detect_xsect}()}, 49 | \code{\link{vartrack_samplesize_detect}()}, 50 | \code{\link{vartrack_samplesize_prev_xsect}()}, 51 | \code{\link{vartrack_samplesize_prev}()} 52 | } 53 | \author{ 54 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 55 | } 56 | \concept{variant prevalence estimation functions} 57 | \concept{variant tracking functions} 58 | -------------------------------------------------------------------------------- /R/vartrack_samplesize_prev_xsect.R: -------------------------------------------------------------------------------- 1 | ##' Calculate sample size needed for variant prevalence estimation under cross-sectional sampling 2 | ##' 3 | ##' This function calculates the sample size needed for estimating variant prevalence 4 | ##' given a desired confidence and desired precision in the variant prevalence estimate 5 | ##' and assuming a single, cross-sectional sample of detected infections. 6 | ##' 7 | ##' @param p_v1 variant prevalence (proportion) 8 | ##' @param prob desired confidence in variant prevalence estimate 9 | ##' @param precision desired precision in variant prevalence estimate 10 | ##' @param omega probability of sequencing (or other characterization) success 11 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 12 | ##' @return scalar of sample size 13 | ##' 14 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 15 | ##' 16 | ##' @examples 17 | ##' vartrack_samplesize_prev_xsect(p_v1 = 0.1, prob = 0.95, precision = 0.25, omega = 0.8, c_ratio = 1) 18 | ##' 19 | ##' @family variant prevalence estimation functions 20 | ##' @family variant tracking functions 21 | ##' 22 | ##' @export 23 | 24 | 25 | vartrack_samplesize_prev_xsect <- function(p_v1, prob, precision, omega, c_ratio = 1) { 26 | if (!all(is.numeric(p_v1), p_v1 > 0 & p_v1 < 1)) 27 | stop("Variant prevalence must be numeric and between 0 and 1.") 28 | if (!all(is.numeric(prob), prob > 0 & prob < 1)) 29 | stop("Desired probability of detection must be numeric and between 0 and 1.") 30 | if (!all(is.numeric(precision), precision > 0 & precision < 1)) 31 | stop("Desired precision must be numeric and between 0 and 1.") 32 | if (!all(is.numeric(omega), omega > 0 & omega <= 1)) 33 | stop("Sequencing success rate must be numeric and between 0 and 1.") 34 | if (!all(is.numeric(c_ratio), c_ratio > 0)) 35 | stop("Coefficient of detection ratio must be numeric and greater than 0") 36 | 37 | p_star <- varfreq_obs_freq(p_v1, c_ratio) 38 | Z <- stats::qnorm(1 - ((1 - prob)/2)) 39 | n <- ((Z^2) * p_star * (1 - p_star))/((p_star * precision)^2) 40 | n_samples <- n/omega 41 | return(n_samples) 42 | } 43 | -------------------------------------------------------------------------------- /man/translink_expected_links_true_stsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/translink_expected_links_true_stsl.R 3 | \name{translink_expected_links_true_stsl} 4 | \alias{translink_expected_links_true_stsl} 5 | \title{Calculate expected number of true transmission pairs assuming single-transmission and single-linkage} 6 | \usage{ 7 | translink_expected_links_true_stsl(sensitivity, rho, M) 8 | } 9 | \arguments{ 10 | \item{sensitivity}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | } 16 | \value{ 17 | scalar or vector giving the expected number of true transmission pairs in the sample 18 | } 19 | \description{ 20 | This function calculates the expected number of true transmission pairs in a sample of size \code{M}. 21 | The single-transmission and single-linkage method assumes the following: 22 | \enumerate{ 23 | \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 24 | \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 25 | } 26 | } 27 | \examples{ 28 | translink_expected_links_true_stsl(sensitivity=0.95, rho=0.2, M=200) 29 | 30 | } 31 | \seealso{ 32 | Other transmission linkage functions: 33 | \code{\link{translink_expected_links_obs_mtml}()}, 34 | \code{\link{translink_expected_links_obs_mtsl}()}, 35 | \code{\link{translink_expected_links_obs_stsl}()}, 36 | \code{\link{translink_expected_links_obs}()}, 37 | \code{\link{translink_expected_links_true_mtml}()}, 38 | \code{\link{translink_expected_links_true_mtsl}()}, 39 | \code{\link{translink_expected_links_true}()}, 40 | \code{\link{translink_fdr}()}, 41 | \code{\link{translink_prob_transmit_mtml}()}, 42 | \code{\link{translink_prob_transmit_mtsl}()}, 43 | \code{\link{translink_prob_transmit_stsl}()}, 44 | \code{\link{translink_prob_transmit}()}, 45 | \code{\link{translink_samplesize}()}, 46 | \code{\link{translink_tdr}()} 47 | } 48 | \author{ 49 | John Giles, Shirlee Wohl, and Justin Lessler 50 | } 51 | \concept{transmission linkage functions} 52 | -------------------------------------------------------------------------------- /tests/testthat/test-varfreq_freq_logistic.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("varfreq_freq_logistic input arguments are valid", { 3 | 4 | expect_error(varfreq_freq_logistic(t = "invalid", p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1)) 5 | 6 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = 1.1, r_v1 = 0.1, c_ratio = 1)) 7 | 8 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = "invalid", r_v1 = 0.1, c_ratio = 1)) 9 | 10 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = 0.1, r_v1 = "invalid", c_ratio = 1)) 11 | 12 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0, c_ratio = 1)) 13 | 14 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = "invalid")) 15 | 16 | expect_error(varfreq_freq_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 0)) 17 | }) 18 | 19 | test_that("varfreq_freq_logistic return object is valid double", { 20 | 21 | expect_type(varfreq_freq_logistic(t = 5, p0_v1 = 0.1, r_v1 = 0.1, c_ratio = 1), 22 | "double") 23 | }) 24 | 25 | test_that("varfreq_freq_logistic variant prevalence increases when growth rate is positive", { 26 | 27 | expect_gt(varfreq_freq_logistic(t = 5, p0_v1 = 1/10000, r_v1 = 0.3, c_ratio = 1), 28 | 1/10000) 29 | }) 30 | 31 | test_that("varfreq_freq_logistic variant prevalence decreases when growth rate is negative", { 32 | 33 | expect_lt(varfreq_freq_logistic(t = 5, p0_v1 = 1/10000, r_v1 = -0.3, c_ratio = 1), 34 | 1/10000) 35 | }) 36 | 37 | test_that("varfreq_freq_logistic observed variant prevalence is higher when c_ratio is above 1", { 38 | 39 | expect_gt(varfreq_freq_logistic(t = 4, p0_v1 = 1/10000, r_v1 = 0.2, c_ratio = 1.2), 40 | varfreq_freq_logistic(t = 4, p0_v1 = 1/10000, r_v1 = 0.2, c_ratio = 1)) 41 | }) 42 | 43 | test_that("varfreq_freq_logistic observed variant prevalence is lower when c_ratio is below 1", { 44 | 45 | expect_lt(varfreq_freq_logistic(t = 10, p0_v1 = 1/1000, r_v1 = 0.11, c_ratio = 0.9), 46 | varfreq_freq_logistic(t = 10, p0_v1 = 1/1000, r_v1 = 0.11, c_ratio = 1)) 47 | }) 48 | 49 | test_that("varfreq_freq_logistic manuscript results remain valid", { 50 | 51 | expect_equal(round(varfreq_freq_logistic(t = 14, p0_v1 = 1/10000, r_v1 = 0.1, 52 | c_ratio = 1), 4), 4e-04) 53 | }) 54 | 55 | -------------------------------------------------------------------------------- /man/get_optim_roc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_optim_roc.R 3 | \name{get_optim_roc} 4 | \alias{get_optim_roc} 5 | \title{Find optimal ROC threshold} 6 | \usage{ 7 | get_optim_roc(roc) 8 | } 9 | \arguments{ 10 | \item{roc}{a dataframe produced by the \code{sens_spec_roc()} function containing the Receiver Operating Characteristic (ROC) curve} 11 | } 12 | \value{ 13 | vector containing optimal thresholds of sensitivity and specificity 14 | } 15 | \description{ 16 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 17 | This function takes the dataframe output of the \code{sens_spec_roc()} function and finds the optimal threshold 18 | of sensitivity and specificity by minimizing the distance to the top left corner of the Receiver Operating Characteristic (ROC) curve 19 | } 20 | \examples{ 21 | # ebola-like pathogen 22 | R <- 1.5 23 | mut_rate <- 1 24 | 25 | # use simulated generation distributions 26 | data(genDistSim) 27 | mean_gens_pdf <- as.numeric(genDistSim[genDistSim$R == R, -(1:2)]) 28 | 29 | # get theoretical genetic distance dist based on mutation rate and generation parameters 30 | dists <- as.data.frame(gen_dists(mut_rate = mut_rate, 31 | mean_gens_pdf = mean_gens_pdf, 32 | max_link_gens = 1)) 33 | 34 | # reshape dataframe for plotting 35 | dists <- reshape2::melt(dists, 36 | id.vars = 'dist', 37 | variable.name = 'status', 38 | value.name = 'prob') 39 | 40 | # get sensitivity and specificity using the same paramters 41 | roc_calc <- sens_spec_roc(cutoff = 1:(max(dists$dist)-1), 42 | mut_rate = mut_rate, 43 | mean_gens_pdf = mean_gens_pdf) 44 | 45 | # get the optimal value for the ROC plot 46 | optim_point <- get_optim_roc(roc_calc) 47 | 48 | } 49 | \seealso{ 50 | Other mutrate_functions: 51 | \code{\link{gen_dists}()}, 52 | \code{\link{sens_spec_calc}()}, 53 | \code{\link{sens_spec_roc}()} 54 | } 55 | \author{ 56 | Shirlee Wohl, John Giles, and Justin Lessler 57 | } 58 | \concept{mutrate_functions} 59 | -------------------------------------------------------------------------------- /R/true_pairs_mtsl.R: -------------------------------------------------------------------------------- 1 | ##' Expected number of true transmission pairs assuming multiple-transmission and single-linkage 2 | ##' 3 | ##' @description 4 | ##' `r lifecycle::badge('deprecated')` 5 | ##' This function calculates the expected number true transmission pairs in a sample of size `M`. 6 | ##' The multiple-transmission and single-linkage method assumes the following: 7 | ##' \enumerate{ 8 | ##' \item Each case \eqn{i} is, on average, the infector of `R` cases in the population (\eqn{N}) 9 | ##' \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 10 | ##' } 11 | ##' 12 | ##' @param eta scalar or vector giving the sensitivity of the linkage criteria 13 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 14 | ##' @param M scalar or vector giving the number of cases sampled 15 | ##' @param R scalar or vector giving the effective reproductive number of the pathogen 16 | ##' 17 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 18 | ##' 19 | ##' @author John Giles, Shirlee Wohl and Justin Lessler 20 | ##' 21 | ##' @examples 22 | ##' true_pairs_mtsl(eta=0.95, rho=0.2, M=200, R=1) 23 | ##' 24 | ##' @family true_pairs 25 | ##' 26 | ##' @export 27 | ##' 28 | ##' 29 | 30 | true_pairs_mtsl <- function(eta, rho, M, R) { 31 | lifecycle::deprecate_soft("1.0.0", "true_pairs_mtsl()", "translink_expected_links_true_mtsl()") 32 | lifecycle::deprecate_soft("1.0.0", "true_pairs_mtsl(eta)", "translink_expected_links_true_mtsl(sensitivity)") 33 | 34 | if (!all(is.numeric(eta), eta >= 0 & eta <= 1)) 35 | stop("eta must be numeric between 0 and 1") 36 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 37 | stop("rho must be numeric > 0 and <= 1") 38 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 39 | stop("Sample size (M) must be integer or numeric greater than 0") 40 | if (!all(is.numeric(R), R > 0)) 41 | stop("Reproductive number (R) must be numeric greater than 0") 42 | if (!all(is.numeric(R), R <= 1)) 43 | warning("Reproductive number (R) is usually less than 1 for finite outbreaks") 44 | 45 | (M * rho * (R + 1) * eta)/2 46 | } 47 | -------------------------------------------------------------------------------- /R/vartrack_samplesize_prev.R: -------------------------------------------------------------------------------- 1 | ##' Calculate sample size needed for estimating variant prevalence given a desired confidence 2 | ##' 3 | ##' This function calculates the sample size needed for estimating variant prevalence 4 | ##' given a desired confidence and desired precision in the variant prevalence estimate. 5 | ##' Currently, only cross-sectional sampling is supported. 6 | ##' 7 | ##' @param p_v1 variant prevalence (proportion) 8 | ##' @param prob desired confidence in variant prevalence estimate 9 | ##' @param precision desired precision in variant prevalence estimate 10 | ##' @param omega probability of sequencing (or other characterization) success 11 | ##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias) 12 | ##' @param sampling_freq the sampling frequency (must be 'xsect' in current implementation) 13 | ##' @return scalar of sample size 14 | ##' 15 | ##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 16 | ##' 17 | ##' @examples 18 | ##' vartrack_samplesize_prev(p_v1 = 0.1, prob = 0.95, precision = 0.25, 19 | ##' omega = 0.8, c_ratio = 1, sampling_freq = 'xsect') 20 | ##' 21 | ##' @family variant prevalence estimation functions 22 | ##' @family variant tracking functions 23 | ##' 24 | ##' @export 25 | 26 | 27 | vartrack_samplesize_prev <- function(p_v1, prob, precision, omega, c_ratio = 1, sampling_freq) { 28 | 29 | if (sampling_freq == "xsect") { 30 | message("Calculating sample size for variant prevalence estimation assuming single cross-sectional sample") 31 | out <- vartrack_samplesize_prev_xsect(p_v1 = p_v1, prob = prob, precision = precision, 32 | omega = omega, c_ratio = c_ratio) 33 | 34 | } else if (sampling_freq == "cont") { 35 | stop("Functionality for the sample size needed for estimating variant prevalence given periodic sampling is not yet implemented in the phylosamp package. You can calculate the sample size needed for variant prevalence estimation given a cross-sectional sample by specifying 'xsect' as the sampling frequency") 36 | 37 | } else { 38 | stop("Incorrect sampling frequency argument (please specify 'xsect' or 'cont')") 39 | } 40 | return(out) 41 | } 42 | -------------------------------------------------------------------------------- /R/translink_expected_links_true_mtml.R: -------------------------------------------------------------------------------- 1 | ##' Calculate expected number of true transmission pairs assuming multiple-transmission and multiple-linkage 2 | ##' 3 | ##' This function calculates the expected number of true transmission pairs in a sample of size `M`. 4 | ##' The multiple-transmission and multiple-linkage method assumes the following: 5 | ##' \enumerate{ 6 | ##' \item Each case \eqn{i} is, on average, the infector of `R` cases in the population (\eqn{N}) 7 | ##' \item Each case \eqn{i} is allowed to be linked by the linkage criteria to multiple cases \eqn{j} in the sampled population (\eqn{M}). 8 | ##' \item Linkage events are independent of one another (i.e, linkage of case \eqn{i} to case \eqn{j} has no bearing on linkage of case \eqn{i} to any other sample). 9 | ##' } 10 | ##' 11 | ##' @param sensitivity scalar or vector giving the sensitivity of the linkage criteria 12 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 13 | ##' @param M scalar or vector giving the number of cases sampled 14 | ##' @param R scalar or vector giving the effective reproductive number of the pathogen 15 | ##' 16 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 17 | ##' 18 | ##' @author John Giles, Shirlee Wohl and Justin Lessler 19 | ##' 20 | ##' @examples 21 | ##' translink_expected_links_true_mtml(sensitivity=0.95, rho=0.2, M=1000, R=1) 22 | ##' 23 | ##' @family transmission linkage functions 24 | ##' 25 | ##' @export 26 | ##' 27 | 28 | translink_expected_links_true_mtml <- function(sensitivity, rho, M, R) { 29 | if (!all(is.numeric(sensitivity), sensitivity >= 0 & sensitivity <= 1)) 30 | stop("sensitivity must be numeric between 0 and 1") 31 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 32 | stop("rho must be numeric > 0 and <= 1") 33 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 34 | stop("Sample size (M) must be integer or numeric greater than 0") 35 | if (!all(is.numeric(R), R > 0)) 36 | stop("Reproductive number (R) must be numeric greater than 0") 37 | if (!all(is.numeric(R), R <= 1)) 38 | warning("Reproductive number (R) is usually less than 1 for finite outbreaks") 39 | 40 | (M * rho * (R + 1) * sensitivity)/2 41 | } 42 | -------------------------------------------------------------------------------- /R/translink_expected_links_obs_stsl.R: -------------------------------------------------------------------------------- 1 | ##' Calculate expected number of observed pairs assuming single-transmission and single-linkage 2 | ##' 3 | ##' This function calculates the expected number of link pairs observed in a sample of size `M`. 4 | ##' The single-transmission and single-linkage method assumes the following: 5 | ##' \enumerate{ 6 | ##' \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 7 | ##' \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 8 | ##' } 9 | ##' 10 | ##' @param sensitivity scalar or vector giving the sensitivity of the linkage criteria 11 | ##' @param specificity scalar or vector giving the specificity of the linkage criteria 12 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 13 | ##' @param M scalar or vector giving the number of cases sampled 14 | ##' 15 | ##' @return scalar or vector giving the expected number of linked pairs observed in the sample 16 | ##' 17 | ##' @author John Giles, Shirlee Wohl, and Justin Lessler 18 | ##' 19 | ##' @examples 20 | ##' # perfect sensitivity and specificity 21 | ##' translink_expected_links_obs_stsl(sensitivity=1, specificity=1, rho=0.5, M=100) 22 | ##' 23 | ##' translink_expected_links_obs_stsl(sensitivity=0.99, specificity=0.9, rho=1, M=50) 24 | ##' 25 | ##' translink_expected_links_obs_stsl(sensitivity=0.99, specificity=0.9, rho=0.5, M=100) 26 | ##' 27 | ##' @family transmission linkage functions 28 | ##' 29 | ##' @export 30 | 31 | translink_expected_links_obs_stsl <- function(sensitivity, specificity, rho, M) { 32 | if (!all(is.numeric(sensitivity), sensitivity >= 0 & sensitivity <= 1)) 33 | stop("sensitivity must be numeric between 0 and 1") 34 | if (!all(is.numeric(specificity), specificity >= 0 & specificity <= 1)) 35 | stop("specificity must be numeric between 0 and 1") 36 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 37 | stop("rho must be numeric > 0 and <= 1") 38 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 39 | stop("Sample size (M) must be integer or numeric greater than 0") 40 | 41 | (M/2) * ((sensitivity * rho) + (rho * (1 - sensitivity) * (1 - specificity^(M - 42 | 2))) + ((1 - rho) * (1 - specificity^(M - 1)))) 43 | } 44 | -------------------------------------------------------------------------------- /man/relR_power.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/relR_power.R 3 | \name{relR_power} 4 | \alias{relR_power} 5 | \title{Calculate power for detecting differential transmission given a sample size} 6 | \usage{ 7 | relR_power( 8 | m, 9 | R_a, 10 | R_b, 11 | p_a, 12 | N = NULL, 13 | rho = NULL, 14 | alpha = 0.05, 15 | alternative = c("two_sided", "less", "greater"), 16 | sensitivity = 1, 17 | specificity = 1, 18 | overdispersion = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{m}{the sample size.} 23 | 24 | \item{R_a}{Numeric (Positive). The assumed R among the group in the 25 | denominator of the ratio. Input value must be greater than 0.} 26 | 27 | \item{R_b}{Numeric (Positive). The assumed R among the group in the 28 | numerator of the ratio. Input value must be greater than 0.} 29 | 30 | \item{p_a}{Numeric. The proportion of the population in group \code{a}. Must be 31 | between 0 and 1.} 32 | 33 | \item{N}{Numeric (Positive). The size of the infected pool. Only one of 34 | \code{rho} or \code{N} should be specified.} 35 | 36 | \item{rho}{Numeric. The proportion of the infected pool sampled. 37 | Only one of \code{rho} or \code{N} should be specified. Values should be between 0 38 | and 1.} 39 | 40 | \item{alpha}{Numeric. The desired alpha level. Default: 0.05} 41 | 42 | \item{alternative}{Character. Specifies the alternative hypothesis. 43 | Must be: \code{two_sided} (Default), \code{less}, or \code{greater}} 44 | 45 | \item{sensitivity}{Numeric. The sensitivity of the linkage criteria. 46 | Must be between 0 and 1. Default: 1.} 47 | 48 | \item{specificity}{Numeric. The specificity of the linkage criteria. 49 | Must be between 0 and 1. Default: 1.} 50 | 51 | \item{overdispersion}{Numeric (Positive). An overdispersion parameter, set 52 | if the assumed distribution of the number of edges is negative binomial. 53 | If \code{NULL} the assumed distribution is Poisson (equivalent to an 54 | overdispersion parameter of infinity) Default: \code{NULL} Note that this is 55 | equivalent to setting the overdispersion parameter to \code{Inf}.} 56 | } 57 | \value{ 58 | The power given \code{m} 59 | } 60 | \description{ 61 | Function to calculate the power given a sample size. This is the top 62 | level function to be called to calculate power given a sample size m 63 | and a proportion sampled. 64 | } 65 | -------------------------------------------------------------------------------- /man/translink_expected_links_true_mtsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/translink_expected_links_true_mtsl.R 3 | \name{translink_expected_links_true_mtsl} 4 | \alias{translink_expected_links_true_mtsl} 5 | \title{Calculate expected number of true transmission pairs assuming multiple-transmission and single-linkage} 6 | \usage{ 7 | translink_expected_links_true_mtsl(sensitivity, rho, M, R) 8 | } 9 | \arguments{ 10 | \item{sensitivity}{scalar or vector giving the sensitivity of the linkage criteria} 11 | 12 | \item{rho}{scalar or vector giving the proportion of the final outbreak size that is sampled} 13 | 14 | \item{M}{scalar or vector giving the number of cases sampled} 15 | 16 | \item{R}{scalar or vector giving the effective reproductive number of the pathogen} 17 | } 18 | \value{ 19 | scalar or vector giving the expected number of true transmission pairs in the sample 20 | } 21 | \description{ 22 | This function calculates the expected number true transmission pairs in a sample of size \code{M}. 23 | The multiple-transmission and single-linkage method assumes the following: 24 | \enumerate{ 25 | \item Each case \eqn{i} is, on average, the infector of \code{R} cases in the population (\eqn{N}) 26 | \item Each case \eqn{i} is allowed to be linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 27 | } 28 | } 29 | \examples{ 30 | translink_expected_links_true_mtsl(sensitivity=0.95, rho=0.2, M=200, R=1) 31 | 32 | } 33 | \seealso{ 34 | Other transmission linkage functions: 35 | \code{\link{translink_expected_links_obs_mtml}()}, 36 | \code{\link{translink_expected_links_obs_mtsl}()}, 37 | \code{\link{translink_expected_links_obs_stsl}()}, 38 | \code{\link{translink_expected_links_obs}()}, 39 | \code{\link{translink_expected_links_true_mtml}()}, 40 | \code{\link{translink_expected_links_true_stsl}()}, 41 | \code{\link{translink_expected_links_true}()}, 42 | \code{\link{translink_fdr}()}, 43 | \code{\link{translink_prob_transmit_mtml}()}, 44 | \code{\link{translink_prob_transmit_mtsl}()}, 45 | \code{\link{translink_prob_transmit_stsl}()}, 46 | \code{\link{translink_prob_transmit}()}, 47 | \code{\link{translink_samplesize}()}, 48 | \code{\link{translink_tdr}()} 49 | } 50 | \author{ 51 | John Giles, Shirlee Wohl and Justin Lessler 52 | } 53 | \concept{transmission linkage functions} 54 | -------------------------------------------------------------------------------- /man/vartrack_samplesize_prev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vartrack_samplesize_prev.R 3 | \name{vartrack_samplesize_prev} 4 | \alias{vartrack_samplesize_prev} 5 | \title{Calculate sample size needed for estimating variant prevalence given a desired confidence} 6 | \usage{ 7 | vartrack_samplesize_prev( 8 | p_v1, 9 | prob, 10 | precision, 11 | omega, 12 | c_ratio = 1, 13 | sampling_freq 14 | ) 15 | } 16 | \arguments{ 17 | \item{p_v1}{variant prevalence (proportion)} 18 | 19 | \item{prob}{desired confidence in variant prevalence estimate} 20 | 21 | \item{precision}{desired precision in variant prevalence estimate} 22 | 23 | \item{omega}{probability of sequencing (or other characterization) success} 24 | 25 | \item{c_ratio}{coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)} 26 | 27 | \item{sampling_freq}{the sampling frequency (must be 'xsect' in current implementation)} 28 | } 29 | \value{ 30 | scalar of sample size 31 | } 32 | \description{ 33 | This function calculates the sample size needed for estimating variant prevalence 34 | given a desired confidence and desired precision in the variant prevalence estimate. 35 | Currently, only cross-sectional sampling is supported. 36 | } 37 | \examples{ 38 | vartrack_samplesize_prev(p_v1 = 0.1, prob = 0.95, precision = 0.25, 39 | omega = 0.8, c_ratio = 1, sampling_freq = 'xsect') 40 | 41 | } 42 | \seealso{ 43 | Other variant prevalence estimation functions: 44 | \code{\link{vartrack_prob_prev_xsect}()}, 45 | \code{\link{vartrack_prob_prev}()}, 46 | \code{\link{vartrack_samplesize_prev_xsect}()} 47 | 48 | Other variant tracking functions: 49 | \code{\link{vartrack_cod_ratio}()}, 50 | \code{\link{vartrack_prob_detect_cont}()}, 51 | \code{\link{vartrack_prob_detect_xsect}()}, 52 | \code{\link{vartrack_prob_detect}()}, 53 | \code{\link{vartrack_prob_prev_xsect}()}, 54 | \code{\link{vartrack_prob_prev}()}, 55 | \code{\link{vartrack_samplesize_detect_cont}()}, 56 | \code{\link{vartrack_samplesize_detect_xsect}()}, 57 | \code{\link{vartrack_samplesize_detect}()}, 58 | \code{\link{vartrack_samplesize_prev_xsect}()} 59 | } 60 | \author{ 61 | Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler 62 | } 63 | \concept{variant prevalence estimation functions} 64 | \concept{variant tracking functions} 65 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /man/relR_samplesize_solve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/relR_samplesize_solve.R 3 | \name{relR_samplesize_solve} 4 | \alias{relR_samplesize_solve} 5 | \title{Calculate optimal sample size for detecting differential transmission with imperfect specificity} 6 | \usage{ 7 | relR_samplesize_solve( 8 | R_a, 9 | R_b, 10 | p_a, 11 | N, 12 | alpha = 0.05, 13 | alternative = c("two_sided", "less", "greater"), 14 | power = 0.8, 15 | sensitivity = 1, 16 | specificity = 1, 17 | overdispersion = NULL, 18 | allow_impossible_m = FALSE 19 | ) 20 | } 21 | \arguments{ 22 | \item{R_a}{Numeric (Positive). The assumed R among the group in the 23 | denominator of the ratio. Input value must be greater than 0.} 24 | 25 | \item{R_b}{Numeric (Positive). The assumed R among the group in the 26 | numerator of the ratio. Input value must be greater than 0.} 27 | 28 | \item{p_a}{Numeric. The proportion of the population in group \code{a}. Must be 29 | between 0 and 1.} 30 | 31 | \item{N}{Numeric (Positive). The size of the infected pool. Only one of 32 | \code{rho} or \code{N} should be specified.} 33 | 34 | \item{alpha}{Numeric. The desired alpha level. Default: 0.05} 35 | 36 | \item{alternative}{Character. Specifies the alternative hypothesis. 37 | Must be: \code{two_sided} (Default), \code{less}, or \code{greater}} 38 | 39 | \item{power}{Numeric. The desired power. Must be a value between 0 and 1. 40 | Default: 0.8.} 41 | 42 | \item{sensitivity}{Numeric. The sensitivity of the linkage criteria. 43 | Must be between 0 and 1. Default: 1.} 44 | 45 | \item{specificity}{Numeric. The specificity of the linkage criteria. 46 | Must be between 0 and 1. Default: 1.} 47 | 48 | \item{overdispersion}{Numeric (Positive). An overdispersion parameter, set 49 | if the assumed distribution of the number of edges is negative binomial. 50 | If \code{NULL} the assumed distribution is Poisson (equivalent to an 51 | overdispersion parameter of infinity) Default: \code{NULL} Note that this is 52 | equivalent to setting the overdispersion parameter to \code{Inf}.} 53 | 54 | \item{allow_impossible_m}{Logical. Indicates whether a value for \code{m} can be 55 | returned that is greater than the input \code{N}. Default: \code{FALSE}.} 56 | } 57 | \value{ 58 | The sample size 59 | } 60 | \description{ 61 | Function to solve for optimal sample size when the specificity isn't 1 62 | } 63 | -------------------------------------------------------------------------------- /R/true_pairs_mtml.R: -------------------------------------------------------------------------------- 1 | ##' Expected number of true transmission pairs assuming multiple-transmission and multiple-linkage 2 | ##' 3 | ##' @description 4 | ##' `r lifecycle::badge('deprecated')` 5 | ##' This function calculates the expected number of true transmission pairs in a sample of size `M`. 6 | ##' The multiple-transmission and multiple-linkage method assumes the following: 7 | ##' \enumerate{ 8 | ##' \item Each case \eqn{i} is, on average, the infector of `R` cases in the population (\eqn{N}) 9 | ##' \item Each case \eqn{i} is allowed to be linked by the linkage criteria to multiple cases \eqn{j} in the sampled population (\eqn{M}). 10 | ##' \item Linkage events are independent of one another (i.e, linkage of case \eqn{i} to case \eqn{j} has no bearing on linkage of case \eqn{i} to any other sample). 11 | ##' } 12 | ##' 13 | ##' @param eta scalar or vector giving the sensitivity of the linkage criteria 14 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 15 | ##' @param M scalar or vector giving the number of cases sampled 16 | ##' @param R scalar or vector giving the effective reproductive number of the pathogen 17 | ##' 18 | ##' @return scalar or vector giving the expected number of true transmission pairs in the sample 19 | ##' 20 | ##' @author John Giles, Shirlee Wohl and Justin Lessler 21 | ##' 22 | ##' @examples 23 | ##' true_pairs_mtml(eta=0.95, rho=0.2, M=1000, R=1) 24 | ##' 25 | ##' @family true_pairs 26 | ##' 27 | ##' @export 28 | ##' 29 | 30 | true_pairs_mtml <- function(eta, rho, M, R) { 31 | lifecycle::deprecate_soft("1.0.0", "true_pairs_mtml()", "translink_expected_links_true_mtml()") 32 | lifecycle::deprecate_soft("1.0.0", "true_pairs_mtml(eta)", "translink_expected_links_true_mtml(sensitivity)") 33 | 34 | if (!all(is.numeric(eta), eta >= 0 & eta <= 1)) 35 | stop("eta must be numeric between 0 and 1") 36 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 37 | stop("rho must be numeric > 0 and <= 1") 38 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 39 | stop("Sample size (M) must be integer or numeric greater than 0") 40 | if (!all(is.numeric(R), R > 0)) 41 | stop("Reproductive number (R) must be numeric greater than 0") 42 | if (!all(is.numeric(R), R <= 1)) 43 | warning("Reproductive number (R) is usually less than 1 for finite outbreaks") 44 | 45 | (M * rho * (R + 1) * eta)/2 46 | } 47 | -------------------------------------------------------------------------------- /man/gendist_sensspec_cutoff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gendist_sensspec_cutoff.R 3 | \name{gendist_sensspec_cutoff} 4 | \alias{gendist_sensspec_cutoff} 5 | \title{Calculate sensitivity and specificity of a genetic distance cutoff} 6 | \usage{ 7 | gendist_sensspec_cutoff( 8 | cutoff, 9 | mut_rate, 10 | mean_gens_pdf, 11 | max_link_gens = 1, 12 | max_gens = NULL, 13 | max_dist = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{cutoff}{the maximum genetic distance at which to consider cases linked} 18 | 19 | \item{mut_rate}{mean number of mutations per generation, assumed to be Poisson distributed} 20 | 21 | \item{mean_gens_pdf}{the density distribution of the mean number of generations between cases; 22 | the index of this vector is assumed to be the discrete distance between cases} 23 | 24 | \item{max_link_gens}{the maximum generations of separation for linked pairs} 25 | 26 | \item{max_gens}{the maximum number of generations to consider, if \code{NULL} (default) value set to the highest 27 | number of generations in mean_gens_pdf with a non-zero probability} 28 | 29 | \item{max_dist}{the maximum distance to calculate, if \code{NULL} (default) value set to max_gens * 99.9th percentile 30 | of mut_rate Poisson distribution} 31 | } 32 | \value{ 33 | a data frame with the sensitivity and specificity for a particular genetic distance cutoff 34 | } 35 | \description{ 36 | Function to calculate the sensitivity and specificity of a genetic distance cutoff 37 | given an underlying mutation rate and mean number of generations between cases 38 | } 39 | \examples{ 40 | # calculate the sensitivity and specificity for a specific genetic distance threshold of 2 mutations 41 | gendist_sensspec_cutoff(cutoff=2, 42 | mut_rate=1, 43 | mean_gens_pdf=c(0.02,0.08,0.15,0.75), 44 | max_link_gens=1) 45 | 46 | # calculate the sensitivity and specificity for a a range of genetic distance thresholds 47 | gendist_sensspec_cutoff(cutoff=1:10, 48 | mut_rate=1, 49 | mean_gens_pdf=c(0.02,0.08,0.15,0.75), 50 | max_link_gens=1) 51 | 52 | } 53 | \seealso{ 54 | Other genetic distance functions: 55 | \code{\link{gendist_distribution}()}, 56 | \code{\link{gendist_roc_format}()} 57 | } 58 | \author{ 59 | Shirlee Wohl and Justin Lessler 60 | } 61 | \concept{genetic distance functions} 62 | -------------------------------------------------------------------------------- /R/obs_pairs_stsl.R: -------------------------------------------------------------------------------- 1 | ##' Expected number of observed pairs assuming single-transmission and single-linkage 2 | ##' 3 | ##' @description 4 | ##' `r lifecycle::badge('deprecated')` 5 | ##' This function calculates the expected number of link pairs observed in a sample of size `M`. 6 | ##' The single-transmission and single-linkage method assumes the following: 7 | ##' \enumerate{ 8 | ##' \item Each case \eqn{i} is linked by transmission to only one other case \eqn{j} in the population (\eqn{N}). 9 | ##' \item Each case \eqn{i} is linked by the linkage criteria to only one other case \eqn{j} in the sampled population (\eqn{M}). 10 | ##' } 11 | ##' 12 | ##' @param eta scalar or vector giving the sensitivity of the linkage criteria 13 | ##' @param chi scalar or vector giving the specificity of the linkage criteria 14 | ##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled 15 | ##' @param M scalar or vector giving the number of cases sampled 16 | ##' 17 | ##' @return scalar or vector giving the expected number of linked pairs observed in the sample 18 | ##' 19 | ##' @author John Giles, Shirlee Wohl, and Justin Lessler 20 | ##' 21 | ##' @examples 22 | ##' # perfect sensitivity and specificity 23 | ##' obs_pairs_stsl(eta=1, chi=1, rho=0.5, M=100) 24 | ##' 25 | ##' obs_pairs_stsl(eta=0.99, chi=0.9, rho=1, M=50) 26 | ##' 27 | ##' obs_pairs_stsl(eta=0.99, chi=0.9, rho=0.5, M=100) 28 | ##' 29 | ##' @family obs_pairs 30 | ##' 31 | ##' @export 32 | 33 | obs_pairs_stsl <- function(eta, chi, rho, M) { 34 | lifecycle::deprecate_soft("1.0.0", "obs_pairs_stsl()", "translink_expected_links_obs_stsl()") 35 | lifecycle::deprecate_soft("1.0.0", "obs_pairs_stsl(eta)", "translink_expected_links_obs_stsl(sensitivity)") 36 | lifecycle::deprecate_soft("1.0.0", "obs_pairs_stsl(chi)", "translink_expected_links_obs_stsl(specificity)") 37 | 38 | if (!all(is.numeric(eta), eta >= 0 & eta <= 1)) 39 | stop("eta must be numeric between 0 and 1") 40 | if (!all(is.numeric(chi), chi >= 0 & chi <= 1)) 41 | stop("chi must be numeric between 0 and 1") 42 | if (!all(is.numeric(rho), rho > 0 & rho <= 1)) 43 | stop("rho must be numeric > 0 and <= 1") 44 | if (!all(is.numeric(M) | is.integer(M), M >= 0)) 45 | stop("Sample size (M) must be integer or numeric greater than 0") 46 | 47 | (M/2) * ((eta * rho) + (rho * (1 - eta) * (1 - chi^(M - 2))) + ((1 - rho) * (1 - 48 | chi^(M - 1)))) 49 | } 50 | --------------------------------------------------------------------------------