JMSLTM Numerical Library 3.0

com.imsl.stat
Class LinearRegression

java.lang.Object
  extended bycom.imsl.stat.LinearRegression
All Implemented Interfaces:
Cloneable, Serializable

public class LinearRegression
extends Object
implements Serializable, Cloneable

Fits a multiple linear regression model with or without an intercept. If the constructor argument hasIntercept is true, the multiple linear regression model is

y_i  = beta _0  + beta _1 x_{i1}  + beta _2 
  x_{i2}  + , ldots  + beta _k x_{ik}+ varepsilon _i ,,,,, 
  i = 1,,2,, ldots ,,n


where the observed values of the y_i's constitute the responses or values of the dependent variable, the x_{i1}'s, x_{i2}'s, ldots, x_{ik}'s are the settings of the independent variables, beta_0,beta_1, ldots, 
  beta_k are the regression coefficients, and the e_i's are independently distributed normal errors each with mean zero and variance sigma^2. If hasIntercept is false, beta_0 is not included in the model.

LinearRegression computes estimates of the regression coefficients by minimizing the sum of squares of the deviations of the observed response y_i from the fitted response

hat y_i


for the observations. This minimum sum of squares (the error sum of squares) is in the ANOVA output and denoted by

{rm SSE} = sumlimits_{i=1}^n w_i (y_i-hat y_i)^2


In addition, the total sum of squares is output in the ANOVA table. For the case, hasIntercept is true; the total sum of squares is the sum of squares of the deviations of y_i from its mean

bar y


--the so-called corrected total sum of squares; it is denoted by

{rm SST} = sumlimits_{i=1}^n  w_i (y_i - bar y)^2


For the case hasIntercept is false, the total sum of squares is the sum of squares of y_i--the so-called uncorrected total sum of squares; it is denoted by

{rm SST} = sumlimits_{i=1}^n y_i^2


See Draper and Smith (1981) for a good general treatment of the multiple linear regression model, its analysis, and many examples.

In order to compute a least-squares solution, LinearRegression performs an orthogonal reduction of the matrix of regressors to upper triangular form. Givens rotations are used to reduce the matrix. This method has the advantage that the loss of accuracy resulting from forming the crossproduct matrix used in the normal equations is avoided, while not requiring the storage of the full matrix of regressors. The method is described by Lawson and Hanson, pages 207-212.

See Also:
Example, Serialized Form

Nested Class Summary
 class LinearRegression.CoefficientTTests
          CoefficientTTests contains statistics related to the regression coefficients.
 
Constructor Summary
LinearRegression(int nVariables, boolean hasIntercept)
          Constructs a new linear regression object.
 
Method Summary
 ANOVA getANOVA()
          Get an analysis of variance table and related statistics.
 double[] getCoefficients()
          Returns the regression coefficients.
 LinearRegression.CoefficientTTests getCoefficientTTests()
          Returns statistics relating to the regression coefficients.
 double[][] getR()
          Returns a copy of the R matrix.
 int getRank()
          Returns the rank of the matrix.
 void update(double[][] x, double[] y)
          Updates the regression object with a new set of observations.
 void update(double[][] x, double[] y, double[] w)
          Updates the regression object with a new set of observations and weights.
 void update(double[] x, double y)
          Updates the regression object with a new observation.
 void update(double[] x, double y, double w)
          Updates the regression object with a new observation and weight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearRegression

public LinearRegression(int nVariables,
                        boolean hasIntercept)
Constructs a new linear regression object.

Parameters:
nVariables - int number of variables in the regression
hasIntercept - int boolean which indicates whether or not an intercept is in this regression model
Method Detail

update

public void update(double[] x,
                   double y)
Updates the regression object with a new observation.

Parameters:
x - a double array containing the independent (explanatory) variables. Its length must be equal to the number of variables set in the constructor.
y - a double representing the dependent (response) variable

update

public void update(double[] x,
                   double y,
                   double w)
Updates the regression object with a new observation and weight.

Parameters:
x - a double array containing the independent (explanatory) variables. Its length must be equal to the number of variables set in the constructor.
y - a double representing the dependent (response) variable
w - a double representing the weight

update

public void update(double[][] x,
                   double[] y)
Updates the regression object with a new set of observations.

Parameters:
x - a double matrix containing the independent (explanatory) variables. The number of rows in x must equal the length of y and the number of columns must be equal to the number of variables set in the constructor.
y - a double array containing the dependent (response) variables.

update

public void update(double[][] x,
                   double[] y,
                   double[] w)
Updates the regression object with a new set of observations and weights.

Parameters:
x - a double matrix containing the independent (explanatory) variables. The number of rows in x must equal the length of y and the number of columns must be equal to the number of variables set in the constructor.
y - a double array containing the dependent (response) variables.
w - a double array representing the weights

getCoefficients

public double[] getCoefficients()
Returns the regression coefficients.

Returns:
A double array containing the regression coefficients. If hasIntercept is false its length is equal to the number of variables. If hasIntercept is true then its length is the number of variables plus one and the 0-th entry is the value of the intercept.
Throws:
SingularMatrixException - is thrown when the regression matrix is singular.

getR

public double[][] getR()
Returns a copy of the R matrix. R is the upper triangular matrix containing the R matrix from a QR decomposition of the matrix of regressors.

Returns:
a double matrix containing a copy of the R matrix

getANOVA

public ANOVA getANOVA()
Get an analysis of variance table and related statistics.

Returns:
an ANOVA table and related statistics

getRank

public int getRank()
Returns the rank of the matrix.

Returns:
the int rank of the matrix

getCoefficientTTests

public LinearRegression.CoefficientTTests getCoefficientTTests()
Returns statistics relating to the regression coefficients.


JMSLTM Numerical Library 3.0

Copyright 1970-2004 Visual Numerics, Inc.
Built November 5 2004.