Last active
March 11, 2022 13:53
-
-
Save DrNickRedfern/e54a3607b3e5a41931dea548bf0adb9a to your computer and use it in GitHub Desktop.
Quantile-based summary of a numeric vector, returning the median, IQR, skewness, kurtosis, and quartile coefficient of dispersion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q_summary <- function (x) { | |
h <- Hmisc::hdquantile(x, probs = seq(0.125, 0.875, 0.125), na.rm = TRUE, names = FALSE, se = FALSE, weights = FALSE) | |
med = h[4]; iqr = h[6] - h[2] | |
skew = (h[2] + h[6] - (2 * h[4]))/iqr; kurt = ((h[7] - h[5]) + (h[3] - h[1]))/iqr | |
qcd = (iqr)/(h[6] + h[2]) | |
out <- list(med, iqr, skew, kurt, qcd) | |
names(out) <- c("median", "IQR", "skewness", "kurtosis", "quatile coefficient of dispersion") | |
return(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment