Java Code Examples for org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression#estimateErrorVariance()

The following examples show how to use org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression#estimateErrorVariance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Forecast.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    final OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
    last_error_rate = ols.estimateErrorVariance();
    Log.d(TAG, getClass().getSimpleName() + " Forecast Error rate: errorvar:"
            + JoH.qs(last_error_rate, 4)
            + " regssionvar:" + JoH.qs(ols.estimateRegressandVariance(), 4)
            + "  stderror:" + JoH.qs(ols.estimateRegressionStandardError(), 4));
}
 
Example 2
Source File: Forecast.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    final OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
    last_error_rate = ols.estimateErrorVariance();
    Log.d(TAG, getClass().getSimpleName() + " Forecast Error rate: errorvar:"
            + JoH.qs(last_error_rate, 4)
            + " regssionvar:" + JoH.qs(ols.estimateRegressandVariance(), 4)
            + "  stderror:" + JoH.qs(ols.estimateRegressionStandardError(), 4));
}
 
Example 3
Source File: Forecast.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    final OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
    last_error_rate = ols.estimateErrorVariance();
    Log.d(TAG, getClass().getSimpleName() + " Forecast Error rate: errorvar:"
            + JoH.qs(last_error_rate, 4)
            + " regssionvar:" + JoH.qs(ols.estimateRegressandVariance(), 4)
            + "  stderror:" + JoH.qs(ols.estimateRegressionStandardError(), 4));
}
 
Example 4
Source File: Forecast.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    final OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
    last_error_rate = ols.estimateErrorVariance();
    Log.d(TAG, getClass().getSimpleName() + " Forecast Error rate: errorvar:"
            + JoH.qs(last_error_rate, 4)
            + " regssionvar:" + JoH.qs(ols.estimateRegressandVariance(), 4)
            + "  stderror:" + JoH.qs(ols.estimateRegressionStandardError(), 4));
}