-
Notifications
You must be signed in to change notification settings - Fork 2
/
translink_expected_links_true_mtml.R
41 lines (39 loc) · 2.07 KB
/
translink_expected_links_true_mtml.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
##' Calculate expected number of true transmission pairs assuming multiple-transmission and multiple-linkage
##'
##' This function calculates the expected number of true transmission pairs in a sample of size `M`.
##' The multiple-transmission and multiple-linkage method assumes the following:
##' \enumerate{
##' \item Each case \eqn{i} is, on average, the infector of `R` cases in the population (\eqn{N})
##' \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}).
##' \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).
##' }
##'
##' @param sensitivity scalar or vector giving the sensitivity of the linkage criteria
##' @param rho scalar or vector giving the proportion of the final outbreak size that is sampled
##' @param M scalar or vector giving the number of cases sampled
##' @param R scalar or vector giving the effective reproductive number of the pathogen
##'
##' @return scalar or vector giving the expected number of true transmission pairs in the sample
##'
##' @author John Giles, Shirlee Wohl and Justin Lessler
##'
##' @examples
##' translink_expected_links_true_mtml(sensitivity=0.95, rho=0.2, M=1000, R=1)
##'
##' @family transmission linkage functions
##'
##' @export
##'
translink_expected_links_true_mtml <- function(sensitivity, rho, M, R) {
if (!all(is.numeric(sensitivity), sensitivity >= 0 & sensitivity <= 1))
stop("sensitivity must be numeric between 0 and 1")
if (!all(is.numeric(rho), rho > 0 & rho <= 1))
stop("rho must be numeric > 0 and <= 1")
if (!all(is.numeric(M) | is.integer(M), M >= 0))
stop("Sample size (M) must be integer or numeric greater than 0")
if (!all(is.numeric(R), R > 0))
stop("Reproductive number (R) must be numeric greater than 0")
if (!all(is.numeric(R), R <= 1))
warning("Reproductive number (R) is usually less than 1 for finite outbreaks")
(M * rho * (R + 1) * sensitivity)/2
}