R/apa.ci.r

#' @title apa.ci
#'
#' @description APA formating for confidence intervals
#'
#' @export
#' 
#' @param lb lower bound of the confidence interval
#' @param ub upper bound of the confidence interval
#' @param level the confidence level (optional)
#' @return the formatted value as a \code{\link[base]{character}}
#'
#' @author Mark Newman, \email{mark@trinetteandmark.com}
#' @keywords statistic
#' @family statistic
#'
#' @examples
#'   ci = apa.ci(1,2)
#'   cis = apa.ci(c(1, 0.01), c(2, 1.006), c(.95, .99))
#'   # In the markdown put `r ci` or `r cis`
#'   
apa.ci = function(lb, ub, level = .95) {
  
  stopifnot(level < 1)

  res = sprintf("CI %s%% [%s, %s]", 100*level, round(lb, 2), round(ub, 2))
  
  return(res)
}
markanewman/apaformat documentation built on May 10, 2019, 1:19 a.m.