Class SpearmanRankCorrelation
- java.lang.Object
-
- dev.nm.stat.descriptive.correlation.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}} \]
-
-
Constructor Summary
Constructors Constructor Description SpearmanRankCorrelation(double[] data1, double[] data2)
Construct a Spearman rank calculator initialized with two samples.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addData(double... data)
Update the statistic with more data.void
addData(double[] data1, double[] data2)
Add the given two samples.long
N()
Get the size of the sample.double
value()
Get the value of the statistic.
-
-
-
Method Detail
-
addData
public void addData(double... data)
Update the statistic with more data. Since this signature takes only a single arraydouble[]
, we concatenate the two arrays into one. For example, suppose we want to doaddData(new double[][]{ {1, 2, 3}, {4, 5, 6} });
addData(new double[]{ {1, 2, 3, 4, 5, 6} });
-
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 sampledata2
- the second sample
-
N
public long N()
Description copied from interface:Statistic
Get the size of the sample.
-
-