PearsonsCorrelation { public RealMatrix getCorrelationPValues() { TDistribution tDistribution = new TDistribution(nObs - 2); int nVars = correlationMatrix.getColumnDimension(); double[][] out = new double[nVars][nVars]; for (int i = 0; i < nVars; i++) { for (int j = 0; j < nVars; j++) { if (i == j) { out[i][j] = 0d; } else { double r = correlationMatrix.getEntry(i, j); double t = FastMath.abs(r * FastMath.sqrt((nObs - 2)/(1 - r * r))); out[i][j] = 2 * tDistribution.cumulativeProbability(-t); } } } return new BlockRealMatrix(out); } PearsonsCorrelation();  PearsonsCorrelation(double[][] data);  PearsonsCorrelation(RealMatrix matrix);  PearsonsCorrelation(Covariance covariance);  PearsonsCorrelation(RealMatrix covarianceMatrix, int numberOfObservations); RealMatrix getCorrelationMatrix(); RealMatrix getCorrelationStandardErrors(); RealMatrix getCorrelationPValues(); RealMatrix computeCorrelationMatrix(RealMatrix matrix); RealMatrix computeCorrelationMatrix(double[][] data); double correlation(final double[] xArray, final double[] yArray); RealMatrix covarianceToCorrelation(RealMatrix covarianceMatrix);  }
@Test public void testPValueNearZero() { int dimension = 120; double[][] data = new double[dimension][2]; for (int i = 0; i < dimension; i++) { data[i][0] = i; data[i][1] = i + 1/((double)i + 1); } PearsonsCorrelation corrInstance = new PearsonsCorrelation(data); Assert.assertTrue(corrInstance.getCorrelationPValues().getEntry(0, 1) > 0); }