I am trying to use Apache Commons Math’s SpearmansCorrelation but I am having some difficulty as I do not have enough background in mathematics/statistics.
I have researched Spearman’s Rank Correlation from:
- https://statistics.laerd.com/statistical-guides/spearmans-rank-order-correlation-statistical-guide-2.php
- http://geographyfieldwork.com/SpearmansRank.htm
I have found the following examples:
- http://www.devdaily.com/java/jwarehouse/commons-math/src/main/java/org/apache/commons/math/stat/correlation/SpearmansCorrelation.java.shtml
- http://www.devdaily.com/java/jwarehouse/commons-math/src/test/java/org/apache/commons/math/stat/correlation/SpearmansRankCorrelationTest.java.shtml
- http://www.androidadb.com/class/na/NaturalRanking.html
I would like to calculate the correlation between two lists of my class:
public class TestClass{
int rank; // there may be two or more classes with the same rank - will need an averaging ties strategy
}
From which I have deduced the following:
NaturalRanking naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
TiesStrategy.AVERAGE);
RealMatrix dataMatrix= createRealMatrix(double[], int, int); // what do I need this matrix for and what parameters do I need to pass?
SpearmansCorrelation sc = SpearmansCorrelation(dataMatrix, naturalRanking);
sc.correlation(double[],double[]);// I have to convert my class into a list of doubles? How?
For the example found in the link you provided, all you need to do is:
The class will average ties by default.