mad | R Documentation |
Median absolute deviation, adapted to operate on complex data as well as numeric.
In the later case it simply calls stats::mad()
.
For complex x it uses the geometric median, pracma::geo_median()
, as the center,
then returns the median absolute difference between center and each element of x, multiplied by constant
.
mad(
x,
center = median(x),
constant = 1.4826,
na.rm = FALSE,
low = FALSE,
high = FALSE
)
x |
a numeric or complex vector. |
center |
optional, numeric or complex. The center about which to calculate MAD. Defaults to median for numeric, and geo_median for complex. |
constant |
a constant by which to multiply the median absolute deviation from center. Default is 1.4826, which is the inverse of the 3/4 quantile for the normal distribution. |
na.rm |
logical. Should NAs be removed from x before calculating. |
low |
logical. If TRUE, compute the "lo-median", i.e., for even sample size, do not average the two middle values, but take the smaller one. Not used if x is complex. |
high |
logical. If TRUE, compute the "hi-median", i.e., take the larger of the two middle values for even sample size. Not used if x is complex. |
numeric. The median absolute deviation (MAD) from center.
The concept of quantile requires ordering to be defined, which the complex numbers lack.
The usefulness of multiplying by constant
is thus called into question. However, for no more rigorous
reason than consistency, the default behavior of this function is to do so.
median.complex, stats::mad
set.seed(4242)
n <- 8
foo <- complex(real = rnorm(n), imaginary = rnorm(n))
mad(foo)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.