R/add_ci_bounds_mc_power.R

Defines functions add_ci_bounds_mc_power

Documented in add_ci_bounds_mc_power

#'@title Calculate CI bounds on Monte Carlo
#'
#'@description Calculates CI bounds for Monte Carlo power
#'@return Power data.frame with conf intervals
#'@keywords internal
add_ci_bounds_mc_power = function(power_results, nsim, conf = 0.95) {
  get_lcbs = function(power) {
    return(unlist(lapply(power, \(x) (binom.test(x*nsim, n = nsim, conf.level = conf)[["conf.int"]][1]))))
  }
  get_ucbs = function(power) {
    return(unlist(lapply(power, \(x) (binom.test(x*nsim, n = nsim, conf.level = conf)[["conf.int"]][2]))))
  }
  lcb = get_lcbs(power_results[["power"]])
  ucb = get_ucbs(power_results[["power"]])
  power_results$power_lcb = lcb
  power_results$power_ucb = ucb
  return(power_results)
}

Try the skpr package in your browser

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

skpr documentation built on May 29, 2024, 5:06 a.m.