Class KendallRankCorrelation

  • All Implemented Interfaces:
    Statistic

    public class KendallRankCorrelation
    extends Object
    implements Statistic
    The Kendall rank correlation coefficient, commonly referred to as Kendall's tau (τ) coefficient, is a statistic used to measure the association between two measured quantities. A tau test is a non-parametric hypothesis test which uses the coefficient to test for statistical dependence. Specifically, it is a measure of rank correlation, that is, the similarity of the orderings of the data when ranked by each of the quantities.

    Specifically, for each pair of observations \((x_i, y_i), (x_j, y_j)\) we say that they are concordant if either \(x_i > x_j\) and \(y_i > y_j\) or \(x_i < x_j\) and \(y_i < y_j\). Otherwise, they are said to be discordant.

    Kendall's tau is defined as: \[ \tau = \frac{(\text{no. of concordant pairs}) - (\text{no. of discordant pairs})}{\frac{1}{2} n (n-1) } \]

    If the values in \(x\) and \(y\) are not unique, (τ - b) is computed.

    This class implements the O(n log n) algorithm from Knight, W. (1966). "A Computer Method for Calculating Kendall's Tau with Ungrouped Data".

    The R equivalent function is Kendall in package Kendall.

    See Also:
    Wikipedia: Kendall tau rank correlation coefficient
    • Constructor Detail

      • KendallRankCorrelation

        public KendallRankCorrelation​(double[] data1,
                                      double[] data2)
        Construct a Kendall rank calculator initialized with two samples. The size of the two sample must be equal.
        Parameters:
        data1 - the first sample
        data2 - the second sample
    • Method Detail

      • addData

        public void addData​(double... data)
        Update the statistic with more data. Since this signature takes only a single array double[], we concatenate the two arrays into one.

        For example, suppose we want to do

         
         addData(new double[][]{
             {1, 2, 3},
             {4, 5, 6}
         });
         
         
        We can also write
         
         addData(new double[]{
             {1, 2, 3, 4, 5, 6}
         });
         
         
        In the latter case, there must be an even number of data points.
        Specified by:
        addData in interface Statistic
        Parameters:
        data - a data array concatenating two samples
      • N

        public long N()
        Description copied from interface: Statistic
        Get the size of the sample.
        Specified by:
        N in interface Statistic
        Returns:
        the sample size
      • addData

        public void addData​(double[] data1,
                            double[] data2)
        Add the given two samples. The size of the two samples must be equal.
        Parameters:
        data1 - the first sample
        data2 - the second sample
      • value

        public double value()
        Description copied from interface: Statistic
        Get the value of the statistic.
        Specified by:
        value in interface Statistic
        Returns:
        the statistic