Package org.jamesii.core.math

Examples of org.jamesii.core.math.Matrix


  }

  @Override
  public void setResponseVariable(List<Double> response) {
    reset();
    setY(new Matrix(response.toArray(new Double[response.size()])));
  }
View Full Code Here


  public Matrix getResiduals() {
    if (mResiduals == null) {
      if (getB() == null) {
        getCoefficients();
      }
      Matrix estimations = getX().mult(getB());
      mResiduals = getY().copy();
      mResiduals.sub(estimations);
    }
    return mResiduals.copy();
  }
View Full Code Here

      int p = getX().getColumns();

      // If there are no free degrees, there should be no error in the
      // regression.
      if (n - p == 0) {
        mStandardErrorsPerCoefficient = new Matrix(p, 1);
        mStandardErrorsPerCoefficient.flood(0.0);
        // Free the possibly huge standardErrorMatrix.
        setStandardErrorMatrix(null);
        return mStandardErrorsPerCoefficient.copy();
      }

      for (int i = 0; i < n; i++) {
        double temp = getY().getElement(i, 0);
        standardErrorSESquare += temp * temp;
      }
      for (int j = 0; j < p; j++) {
        double temp = 0.0;
        for (int i = 0; i < n; i++) {
          temp += getX().getElement(i, j) * getY().getElement(i, 0);
        }
        temp *= getB().getElement(j, 0);
        standardErrorSESquare -= temp;
      }
      standardErrorSESquare /= n - p;

      if (getStandardErrorMatrix() == null) {
        setStandardErrorMatrix(getX().transpose().mult(getX()).solve());
      }

      // Calculate standard errors.
      mStandardErrorsPerCoefficient = new Matrix(p, 1);
      for (int i = 0; i < p; i++) {
        mStandardErrorsPerCoefficient.setElement(
            i,
            0,
            Math.sqrt(standardErrorSESquare
View Full Code Here

   *          the y
   *
   * @return R?
   */
  public static double regressVariance(Matrix x, Matrix y, Matrix b) {
    Matrix bT = b.transpose();
    Matrix xT = x.transpose();
    Matrix yT = y.transpose();

    double meanY = ArithmeticMean.arithmeticMean(y.getColumn(0));
    meanY *= meanY;
    meanY *= y.getRows();

    Matrix top = bT.mult(xT).mult(y);
    Matrix bottom = yT.mult(y);

    return (top.getElement(0, 0) - meanY) / (bottom.getElement(0, 0) - meanY);
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.