R/04-estimate_classic.R

Defines functions estimate_classic

Documented in estimate_classic

################################################################################
#
#' Estimate proportion using classic estimator
#'
#' @param x Total number of successes
#' @param n Total number of tests
#' @param z z-value. Default is 1.96 for 95\% confidence interval
#'
#' @return A list containing the following components:
#' \item{\code{estimate}}{A vector with the sample proportions}
#' \item{\code{conf.int}}{A confidence interval for the true proportion}
#'
#' @examples
#'
#' estimate_classic(x = 50, n = 200)
#'
#' @export
#'
#
################################################################################

estimate_classic <- function(x, n, z = 1.96) {
  estimate <- x / n
  lowerCI  <- estimate - z * sqrt((estimate * (1 - estimate)) / (n ^ 2))
  upperCI  <- estimate + z * sqrt((estimate * (1 - estimate)) / (n ^ 2))
  conf.int <- c(lowerCI, upperCI)
  x <- list(estimate, conf.int)
  return(x)
}
validmeasures/liberiaData documentation built on Dec. 2, 2020, 3:32 a.m.