1 Matching Annotations
  1. Apr 2019
    1. skewness <- function(x, na.rm = FALSE) { n <- length(x) m <- mean(x, na.rm = na.rm) v <- var(x, na.rm = na.rm) (sum(x - m)^3 / (n - 2)) / v^(3 / 2) }

      This function always returns 0. This is because sum(x-m) (performed before raised to the power 3) will always be 0. Resolved with additional parenthesis:

      skewness <- function(x, na.rm = FALSE) { n <- length(x) m <- mean(x, na.rm = na.rm) v <- var(x, na.rm = na.rm) (sum((x - m)^3) / (n - 2)) / v^(3 / 2) }

      I appreciate there are several possible formulas for skewness which may not match this one.