R/moments.R

Defines functions kurtosis skewness

#' Compute standardized moments (internal function)
#'
#' @description Internal function substituting the `moments` package. Only
#'   third (skewness) and fourth (kurtosis) moments are included.
#'
#' @keywords internal
#' @noRd
skewness <- function(x) {
  n <- length(x)
  dev <- x - mean(x, na.rm = TRUE)

  (sum(dev^3, na.rm = TRUE) / n) / (sum(dev^2, na.rm = TRUE) / n)^(3 / 2)
}

kurtosis <- function(x) {
  n <- length(x)
  dev <- x - mean(x, na.rm = TRUE)
  n * sum(dev^4, na.rm = TRUE) / (sum(dev^2, na.rm = TRUE)^2)
}

Try the ShinyItemAnalysis package in your browser

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

ShinyItemAnalysis documentation built on May 31, 2023, 7:08 p.m.