Exemplo n.º 1
0
  /**
   * Get the mean square error of the y value with respect to the fitted line. The square root of
   * this number gives an indication of the uncertainty in y value estimates under certain
   * assumptions about the error distribution.
   *
   * @return the mean square error of the y value with respect to the fitted line
   */
  public synchronized double getMeanSquareOrdinateError() {
    performFitIfNeeded();

    final double slope = _slope;
    final double intercept = _intercept;
    final double xyMean = _xyStats.mean();
    final double xxMean = _xxStats.mean();
    final double yyMean = _yyStats.mean();

    return yyMean - 2 * slope * xyMean + slope * slope * xxMean - intercept * intercept;
  }
Exemplo n.º 2
0
  /** Calculate the slope and intercept. */
  protected synchronized void performFit() {
    final double xMean = _xStats.mean();
    final double yMean = _yStats.mean();
    final double xyMean = _xyStats.mean();
    final double xxMean = _xxStats.mean();
    final double yyMean = _yyStats.mean();

    _slope = (xyMean - xMean * yMean) / (xxMean - xMean * xMean);
    _intercept = yMean - _slope * xMean;
    _correlationCoefficient =
        (xyMean - xMean * yMean) / Math.sqrt((xxMean - xMean * xMean) * (yyMean - yMean * yMean));

    _needsUpdate = false;
  }
Exemplo n.º 3
0
  /**
   * Generate a string representation of the linear equation.
   *
   * @return a string representation of the linear equation
   */
  public synchronized String toString() {
    performFitIfNeeded();

    StringBuffer buffer = new StringBuffer();
    buffer.append("y = " + _slope + " * x + " + _intercept);
    buffer.append("\n" + "r = " + _correlationCoefficient);
    buffer.append("\n" + "<x> = " + _xStats.mean() + ", <y> = " + _yStats.mean());
    buffer.append(
        "\n"
            + "<xx> = "
            + _xxStats.mean()
            + ", <xy> = "
            + _xyStats.mean()
            + ", <yy> = "
            + _yyStats.mean());
    return buffer.toString();
  }