| madn | R Documentation |
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.
madn(x, center = c("median", "mean"), factors = c("AA", "CR"), na.rm = FALSE)
x |
numeric; A vector of values. |
center |
character; either |
factors |
character; |
na.rm |
logical; If |
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.
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.
Avraham Adler Avraham.Adler@gmail.com
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 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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.