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...

  1. Create a method that takes a two-dimensional double array and a one-dimensional double array:
            public void calculateOlsRegression(double[][] x, double[] y){ 
    
  2. Create an OLS regression object and add the data points x and y:
            OLSMultipleLinearRegression regression = new 
              OLSMultipleLinearRegression(); 
            regression.newSampleData(y, x); 
    
  3. Calculate various regression parameters and diagnostics using the following ...

Get Java Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.