package com.imsl.test.example.stat; import com.imsl.stat.*; /** *
* Computes a simple linear regression model.
* * The coefficients of a simple linear regression model, without an intercept, * are computed. * * * * @see Code * @see Output */ public class LinearRegressionEx1 { public static void main(String args[]) { // y = 4*x0 + 3*x1 LinearRegression r = new LinearRegression(2, false); double c[] = {4, 3}; double x[][] = {{1, 5}, {0, 2}, {-1, 4}}; r.update(x[0], 1 * c[0] + 5 * c[1]); r.update(x[1], 0 * c[0] + 2 * c[1]); r.update(x[2], -1 * c[0] + 4 * c[1]); double coef[] = r.getCoefficients(); System.out.println("The computed regression coefficients are {" + coef[0] + ", " + coef[1] + "}"); } }