Class SpearmansCorrelation
java.lang.Object
org.apache.commons.math.stat.correlation.SpearmansCorrelation
Spearman's rank correlation. This implementation performs a rank
transformation on the input data and then computes 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.
- Since:
- 2.0
- Version:
- $Revision: 983921 $ $Date: 2010-08-10 12:46:06 +0200 (mar. 10 août 2010) $
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a SpearmansCorrelation without data.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. -
Method Summary
Modifier and TypeMethodDescriptioncomputeCorrelationMatrix
(double[][] matrix) Computes the Spearman's rank correlation matrix for the columns of the input rectangular array.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.Calculate the Spearman Rank Correlation Matrix.Returns aPearsonsCorrelation
instance constructed from the ranked input data.
-
Constructor Details
-
SpearmansCorrelation
Create a SpearmansCorrelation with the given input data matrix and ranking algorithm.- Parameters:
dataMatrix
- matrix of data with columns representing variables to correlaterankingAlgorithm
- ranking algorithm
-
SpearmansCorrelation
Create a SpearmansCorrelation from the given data matrix.- Parameters:
dataMatrix
- matrix of data with columns representing variables to correlate
-
SpearmansCorrelation
public SpearmansCorrelation()Create a SpearmansCorrelation without data.
-
-
Method Details
-
getCorrelationMatrix
Calculate the Spearman Rank Correlation Matrix.- Returns:
- Spearman Rank Correlation Matrix
-
getRankCorrelation
Returns aPearsonsCorrelation
instance constructed from the ranked input data. That is,new SpearmansCorrelation(matrix).getRankCorrelation()
is equivalent tonew PearsonsCorrelation(rankTransform(matrix))
whererankTransform(matrix)
is the result of applying the configuredRankingAlgorithm
to each of the columns ofmatrix.
- Returns:
- PearsonsCorrelation among ranked column data
-
computeCorrelationMatrix
Computes the Spearman's rank correlation matrix for the columns of the input matrix.- Parameters:
matrix
- matrix with columns representing variables to correlate- Returns:
- correlation matrix
-
computeCorrelationMatrix
Computes the Spearman's rank correlation matrix for the columns of the input rectangular array. The columns of the array represent values of variables to be correlated.- Parameters:
matrix
- matrix with columns representing variables to correlate- Returns:
- correlation matrix
-
correlation
Computes the Spearman's rank correlation coefficient between the two arrays. Throws IllegalArgumentException if the arrays do not have the same length or their common length is less than 2- Parameters:
xArray
- first data arrayyArray
- second data array- Returns:
- Returns Spearman's rank correlation coefficient for the two arrays
- Throws:
IllegalArgumentException
- if the arrays lengths do not match or there is insufficient data
-