## Class SpearmanRankCorrelation

• All Implemented Interfaces:
Statistic

public class SpearmanRankCorrelation
extends Object
implements Statistic
Spearman's rank correlation coefficient or Spearman's rho is a non-parametric measure of statistical dependence between two variables. It assesses how well the relationship between two variables can be described using a monotonic function. If there are no repeated data values, a perfect Spearman correlation of +1 or -1 occurs when each of the variables is a perfect monotone function of the other.

For a set of observations $$(X_i, Y_i)$$ we first compute the ranks $$x_i$$ and $$y_i$$ of the $$X$$ and $$Y$$ values for each observation. Spearman's rho is defined as the Pearson correlation coefficient between the ranked variables: $\rho = \frac{\sum_i(x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\sum_i (x_i-\bar{x})^2 \sum_i(y_i-\bar{y})^2}}$

Wikipedia: Spearman's rank correlation coefficient, Covariance.correlation()
• ### Constructor Summary

Constructors
Constructor Description
SpearmanRankCorrelation​(double[] data1, double[] data2)
Construct a Spearman rank calculator initialized with two samples.
• ### Method Summary

All Methods
Modifier and Type Method Description
void addData​(double... data)
Update the statistic with more data.
void addData​(double[] data1, double[] data2)
long N()
Get the size of the sample.
double value()
Get the value of the statistic.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### SpearmanRankCorrelation

public SpearmanRankCorrelation​(double[] data1,
double[] data2)
Construct a Spearman 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

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

 
{1, 2, 3},
{4, 5, 6}
});


We can also write
 
{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

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
• #### 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
• #### value

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