Computing generalized least squares regression
In this recipe, we will see another variant of least squares regression named generalized least squares regression. GLSMultipleLinearRegression
implements Generalized Least Squares to fit the linear model Y=X*b+u.
How to do it...
Create a method that takes a two-dimensional double array, a one-dimensional double array, and a two-dimensional double array for the regression's omega parameter:
public void calculateGlsRegression(double[][] x, double[] y, double[][] omega){
Create a GLS regression object, the data points, and the omega parameter:
GLSMultipleLinearRegression regression = new GLSMultipleLinearRegression(); regression.newSampleData(y, x, omega);
Using the methods of the
GLSMultipleLinearRegression
class, compute various statistics of the regression and finally, close the method:double[] beta = regression.estimateRegressionParameters(); ...