/** * Computes the Pearson's product-moment correlation coefficient between two arrays. * * <p>Throws MathIllegalArgumentException if the arrays do not have the same length * or their common length is less than 2. Returns {@code NaN} if either of the arrays * has zero variance (i.e., if one of the arrays does not contain at least two distinct * values).</p> * * @param xArray first data array * @param yArray second data array * @return Returns Pearson's correlation coefficient for the two arrays * @throws DimensionMismatchException if the arrays lengths do not match * @throws MathIllegalArgumentException if there is insufficient data */ public double correlation(final double[] xArray, final double[] yArray) { SimpleRegression regression = new SimpleRegression(); if (xArray.length != yArray.length) { throw new DimensionMismatchException(xArray.length, yArray.length); } else if (xArray.length < 2) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); } else { for(int i=0; i<xArray.length; i++) { regression.addData(xArray[i], yArray[i]); } return regression.getR(); } }
/** * Computes regression analysis for all data set at once (all measured values). */ //regression analysis over the entire dataset. private void performRAOverEntireDataset(){ // cely vzorek regression = new SimpleRegression(); addDataSet(10,dataSet.size()); intercept = regression.getIntercept(); slope = regression.getSlope(); r = regression.getR(); rSquare = regression.getRSquare(); p = regression.getSignificance(); }
map.put("slope", regression.getSlope()); map.put("intercept", regression.getIntercept()); map.put("R", regression.getR()); map.put("N", regression.getN()); map.put("RSquared", regression.getRSquare());
/** * Computes regression with the given data set values. */ public void run(){ regression = new SimpleRegression(); addDataSet(); slope = regression.getSlope(); r = regression.getR(); rSquare = regression.getRSquare(); p = regression.getSignificance(); issueType = analyzeResults(); if(!PerformanceIssueType.OK.equals(issueType)){ if(PerformanceIssueType.DEGRADATION.equals(issueType)) degradation = true; if(PerformanceIssueType.REGULAR_SPIKES.equals(issueType)) regularSpikes = true; if(PerformanceIssueType.TRAFIC_SPIKE.equals(issueType)) trafficSpike = true; } System.out.println("."); System.out.println("' slope result is '" + slope + "'."); System.out.println("' R is '" + r + "'."); System.out.println("' R square is '" + rSquare + "'."); System.out.println("' significance is '" + p + "'."); }
@Override LR.ModelResult asResult() { LR.ModelResult r = new LR.ModelResult(name, framework, hasConstant(), getNumVars(), state, getNTrain(), getNTest()); if (state != State.created) { List<Double> params = new ArrayList<>(); params.add(R.getIntercept()); params.add(R.getSlope()); r.withTrainInfo("parameters", params, "RSquared", R.getRSquare(), "significance", R.getSignificance(), "slope confidence interval", R.getSlopeConfidenceInterval(), "intercept std error", R.getInterceptStdErr(), "slope std error", R.getSlopeStdErr(), "SSE", R.getSumSquaredErrors(), "MSE", R.getMeanSquareError(), "correlation", R.getR(), "SSR", R.getRegressionSumSquares(), "SST", R.getTotalSumSquares()); } if (tester.isReady()) r.withTestInfo(tester.getStatistics()); return r; }
public double getR() { return regressionChosen.getR(); }
/** * Computes the Pearson's product-moment correlation coefficient between two arrays. * * <p>Throws MathIllegalArgumentException if the arrays do not have the same length * or their common length is less than 2. Returns {@code NaN} if either of the arrays * has zero variance (i.e., if one of the arrays does not contain at least two distinct * values).</p> * * @param xArray first data array * @param yArray second data array * @return Returns Pearson's correlation coefficient for the two arrays * @throws DimensionMismatchException if the arrays lengths do not match * @throws MathIllegalArgumentException if there is insufficient data */ public double correlation(final double[] xArray, final double[] yArray) { SimpleRegression regression = new SimpleRegression(); if (xArray.length != yArray.length) { throw new DimensionMismatchException(xArray.length, yArray.length); } else if (xArray.length < 2) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); } else { for(int i=0; i<xArray.length; i++) { regression.addData(xArray[i], yArray[i]); } return regression.getR(); } }
r = regression.getR(); rSquare = regression.getRSquare(); t = regression.getSlope()/regression.getSlopeStdErr();
/** * Computes the Pearson's product-moment correlation coefficient between two arrays. * * <p>Throws MathIllegalArgumentException if the arrays do not have the same length * or their common length is less than 2. Returns {@code NaN} if either of the arrays * has zero variance (i.e., if one of the arrays does not contain at least two distinct * values).</p> * * @param xArray first data array * @param yArray second data array * @return Returns Pearson's correlation coefficient for the two arrays * @throws DimensionMismatchException if the arrays lengths do not match * @throws MathIllegalArgumentException if there is insufficient data */ public double correlation(final double[] xArray, final double[] yArray) { SimpleRegression regression = new SimpleRegression(); if (xArray.length != yArray.length) { throw new DimensionMismatchException(xArray.length, yArray.length); } else if (xArray.length < 2) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2); } else { for(int i=0; i<xArray.length; i++) { regression.addData(xArray[i], yArray[i]); } return regression.getR(); } }
@Override public void run() throws NullContextException { final Logger logger = new Logger(context()); logger.log("\n*** Comparing", profile1.identifier(), "vs", profile2 .identifier(), "***"); logger.log("KS-test: " + getKStest()); logger.log("Reg R: " + regression.getR()); logger.log("Reg R^2: " + regression.getRSquare()); }
public static double correlation(IDoubleVector x, IDoubleVector y) { final int len = x.getLength(); if (len != y.getLength()) { throw new AdeCoreIllegalArgumentException("Mismatching lengths"); } if (len < 2) { throw new AdeCoreIllegalArgumentException("Vectors must have length >=2"); } final SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < len; i++) { regression.addData(x.get(i), y.get(i)); } return regression.getR(); }
double currentCorrelation = correlationCalculator.getR(); correlationBuffer.set(index, 0, currentCorrelation); if (Double.isNaN(currentCorrelation))