#' calculates z-statistic
#'
#' @param v numeric vector
#' @param mu number
#'
#' @return number
#' @export
#'
#' @examples
#' z_test(rnorm(50))
#' z_test(rnorm(50), 1)
#'
z_test <- function(v, mu = 0){
z <- sum(v- mu) / std_err(v)
p_value <- 2*pnorm(-abs(z))
cat(
"z = ",
round(z, digits = 4),
"; p =",
round(p_value, digits = 4),
"\nThe sample mean of",
round(mean(v), digits = 2),
"is",
ifelse(p_value < 0.05, "significantly",
"not significantly"),
"\ndifferent from ",
mu
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.