Closed spsanderson closed 2 years ago
hai_kurtosis_vec <- function(.x){ # Tidyeval ---- x_term <- .x # Checks ---- if(!is.numeric(x_term)){ stop(call. = FALSE, ".x must be a numeric vector.") } # Calculate n <- length(x_term) mu <- mean(x_term, na.rm = TRUE) n_diff <- (x_term - mu)^4 nu <- (1/n * sum(n_diff)) d_diff <- (x_term - mu)^2 de <- (1/n * sum(d_diff))^2 k <- nu/de return(k) print(k) } hai_skewness_vec <- function(.x){ # Tidyeval ---- x_term <- .x # Checks ---- if(!is.numeric(x_term)){ stop(call. = FALSE, ".x must be a numeric vector.") } # Calculate n <- length(x_term) mu <- mean(x_term, na.rm = TRUE) n_diff <- (x_term - mu)^3 nu <- (1/n * sum(n_diff)) d_diff <- (x_term - mu)^2 de <- (1/n * sum(d_diff))^(3/2) s <- nu/de return(s) print(s) }
Use this link for the formula
https://www.geeksforgeeks.org/skewness-and-kurtosis-in-r-programming/