Changed deprecated MathRuntimeException in package stat.correlation
JIRA: MATH-459 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1239802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11f91fd0eb
commit
c9369dc298
|
@ -16,10 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math.stat.correlation;
|
package org.apache.commons.math.stat.correlation;
|
||||||
|
|
||||||
import org.apache.commons.math.MathException;
|
|
||||||
import org.apache.commons.math.MathRuntimeException;
|
|
||||||
import org.apache.commons.math.distribution.TDistribution;
|
import org.apache.commons.math.distribution.TDistribution;
|
||||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||||
|
import org.apache.commons.math.exception.MathIllegalArgumentException;
|
||||||
import org.apache.commons.math.exception.NullArgumentException;
|
import org.apache.commons.math.exception.NullArgumentException;
|
||||||
import org.apache.commons.math.exception.DimensionMismatchException;
|
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
|
@ -158,9 +157,10 @@ public class PearsonsCorrelation {
|
||||||
* <i>significance</i> of the corresponding correlation coefficients.</p>
|
* <i>significance</i> of the corresponding correlation coefficients.</p>
|
||||||
*
|
*
|
||||||
* @return matrix of p-values
|
* @return matrix of p-values
|
||||||
* @throws MathException if an error occurs estimating probabilities
|
* @throws org.apache.commons.math.exception.MaxCountExceededException
|
||||||
|
* if an error occurs estimating probabilities
|
||||||
*/
|
*/
|
||||||
public RealMatrix getCorrelationPValues() throws MathException {
|
public RealMatrix getCorrelationPValues() {
|
||||||
TDistribution tDistribution = new TDistribution(nObs - 2);
|
TDistribution tDistribution = new TDistribution(nObs - 2);
|
||||||
int nVars = correlationMatrix.getColumnDimension();
|
int nVars = correlationMatrix.getColumnDimension();
|
||||||
double[][] out = new double[nVars][nVars];
|
double[][] out = new double[nVars][nVars];
|
||||||
|
@ -221,16 +221,16 @@ public class PearsonsCorrelation {
|
||||||
* @param xArray first data array
|
* @param xArray first data array
|
||||||
* @param yArray second data array
|
* @param yArray second data array
|
||||||
* @return Returns Pearson's correlation coefficient for the two arrays
|
* @return Returns Pearson's correlation coefficient for the two arrays
|
||||||
* @throws IllegalArgumentException if the arrays lengths do not match or
|
* @throws DimensionMismatchException if the arrays lengths do not match
|
||||||
* there is insufficient data
|
* @throws MathIllegalArgumentException if there is insufficient data
|
||||||
*/
|
*/
|
||||||
public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException {
|
public double correlation(final double[] xArray, final double[] yArray) {
|
||||||
SimpleRegression regression = new SimpleRegression();
|
SimpleRegression regression = new SimpleRegression();
|
||||||
if (xArray.length != yArray.length) {
|
if (xArray.length != yArray.length) {
|
||||||
throw new DimensionMismatchException(xArray.length, yArray.length);
|
throw new DimensionMismatchException(xArray.length, yArray.length);
|
||||||
} else if (xArray.length < 2) {
|
} else if (xArray.length < 2) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException(
|
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
|
||||||
LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
|
xArray.length, 2);
|
||||||
} else {
|
} else {
|
||||||
for(int i=0; i<xArray.length; i++) {
|
for(int i=0; i<xArray.length; i++) {
|
||||||
regression.addData(xArray[i], yArray[i]);
|
regression.addData(xArray[i], yArray[i]);
|
||||||
|
@ -271,13 +271,13 @@ public class PearsonsCorrelation {
|
||||||
* two columns and two rows
|
* two columns and two rows
|
||||||
*
|
*
|
||||||
* @param matrix matrix to check for sufficiency
|
* @param matrix matrix to check for sufficiency
|
||||||
|
* @throws MathIllegalArgumentException if there is insufficient data
|
||||||
*/
|
*/
|
||||||
private void checkSufficientData(final RealMatrix matrix) {
|
private void checkSufficientData(final RealMatrix matrix) {
|
||||||
int nRows = matrix.getRowDimension();
|
int nRows = matrix.getRowDimension();
|
||||||
int nCols = matrix.getColumnDimension();
|
int nCols = matrix.getColumnDimension();
|
||||||
if (nRows < 2 || nCols < 2) {
|
if (nRows < 2 || nCols < 2) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException(
|
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS,
|
||||||
LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS,
|
|
||||||
nRows, nCols);
|
nRows, nCols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
|
|
||||||
package org.apache.commons.math.stat.correlation;
|
package org.apache.commons.math.stat.correlation;
|
||||||
|
|
||||||
import org.apache.commons.math.MathRuntimeException;
|
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||||
|
import org.apache.commons.math.exception.MathIllegalArgumentException;
|
||||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||||
import org.apache.commons.math.linear.BlockRealMatrix;
|
import org.apache.commons.math.linear.BlockRealMatrix;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
|
@ -135,23 +136,18 @@ public class SpearmansCorrelation {
|
||||||
/**
|
/**
|
||||||
* Computes the Spearman's rank correlation coefficient between the two arrays.
|
* Computes the Spearman's rank correlation coefficient between the two arrays.
|
||||||
*
|
*
|
||||||
* </p>Throws IllegalArgumentException if the arrays do not have the same length
|
|
||||||
* or their common length is less than 2</p>
|
|
||||||
*
|
|
||||||
* @param xArray first data array
|
* @param xArray first data array
|
||||||
* @param yArray second data array
|
* @param yArray second data array
|
||||||
* @return Returns Spearman's rank correlation coefficient for the two arrays
|
* @return Returns Spearman's rank correlation coefficient for the two arrays
|
||||||
* @throws IllegalArgumentException if the arrays lengths do not match or
|
* @throws DimensionMismatchException if the arrays lengths do not match
|
||||||
* there is insufficient data
|
* @throws MathIllegalArgumentException if the array length is less than 2
|
||||||
*/
|
*/
|
||||||
public double correlation(final double[] xArray, final double[] yArray)
|
public double correlation(final double[] xArray, final double[] yArray) {
|
||||||
throws IllegalArgumentException {
|
|
||||||
if (xArray.length != yArray.length) {
|
if (xArray.length != yArray.length) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException(
|
throw new DimensionMismatchException(xArray.length, yArray.length);
|
||||||
LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length);
|
|
||||||
} else if (xArray.length < 2) {
|
} else if (xArray.length < 2) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException(
|
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
|
||||||
LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
|
xArray.length, 2);
|
||||||
} else {
|
} else {
|
||||||
return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(xArray),
|
return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(xArray),
|
||||||
rankingAlgorithm.rank(yArray));
|
rankingAlgorithm.rank(yArray));
|
||||||
|
|
Loading…
Reference in New Issue