-
Notifications
You must be signed in to change notification settings - Fork 2
/
vartrack_prob_prev.R
42 lines (36 loc) · 1.91 KB
/
vartrack_prob_prev.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##' Calculate confidence in a variant estimate given a sample size
##'
##' This function calculates the probability of accurately estimating variant prevalence
##' given a sample size and desired precision in the variant prevalence estimate.
##' Currently, only cross-sectional sampling is supported.
##'
##' @param p_v1 variant prevalence (proportion)
##' @param n sample size
##' @param omega probability of sequencing (or other characterization) success
##' @param precision desired precision in variant prevalence estimate
##' @param c_ratio coefficient of detection ratio, calculated as the ratio of the coefficients of variant 1 to variant 2. Default = 1 (no bias)
##' @param sampling_freq the sampling frequency (must be either 'xsect' in current implementation)
##' @return scalar of expected sample size
##'
##' @author Shirlee Wohl, Elizabeth C. Lee, Bethany L. DiPrete, and Justin Lessler
##'
##' @examples
##' vartrack_prob_prev(p_v1 = 0.1, n = 200, omega = 0.8, precision = 0.1,
##' c_ratio = 1, sampling_freq = 'xsect')
##'
##' @family variant prevalence estimation functions
##' @family variant tracking functions
##'
##' @export
vartrack_prob_prev <- function(p_v1, n, omega, precision, c_ratio = 1, sampling_freq) {
if (sampling_freq == "xsect") {
message("Calculating confidence in variant estimate assuming single cross-sectional sample")
out <- vartrack_prob_prev_xsect(p_v1 = p_v1, n = n, omega = omega, precision = precision,
c_ratio = c_ratio)
} else if (sampling_freq == "cont") {
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")
} else {
stop("Incorrect sampling frequency argument (please specify 'xsect' or 'cont')")
}
return(out)
}