madn: Median Absolute Deviation from the Median or Mean for Small...

View source: R/madn.R

madnR Documentation

Median Absolute Deviation from the Median or Mean for Small Sample Size

Description

The median absolute deviation (MAD) is actually the median absolute deviation from the median. For small samples, the normal bias correction of 1.4826 has been shown by Croux & Rousseeuw (1992) to be insufficient. This function can apply the n-specific b_n correction factors found in that paper. It also can apply factors found by a significantly larger Monte-Carlo simulation for either the median absolute distance from the median or from the mean.

Usage

madn(x, center = c("median", "mean"), factors = c("AA", "CR"), na.rm = FALSE)

Arguments

x

numeric; A vector of values.

center

character; either "median" or "mean" which will be used as the function to calculate the central tendency from which to measure the absolute deviations. Defaults to "median".

factors

character; "CR" will use the factors calculated in Croux & Rousseeuw (1992) while "AA" (the default) will use the factors calculated by the package author. Note that if center == "mean", there are no CR factors and the AA factors will be used.

na.rm

logical; If TRUE then NA values are stripped from x before computation takes place.

Details

MAD_n = b_n\;1.4826\;\underset{i}{\textrm{med}}\;|x_i - \underset{j}{\textrm{med}}\;x_j|

where b_n is calculated either by Croux & Rousseeuw (1992) or by Adler (unpublished).

Croux & Rousseeuw (1992) used Monte-Carlo methods to calculate correction factors to make the standard MAD estimate more unbiased for small samples. They called this new function \textrm{MAD}_n to differentiate it from \textrm{MAD}, given the b_n multiplier is dependent on n—the size of the sample. This function can apply those factors to the mad function already existing in stats.

Inspired by Croux & Rousseeuw, the package author ran a significantly larger Monte-Carlo simulation for both the median absolute deviation from the median and the median absolute deviation from the mean. This function can use those factors as well.

However, unlike mad, this function only accepts "median" or "mean" as its central tendency, and not a scalar value or any other scalar-valued function, as the factors were only calculated for those two functions. Also, it does not allow passing a user-defined constant, as the intent is to return the unbiased estimate assuming normality.

If na.rm is TRUE then NA values are stripped from x before computation takes place. If this is not done then an NA value in x will cause madn to return NA.

Value

A numeric value representing the median absolute deviation from the requested central tendency adjusted by the asymptotic normality constant and the small-sample bias constant.

Author(s)

Avraham Adler Avraham.Adler@gmail.com

References

Croux, Christophe and Rousseeuw, Peter J. (1992) "Time-Efficient Algorithms for Two Highly Robust Estimators of Scale", Computational Statistics, Vol. 1, 411–428. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-3-662-26811-7_58")}

See Also

See adm in this package for the average/mean deviation from the median, mad from stats for the “standard” median absolute deviation from the median, and Sn and Qn from robustbase for other robust measures of scale by Croux & Rousseeuw.

Examples

x <- 1:5
madn(x)
madn(x, center = "mean")

# The length 5 CR correction constant is 1.206
all.equal(madn(x, factors = "CR"), 1.206 * mad(x))

# The length 5 AA constant for deviation from median is 1.2167
all.equal(madn(x), 1.2167 * mad(x))

# The length 5 AA constant for deviation from mean is 1.0750
all.equal(madn(x, center = "mean"),
          mad(x, center = mean(x)) * 1.0750)

revss documentation built on March 18, 2026, 9:06 a.m.