/** * Total variance in target attribute * @param residuals error * @param targetAttribute data for target attribute * @return Total variance in target attribute */ public static double ssTotal(double[] residuals, double[] targetAttribute) { return ssReg(residuals, targetAttribute) + ssError(residuals, targetAttribute); }
/** * Returns the correlation coefficient of two double vectors. * * @param residuals residuals * @param targetAttribute target attribute vector * * @return the correlation coefficient or r */ public static double correlation(double[] residuals, double targetAttribute[]) { double[] predictedValues = new double[residuals.length]; for (int i = 0; i < predictedValues.length; i++) { predictedValues[i] = targetAttribute[i] - residuals[i]; } double ssErr = ssError(predictedValues, targetAttribute); double total = ssTotal(residuals, targetAttribute); return 1 - (ssErr / total); }//end correlation