R/boptimal_n.R

Defines functions boptimal_n

Documented in boptimal_n

#' @title Optimal Test Sample Size for Binomial RDT
#'
#' @description Define the optimal function to find the optimal test plan with minimum test sample size given an acceptable
#' level of consumer's risk (for binomial RDT).
#'
#' @param c Maximum allowable failures
#' @param pi Failure probability
#' @param R Lower level reliability requirement
#' @param thres_CR Threshold (acceptable level) of consumer's risk
#' @return Minimum test sample size
#' @examples
#' \donttest{
#' pi <- pi_MCSim_beta(M = 5000, seed = 10, a = 1, b = 1)
#' boptimal_n(c = 2, pi = pi, R = 0.8, thres_CR = 0.05)
#' }
#' @export
#' @family Binomial RDT functions
#' @seealso \code{\link{bcore}} for getting the core probability of passting the test;
#' \code{\link{bconsumerrisk}} for getting the consumer's risk;
#' \code{\link{bIndicator}} for getting the binary indicator;


boptimal_n <- function(c, pi, R, thres_CR){
  n <- c + 1
  CR <- bconsumerrisk(n, c, pi, R)
  while (CR > thres_CR){
    n <- n + 1
    CR <- bconsumerrisk(n, c, pi, R)
  }
  return(n)
}

Try the MSRDT package in your browser

Any scripts or data that you put into this service are public.

MSRDT documentation built on July 2, 2020, 2:13 a.m.