A function for the median absolute deviation is included in base R, mad, but there's no function for calculating confidence intervals. Arachchige/Prendergast introduce interval estimators of the MAD to make reliable inferences for dispersion for a single population and ratios and differences of MADs for comparing two populations.

MADCI(x, y = NULL, two.samp.diff = TRUE, gld.est = "TM", 
      conf.level = 0.95, sides = c("two.sided","left","right"), 
      na.rm = FALSE, ...)

Arguments

x

a (non-empty) numeric vector of data values.

y

a second (non-empty) numeric vector of data values.

two.samp.diff

logical, defining if the confidence intervals for the difference (mad(x)-mad(y)) (default) or for the squared ratio ((mad(x)/mad(y))^2) should be calculated. Ignored if y is not given.

gld.est

A character string, to select the estimation method for the generalized lambda distribution. One of: ML for numerical Maximum Likelihood, MPS or MSP for Maximum Spacings Product, TM for Titterington's Method (default), SM for Starship Method, TL for method of Trimmed L-moments, Lmom for method of L-moments, DLA for the method of Distributional Least Absolutes, or Mom for method of Moments. See fit.fkml().

conf.level

confidence level of the interval.

sides

a character string specifying the side of the confidence interval, must be one of "two.sided" (default), "left" or "right". You can specify just the initial letter. "left" would be analogue to a hypothesis of "greater" in a t.test.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

...

further arguments, not used here

Value

a numeric vector with 3 elements:

mad

median absolute deviation

lwr.ci

lower bound of the confidence interval

upr.ci

upper bound of the confidence interval

References

Arachchige Chandima N. P. G., Prendergast Luke A. (2019) Confidence intervals for median absolute deviations, arXiv:1910.00229 [math.ST]

Author

Arachchige Chandima N. P. G., Prendergast Luke A., Andri Signorell <andri@signorell.net> (only interface)

See also

Examples

x <- rlnorm(100)
y <- rlnorm(200, meanlog=1.2)

MADCI(x)                           # single sample
#>       mad    lwr.ci    upr.ci 
#> 0.6951838 0.5116239 0.8787437 

MADCI(x, y)                        # two sample difference
#>       mad    lwr.ci    upr.ci 
#> -2.339468 -3.399927 -1.279008 
MADCI(x, y, two.samp.diff = FALSE) # two sample squared ratio 
#>        mad     lwr.ci     upr.ci 
#> 0.05247853 0.02203910 0.12495957