library(groupTesting)
## Gonorrhea data information:
p0 <- 0.041 # True prevalence
Se <- 0.913 # Assay sensitivity
Sp <- 0.993 # Assay specificity
psz <- 2:6 # A range of initial pool sizes
## Example 1: Two-stage hierarchical testing (H2)
## REE (using closed-form expressions)
res <- mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H2", criterion="REE")
## Output
# > res
# $efficiency
# PSZ.S1 PSZ.S2 REE
# [1,] 2 1 0.8920
# [2,] 3 1 0.8932
# [3,] 4 1 0.8975
# [4,] 5 1 0.9034
# [5,] 6 1 0.9104
# $expected_cost
# PSZ.S1 PSZ.S2 E[(phat-p)^2]
# [1,] 2 1 5.731668e-05
# [2,] 3 1 5.732655e-05
# [3,] 4 1 5.767260e-05
# [4,] 5 1 5.805423e-05
# [5,] 6 1 5.864758e-05
# $iterations
# NULL
## RTE (using closed-form expressions)
mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H2", criterion="RTE")
## RCE (using the computation algorithm)
# res <- mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H2", seed=123,
# criterion="RCE", N=800, ngit=3000, maxit=200, tol=0.001, nrep=3000, ncore=4)
# Note: For 'H2' protocol, get cumulative running averages as:
# res2 <- res$iterations[ ,-(1:2)]
# Now, plot each row; for example: plot(res2[1, ], type='l')
#
# Execution of 'RCE' for H2 is slow, as discussed in the 'details' section.
# The computing challenge can be overcome using multiple CPU cores as shown above.
## Example 2: Three-stage hierarchical testing (H3)
## REE (using the computation algorithm)
# res <- mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H3", seed=123,
# criterion="REE", N=800, ngit=3000, maxit=200, tol=0.001, nrep=3000, ncore=4)
#
# Note: For 'H3' protocol, get cumulative running averages as:
# res2 <- res$iterations[ ,-(1:3)] # Now, plot each row: plot(res2[1, ], type='l')
## RTE (using closed-form expressions)
# res <- mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H3",
# criterion="RTE", N=800, ngit=3000, maxit=200, tol=0.001, nrep=3000, ncore=4)
## RCE (using the computation algorithm)
# res <- mle.prop.eff(p=p0, Se=Se, Sp=Sp, initial.psz=psz, protocol="H3", seed=123,
# criterion="RCE", N=800, ngit=3000, maxit=200, tol=0.001, nrep=3000, ncore=4)
Run the code above in your browser using DataLab