Computing ordinary least squares regression
The OLSMultipleLinearRegression provides Ordinary Least Squares Regression to fit the linear model Y=X*b+u. Here, Y is an n-vector regress, and X is a [n,k] matrix, where k columns are called regressors, b is k-vector of regression parameters, and u is an n-vector of error terms or residuals.
How to do it...
Create a method that takes a two-dimensional
doublearray and a one-dimensionaldoublearray:public void calculateOlsRegression(double[][] x, double[] y){Create an OLS regression object and add the data points x and y:
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression(); regression.newSampleData(y, x);Calculate various regression parameters and diagnostics using the following methods in the
OLSMultipleLinearRegressionclass. The usage of these information depends on your task in hand. Finally, close the method:double[] beta = regression.estimateRegressionParameters...