Hello, No, there isn't a built-in that I know of. Here is one:
double.mad <- function(x, include.right = FALSE, na.rm = FALSE){ if(na.rm) x <- x[!is.na(x)] m <- median(x) odd <- (length(x) %% 2L) == 1L out <- if(odd){ if(include.right) { c(lo = mad(x[x < m]), hi = mad(x[x >= m])) } else { c(lo = mad(x[x <= m]), hi = mad(x[x > m])) } } else { c(lo = mad(x[x < m]), hi = mad(x[x > m])) } out } double.mad(x) # lo hi #0.81543 0.44478 double.mad(c(x, 1)) # lo hi #2.29803 0.44478 double.mad(c(x, 1), include.right = TRUE) # lo hi #1.03782 1.63086 Hope this helps, Rui Barradas Às 15:22 de 03/08/2020, varin sacha via R-help escreveu:
Dear R-Experts, Is there an all-ready function to calculate the Double MAD (Median absolute deviation) as there is an easy function to calculate the MAD "mad function". Or I have to write my own function for Double MAD ? To calculate the double MAD, the idea is the following : for the obtained median value, we should calculate two median absolution deviations. One deviation should be calculated for the numbers below the median and one for the numbers above the median: Here is the very easy reproducible example : x<-c(2.5,4.4,3.2,2.1,1.3,2.6,5,6.6,5,5,6.1,7.2,9.4,6.9) mad(x) ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Este e-mail foi verificado em termos de vírus pelo software antivírus Avast. https://www.avast.com/antivirus ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.