Map<ModelCoefficient, Double> coefficientFromAvailableData = new HashMap<>(_coefficients); OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); regression.setNoIntercept(true); boolean ignoreLeaderBytesOutRate = !isLeaderBytesInAndOutRatioDiverseEnough(); double[][] sampleBytesRateData = aggregateSampleBytesRateData(ignoreLeaderBytesOutRate);
regression.setNoIntercept(true); boolean ignoreLeaderBytesOut = !isLeaderBytesInAndOutRatioDiverseEnough(); regression.newSampleData(aggregateSampleCpuUtilData(),
ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
reg.setNoIntercept(true);
OlsLRModel(String model, boolean intercept, int numVars) { super(model, Framework.OLS); R = new OLSMultipleLinearRegression(); R.setNoIntercept(!intercept); numObs = 0; this.numVars = numVars; } @Override
double[] y = {-0.48812477, 0.33458213, -0.52754476, -0.79863471, -0.68544309, -0.12970239, 0.02355622, -0.31890850, 0.34725819, 0.08108851}; double[][] x = {{1,0}, {0,0}, {1,0}, {2,1}, {0,1}, {0,0}, {1,0}, {0,0}, {1,0}, {0,0}}; double[][] xb = {{1,0,0}, {0,0,0}, {1,0,0}, {2,1,2}, {0,1,0}, {0,0,0}, {1,0,0}, {0,0,0}, {1,0,0}, {0,0,0}}; OLSMultipleLinearRegression regr = new OLSMultipleLinearRegression(); int degreesOfFreedomA = y.length - (x[0].length); // no + 1 int degreesOfFreedomB = y.length - (xb[0].length); // no + 1 regr.setNoIntercept(true); regr.newSampleData(y, x); double sumOfSquaresNoInterceptA = regr.calculateResidualSumOfSquares(); regr.newSampleData(y, xb); double sumOfSquaresNoInterceptB = regr.calculateResidualSumOfSquares(); double MSE = sumOfSquaresNoInterceptB / degreesOfFreedomB; System.out.printf("RSS no intercept: %f\n",sumOfSquaresNoInterceptB); int degreesOfFreedomDifference = Math.abs(degreesOfFreedomB - degreesOfFreedomA); double MSEdiff = Math.abs((sumOfSquaresNoInterceptB - sumOfSquaresNoInterceptA) / (degreesOfFreedomDifference)); double Fval = MSEdiff / MSE; FDistribution Fdist = new FDistribution(degreesOfFreedomDifference, degreesOfFreedomB); double pval = 1 - Fdist.cumulative(Fval); System.out.printf("pval without intercept: %f",pval);
final OLSMultipleLinearRegression regression2 = new OLSMultipleLinearRegression(); double[] y = { 4, 8, 13, 18 }; double[][] x2 = { { 1, 1, 1 }, { 1, 2, 4 }, { 1, 3, 9 }, { 1, 4, 16 }, }; regression2.newSampleData(y, x2); regression2.setNoIntercept(true); regression2.newSampleData(y, x2); double[] beta = regression2.estimateRegressionParameters(); for (double d : beta) { System.out.println("D: " + d); }
@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)); }
@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)); }
@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)); }