Skip to content

Instantly share code, notes, and snippets.

@DrNickRedfern
Last active March 11, 2022 13:59
Show Gist options
  • Save DrNickRedfern/7a3c553b724714fe483181d02f7801eb to your computer and use it in GitHub Desktop.
Save DrNickRedfern/7a3c553b724714fe483181d02f7801eb to your computer and use it in GitHub Desktop.
Calcualate a trimean using Harrell-Davis quantile estimator (default = Tukey's trimean)
trimean <- function(x, p = 0.25, a = 0.25){
q <- Hmisc::hdquantile(x, probs = c(p, 0.5, 1-p), na.rm = TRUE, names = FALSE)
tm <- (a * q[1]) + ((1 - (2 * p)) * q[2]) + (a * q[3])
return(tm)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment