#' Create Confidence Interval using t Distribution
#'
#' @param data One column of data to create a confidence interval of the mean for.
#' @param alpha Alpha level of the confidence interval.
#' @param rounding_places How many places to round each side of the confidence interval to.
#'
#' @return A confidence interval for the mean based on the t-distribution.
#' @export
#' @importFrom stats qt sd
t_ci <- function(data, alpha, rounding_places) {
n <- length(data)
moe <- stats::qt(1-(alpha/2), df=n-1) * stats::sd(data) / sqrt(n)
lower <- mean(data) - moe
upper <- mean(data) + moe
return(
paste(
"(", round(lower, rounding_places), ", ",
round(upper, rounding_places), ")",
sep=""
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.