Medcouple
above, and the corresponding histogram of the medcouple kernel values below. The actual medcouple is the median of the bottom distribution, marked at 0.188994 with a yellow line. In statistics, the medcouple is a robust statistic that measures the skewness of a univariate distribution. It is defined as a scaled median difference between the left and right half of a distribution. Its robustness makes it suitable for identifying outliers in adjusted boxplots. Ordinary box plots do not fare well with skew distributions, since they label the longer unsymmetrical tails as outliers. Using the medcouple, the whiskers of a boxplot can be adjusted for skew distributions and thus have a more accurate... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
above, and the corresponding histogram of the medcouple kernel values below. The actual medcouple is the median of the bottom distribution, marked at 0.188994 with a yellow line. In statistics, the medcouple is a robust statistic that measures the skewness of a univariate distribution. It is defined as a scaled median difference between the left and right half of a distribution. Its robustness makes it suitable for identifying outliers in adjusted boxplots. Ordinary box plots do not fare well with skew distributions, since they label the longer unsymmetrical tails as outliers. Using the medcouple, the whiskers of a boxplot can be adjusted for skew distributions and thus have a more accurate identification of outliers for non-symmetrical distributions. As a kind of order statistic, the medcouple belongs to the class of incomplete generalised L-statistics. Like the ordinary median or mean, the medcouple is a nonparametric statistic, thus it can be computed for any distribution. Let X := \{x_0 \geq x_1 \geq \ldots \geq x_{n-1}\} be an ordered sample of size n , and let x_m be the median of X . Define the sets X^+ := \{x_i ~|~ x_i \geq x_m \} , X^- := \{x_j ~|~ x_j \leq x_m \} , of sizes p := |X^+| and q := |X^-| respectively. For x_i^+ \in X^+ and x_j^- \in X^- , we define the kernel function h(x_i^+, x_j^-) := \begin{cases} \displaystyle\frac{(x_i^+ - x_m) - (x_m - x_j^-)}{x_i^+ - x_j^-} & \text { if } x_i^+ > x_j^-, \\ \operatorname{signum} (p - 1 - i - j) & \text{ if } x_i^+ = x_m = x_j^-, \end{cases} where \operatorname{signum} is the sign function. The medcouple is then the median of the set \{h(x_i^+, x_j^-) ~|~ x_i^+ \in X^+ \text{ and } x_j^- \in X^- \} . In other words, we split the distribution into all values greater or equal to the median and all values less than or equal to the median. We define a kernel function whose first variable is over the p greater values and whose second variable is over the q lesser values. For the special case of values tied to the median, we define the kernel by the signum function. The medcouple is then the median over all pq values of h(x_i^+, x_j^-) . Since the medcouple is not a median applied to all (x_i, x_j) couples, but only to those for which x_i^+ \geq x_m \geq x_j^- , it belongs to the class of incomplete generalised L-statistics. Z^+ := \left.\left\{\frac{x_i^+ - x_m}{r} ~\right|~ x_i^+ \in X^+\right\} Z^- := \left.\left\{\frac{x_j^- - x_m}{r} ~\right|~ x_j^- \in X^-\right\} where r = 2 \max_{0 \leq i \leq n-1} |x_i| . This makes the set Z := Z^+ \cup Z^- have range of at most 1, median 0, and keep the same medcouple as X . For Z , the medcouple kernel reduces to h(z_i^+, z_j^-) := \begin{cases} \displaystyle\frac{z_i^+ + z_j^-}{z_i^+ - z_j^-} & \text { if } z_i^+ > z_j^- \\ \operatorname{signum} (p - 1 - i - j) & \text{ if } z_i^+ = 0 = z_j^- \end{cases} Using the recentred and rescaled set Z we can observe the following. The kernel function is between -1 and 1, that is, |h(z_i^+, z_j^-)| \leq 1 . This follows from the reverse triangle inequality |a| - |b| \leq |a - b| with a = z_i^+ and b = z_j^- and the fact that z_i^+ \geq 0 \geq z_j^- . The medcouple kernel h(z_i^+, z_j^-) is non-decreasing in each variable. This can be verified by the partial derivatives \frac{\partial h}{\partial z_i^+} and \frac{\partial h}{\partial z_j^-} , both nonnegative, since z_i^+ \geq 0 \geq z_j^- . With properties 1, 2, and 4, we can thus define the following matrix, H :=(h_{ij}) = (h(z_i^+, z_j^-)) = \begin{pmatrix} h(z_0^+, z_0^-) & \cdots & h(z_0^+, z_{q - 1}^-) \\ \vdots & \ddots & \vdots \\ h(z_{p -1}^+, z_0^-) & \cdots & h(z_{p -1}^+, z_{q - 1}^-) \end{pmatrix}. If we sort the sets Z^+ and Z^- in decreasing order, then the matrix H has sorted rows and sorted columns, H = \begin{pmatrix} h(z_0^+, z_0^-) & \geq & \cdots & \geq & h(z_0^+, z_{q - 1}^-) \\ \geq & & & & \geq \\ \vdots & & \ddots & & \vdots \\ \geq & & & & \geq \\ h(z_{p -1}^+, z_0^-) & \geq & \cdots & \geq & h(z_{p -1}^+, z_{q - 1}^-) \end{pmatrix}. The medcouple is then the median of this matrix with sorted rows and sorted columns. The fact that the rows and columns are sorted allows the implementation of a fast algorithm for computing the medcouple. xm := median(X) xscale := 2 * max(abs(X)) // Define the upper and lower centred and rescaled vectors // they inherit X's own decreasing sorting Zplus := [(x - xm)/xscale | x in X such that x >= xm] Zminus := [(x - xm)/xscale | x in X such that x median on a vector of size O(n^2) can be done itself in O(n^2) operations, hence the entire naïve medcouple algorithm is of the same complexity. The first stage of the fast algorithm proceeds as the naïve algorithm. We first compute the necessary ingredients for the kernel matrix, H = (h_{ij}) , with sorted rows and sorted columns in decreasing order. Rather than computing all values of h_{ij} , we instead exploit the monotonicity in rows and columns, via the following observations. function greater_h(kernel h, int p, int q, real u): // h is the kernel function, h(i,j) gives the ith, jth entry of H // p and q are the number of rows and columns of the kernel matrix H // vector of size p P := vector(p) // indexing from zero j := 0 // starting from the bottom, compute the least upper bound for each row for i := p - 1, p - 2, ..., 1, 0: // search this row until we find a value less than u while j u: j := j + 1 endwhile // the entry preceding the one we just found is greater than u P[i] := j - 1 endfor return P endfunction This greater_h function is traversing the kernel matrix from the bottom left to the top right, and returns a vector P of indices that indicate for each row where the boundary lies between values greater than u and those less than or equal to u . This method works because of the row-column sorted property of H = (h_{ij}) . Since greater_h computes at most p + q values of h_{ij} , its complexity is O(n) . Conceptually, the resulting P vector can be visualised as establishing a boundary on the matrix as suggested by the following diagram, where the red entries are all larger than u : The symmetric algorithm for computing the values of h_{ij} less than u is very similar. It instead proceeds along H in the opposite direction, from the top right to the bottom left: function less_h(kernel h, int p, int q, real u): // vector of size p Q := vector(p) // last possible row index j := q - 1 // starting from the top, compute the greatest lower bound for each row for i := 0, 1, ..., p - 2, p - 1: // search this row until we find a value greater than u while j >= 0 and h(i, j) This lower boundary can be visualised like so, where the blue entries are smaller than u : For each i , we have that P_i \geq Q_i , with strict inequality occurring only for those rows that have values equal to u . We also have that the sums \sum_{i=0}^{p-1} (P_i + 1) ~\qquad~ \sum_{i=0}^{p-1} Q_i give, respectively, the number of elements of H that are greater than u , and the number of elements that are greater than or equal to u . Thus this method also yields the rank of u within the elements h_{ij} of H . xm := median(X) xscale := 2 * max(abs(X)) Zplus := [(x - xm)/xscale | x in X such that x >= xm] Zminus := [(x - xm)/xscale | x in X such that x p: // Compute row medians and their associated weights, but skip // any rows that are already empty. middle_idx := [i | i in [0, 1, ..., p - 1] such that L[i] Qtotal - 1: L := Q Ltotal := Qtotal else: // Found the medcouple, rank of the weighted median equals medcouple index return WM endif endif endwhile // Did not find the medcouple, but there are very few tentative entries remaining remaining := [h(i, j) | i in [0, 1, ..., p - 1], j in [L[i], L[i] + 1, ..., R[i such that L[i] greater_h and less_h functions. The naïve algorithm is also implemented for the Python package statsmodels. ==See also== Robust statistic Skewness Adjusted boxplots ==References==
Cite this
"Medcouple". 1780689555. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1357988223 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy