public class SpearmansCorrelation
extends java.lang.Object
PearsonsCorrelation
on the ranked data.
By default, ranks are computed using NaturalRanking
with default
strategies for handling NaNs and ties in the data (NaNs maximal, ties averaged).
The ranking algorithm can be set using a constructor argument.
Modifier and Type | Field and Description |
---|---|
private RealMatrix |
data
Input data
|
private PearsonsCorrelation |
rankCorrelation
Rank correlation
|
private RankingAlgorithm |
rankingAlgorithm
Ranking algorithm
|
Constructor and Description |
---|
SpearmansCorrelation()
Create a SpearmansCorrelation without data.
|
SpearmansCorrelation(RankingAlgorithm rankingAlgorithm)
Create a SpearmansCorrelation with the given ranking algorithm.
|
SpearmansCorrelation(RealMatrix dataMatrix)
Create a SpearmansCorrelation from the given data matrix.
|
SpearmansCorrelation(RealMatrix dataMatrix,
RankingAlgorithm rankingAlgorithm)
Create a SpearmansCorrelation with the given input data matrix
and ranking algorithm.
|
Modifier and Type | Method and Description |
---|---|
RealMatrix |
computeCorrelationMatrix(double[][] matrix)
Computes the Spearman's rank correlation matrix for the columns of the
input rectangular array.
|
RealMatrix |
computeCorrelationMatrix(RealMatrix matrix)
Computes the Spearman's rank correlation matrix for the columns of the
input matrix.
|
double |
correlation(double[] xArray,
double[] yArray)
Computes the Spearman's rank correlation coefficient between the two arrays.
|
RealMatrix |
getCorrelationMatrix()
Calculate the Spearman Rank Correlation Matrix.
|
private java.util.List<java.lang.Integer> |
getNaNPositions(double[] input)
Returns a list containing the indices of NaN values in the input array.
|
PearsonsCorrelation |
getRankCorrelation()
Returns a
PearsonsCorrelation instance constructed from the
ranked input data. |
private RealMatrix |
rankTransform(RealMatrix matrix)
Applies rank transform to each of the columns of
matrix
using the current rankingAlgorithm . |
private double[] |
removeValues(double[] input,
java.util.Set<java.lang.Integer> indices)
Removes all values from the input array at the specified indices.
|
private final RealMatrix data
private final RankingAlgorithm rankingAlgorithm
private final PearsonsCorrelation rankCorrelation
public SpearmansCorrelation()
public SpearmansCorrelation(RankingAlgorithm rankingAlgorithm)
From version 4.0 onwards this constructor will throw an exception
if the provided NaturalRanking
uses a NaNStrategy.REMOVED
strategy.
rankingAlgorithm
- ranking algorithmpublic SpearmansCorrelation(RealMatrix dataMatrix)
dataMatrix
- matrix of data with columns representing
variables to correlatepublic SpearmansCorrelation(RealMatrix dataMatrix, RankingAlgorithm rankingAlgorithm)
From version 4.0 onwards this constructor will throw an exception
if the provided NaturalRanking
uses a NaNStrategy.REMOVED
strategy.
dataMatrix
- matrix of data with columns representing
variables to correlaterankingAlgorithm
- ranking algorithmpublic RealMatrix getCorrelationMatrix()
public PearsonsCorrelation getRankCorrelation()
PearsonsCorrelation
instance constructed from the
ranked input data. That is,
new SpearmansCorrelation(matrix).getRankCorrelation()
is equivalent to
new PearsonsCorrelation(rankTransform(matrix))
where
rankTransform(matrix)
is the result of applying the
configured RankingAlgorithm
to each of the columns of
matrix.
public RealMatrix computeCorrelationMatrix(RealMatrix matrix)
matrix
- matrix with columns representing variables to correlatepublic RealMatrix computeCorrelationMatrix(double[][] matrix)
matrix
- matrix with columns representing variables to correlatepublic double correlation(double[] xArray, double[] yArray)
xArray
- first data arrayyArray
- second data arrayDimensionMismatchException
- if the arrays lengths do not matchMathIllegalArgumentException
- if the array length is less than 2private RealMatrix rankTransform(RealMatrix matrix)
matrix
using the current rankingAlgorithm
.matrix
- matrix to transformprivate java.util.List<java.lang.Integer> getNaNPositions(double[] input)
input
- the input arrayprivate double[] removeValues(double[] input, java.util.Set<java.lang.Integer> indices)
input
- the input arrayindices
- a set containing the indices to be removedCopyright (c) 2003-2014 Apache Software Foundation