regres
Class LinearRegression

java.lang.Object
  extended by regres.LinearRegression

public class LinearRegression
extends java.lang.Object

This class implements different linear regression models, using the least squares method to estimate the regression coefficients. Given input data xi, j and response yi, we want to find coefficients βj that minimize the residuals of the form

i(yi - β0 - ∑j=1kβjxi, j)2.

Using matrix notation, one may write this equation as

minβ| Y - |2,

where the first column of X is all 1, and the L2 norm is used.

Sometimes, one wants to use a basis of general functions ψj(t) with a minimization of the form

i(yi - ∑j=1kβjψj(ti))2.

For example, we could have ψj(t) = e-λjt or some other functions. In that case, one has to choose the points ti at which to compute the basis functions, and use a method below with xi, j = ψj(ti).


Constructor Summary
LinearRegression()
           
 
Method Summary
static double[] calcCoefficients(double[][] X, double[] Y)
          Computes the regression coefficients using the least squares method.
static double[] calcCoefficients(double[] X, double[] Y)
          Computes the regression coefficients using the least squares method.
static double[] calcCoefficients0(double[][] X, double[] Y)
          Computes the regression coefficients using the least squares method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearRegression

public LinearRegression()
Method Detail

calcCoefficients

public static double[] calcCoefficients(double[] X,
                                        double[] Y)
Computes the regression coefficients using the least squares method. This is a simple linear regression with only 2 regression coefficients. The model is

y = α + βx.

Given the n data points (Xi, Yi), i = 0, 1,…,(n - 1), the method computes and returns the array [α, β].

Parameters:
X - the regressor variables
Y - the response
Returns:
the regression coefficients

calcCoefficients0

public static double[] calcCoefficients0(double[][] X,
                                         double[] Y)
Computes the regression coefficients using the least squares method. This is a model for multiple linear regression. There are k + 1 regression coefficients βj, j = 0, 1,…, k and k regressors variables xj. The model is

y = β0 + ∑j=1kβjxj.

There are n data points Yi, Xi, j, i = 0, 1,…,(n - 1), and each Xi is a k-dimensional point. Given the response Y[i] and the regressor variables X[i][j], i = 0, 1,…,(n - 1), j = 0, 1,…,(k - 1), the method computes and returns the array [β0, β1,…, βk]. Restriction: n > k + 1.

Parameters:
X - the regressor variables
Y - the response
Returns:
the regression coefficients

calcCoefficients

public static double[] calcCoefficients(double[][] X,
                                        double[] Y)
Computes the regression coefficients using the least squares method. This is a model for multiple linear regression. There are k regression coefficients βj, j = 0, 1,…,(k - 1) and k regressors variables xj. The model is

y = ∑j=0k-1βjxj.

There are n data points Yi, Xi, j, i = 0, 1,…,(n - 1), and each Xi is a k-dimensional point. Given the response Y[i] and the regressor variables X[i][j], i = 0, 1,…,(n - 1), j = 0, 1,…,(k - 1), the method computes and returns the array [β0, β1,…, βk-1]. Restriction: n > k.

Parameters:
X - the regressor variables
Y - the response
Returns:
the regression coefficients