R/getDecision.R

Defines functions getDecision

Documented in getDecision

#' @title getDecision
#'
#' @description For given n probabilities 0 <= pi <= 1 with sum(pi)=1,
#' return 0,1,2,3,..,n with probability p0, p1, p2, ..., pn.
#'
#' @param p vector of probabilities
#'
#' @return int decision in the range from 0 to n
#'
#' @examples
#'
#' p <- c(0.6, 0.3, 0.1)
#' getDecision(p)
#' @export

getDecision <- function(p) {
  x <- runif(1)
  p <- cumsum(c(0, p))
  sum(x > p) - 1
}

Try the babsim.hospital package in your browser

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

babsim.hospital documentation built on May 30, 2022, 9:05 a.m.