medcouple {phylter} | R Documentation |
A robust measure of skewness for univariate data
Description
Computes the medcouple, a robust measure of skewness for univariate data. For multivariate data the medcouple is calculated on each column of the data matrix.
Usage
medcouple(x, do.reflect = NULL)
Arguments
x |
An |
do.reflect |
Logical indicating whether the medcouple should also be computed on the reflected sample |
Details
The medcouple is a robust measure of skewness yielding values between and
. For left- and right-skewed data the medcouple is negative and positive respectively.
The medcouple is defined as the median of the kernel function
evaluated over all couples
where
is smaller than the median of
x
and larger than the median of
x
. When there are multiple observations tied to the median, the kernel is defined separately as the denominator is not defined for these observations. Let denote the indices of the observations which are tied to the median. Then
is defined to equal
if
,
when
and
if
. To compute the medcouple an algorithm with time complexity
is applied. For details, see https://en.wikipedia.org/wiki/Medcouple.
For numerical accuracy it is advised, for small data sets, to compute the medcouple on both
x
and -x
. The final value of the medcouple may then be obtained as a linear combination of both calculations. This procedure is warranted by the properties of the medcouple. Indeed the medcouple of the distribution equals minus the medcouple of the reflected distribution
. Moreover the medcouple is location and scale invariant.
Note that missing values are not allowed.
Value
mc A -vector containing the medcouple of each column of the data matrix
x
.
Note
This function is extracted from the package mrfDepth - 07/2023
Author(s)
P. Segaert with original code from M. Maechler and G. Brys.
References
Brys G., Hubert M., Struyf A. (2004). A robust measure of skewness. Journal of Computational and Graphical Statistics, 13, 996–1017.
Examples
# Calculate the medcouple of univariate data sets.
# For 2000 normally distributed values
# the medcouple value is close to 0 because
# data are not skewed
x<-rnorm(2000)
medcouple(x)
# For 2000 values following a lognormal
# distribution (mean 0,sd 1), medcouple is close to 1
# because values are right-skewed
y<-rnorm(2000)
medcouple(y)
# Use the option do.reflect to increase expected accuracy.
medcouple(y, do.reflect = TRUE)