rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWLinearRegression Class Reference
[Regression]

Constructs a linear regression model from a matrix of predictor variable data and a vector of observation variable data. More...

#include <rw/analytics/linregress.h>

Inheritance diagram for RWLinearRegression:
RWRegression< double, double >

List of all members.

Public Member Functions

 RWLinearRegression ()
 RWLinearRegression (const RWLinearRegression &lr)
 RWLinearRegression (const RWGenMat< double > &predictorData, const RWMathVec< double > &obsVec, InterceptOption interceptOpt=addIntercept)
 RWLinearRegression (const RWGenMat< double > &predictorData, const RWMathVec< double > &obsVec, const RWRegressionCalc< double, double > &c, InterceptOption interceptOpt=addIntercept)
RWMathVec< double > predictedObservation (const RWGenMat< double > &m) const
double predictedObservation (const RWMathVec< double > &v) const
RWMathVec< double > residuals () const
double variance () const
RWGenMat< double > paramDispersionMatrix () const
RWTValVector
< RWLinearRegressionParam
parameterEstimates () const
RWInterval< double > predictionInterval (const RWMathVec< double > &x, double alpha) const
RWLinearRegressionoperator= (const RWLinearRegression &lr)

Detailed Description

Class RWLinearRegression constructs a linear regression model from a matrix of predictor variable data and a vector of observation variable data. The class implements multiple linear regression as described in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide.

The class makes several assumptions regarding the predictor matrix and observation vector passed to the constructor. Columns in the predictor matrix correspond to predictor variables, and the matrix rows correspond to predictor patterns. Both predictor matrix and observation vector are double precision, and the length of the observation vector should equal the number of rows in the predictor matrix. The user has the choice of specifying whether the model has an intercept parameter, and if so, whether the provided predictor matrix includes a column of 1s for the intercept parameter.

You can choose from among several regression parameter calculation methods, including QR decomposition without pivoting (RWLeastSqQRCalc), QR decomposition with pivoting (RWLeastSqQRPvtCalc), and singular value decomposition (RWLeastSqSVDCalc). The calculation method is set by passing a calculation class instance to the method setCalcMethod(). You have the option of providing your own implementation derived from the class RWRegressionCalc<double,double> .

Once the linear regression object is constructed, it can be queried for specific values related to linear regression, such as model parameters, model predictions, prediction intervals, and confidence intervals for parameter values. The model may also be updated by changing values in the predictor matrix and observation vector, or by changing the calculation method.

Synopsis

 #include <rw/math/mathvec.h>
 #include <rw/math/genmat.h>
 #include <rw/analytics/linregress.h>

 RWGenMat<double> predMat;
 RWMathVecd<double> obsVec;
 RWLinearRegression lr(predMat, obsVec);

Examples

This simple example prints out the calculated parameter values for a linear regression model.

 #include <rw/analytics/linregress.h>

 int main() {
  RWGenMat<double> predictorMatrix =
                        "5x2 [1.2 2.1 8 7 3 3.2 6.4 4.6 2 2.3]";
  RWMathVec<double> observationVector = "[2.5 3.7 1.4 2.3 5.6]";

  RWLinearRegression lr(predictorMatrix, observationVector);

  // Print out the model parameters if the calculation succeeded.
  if ( !lr.fail() )
   cout << "Model parameters: " << lr.parameters() << endl;
  else
   cout << "Parameter calculation failed." << endl;
  return 0;
 }

Constructor & Destructor Documentation

RWLinearRegression::RWLinearRegression (  )  [inline]

Constructs an empty linear regression object. Behavior is undefined.

RWLinearRegression::RWLinearRegression ( const RWLinearRegression lr  )  [inline]

Constructs a copy of lr.

RWLinearRegression::RWLinearRegression ( const RWGenMat< double > &  predictorData,
const RWMathVec< double > &  obsVec,
InterceptOption  interceptOpt = addIntercept 
) [inline]

Constructs a regression object from the given predictor data matrix and observation vector. The intercept option parameter indicates whether or not the model contains an intercept parameter. The parameter calculation is done using the QR decomposition method.

RWLinearRegression::RWLinearRegression ( const RWGenMat< double > &  predictorData,
const RWMathVec< double > &  obsVec,
const RWRegressionCalc< double, double > &  c,
InterceptOption  interceptOpt = addIntercept 
) [inline]

Constructs a regression object from the given predictor data matrix and observation vector. The intercept option parameter indicates whether or not the model contains an intercept parameter. The parameter calculation is done using the method defined by the regression calculation object c.


Member Function Documentation

RWLinearRegression& RWLinearRegression::operator= ( const RWLinearRegression lr  )  [inline]

Copies the contents of lr to self.

RWGenMat<double> RWLinearRegression::paramDispersionMatrix (  )  const

Returns the dispersion matrix for the parameter estimates. This is also known as the parameter variance-covariance matrix.

RWTValVector<RWLinearRegressionParam> RWLinearRegression::parameterEstimates (  )  const

Returns the list of estimated parameters.

double RWLinearRegression::predictedObservation ( const RWMathVec< double > &  v  )  const

Returns the predicted response, $\mathbf{\hat{Y}}$ , as defined in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide.

RWMathVec<double> RWLinearRegression::predictedObservation ( const RWGenMat< double > &  m  )  const

Returns the predicted response vector, $\mathbf{\hat{Y}}$ , as defined in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide.

RWInterval<double> RWLinearRegression::predictionInterval ( const RWMathVec< double > &  x,
double  alpha 
) const

Returns an alpha level confidence interval for the response predicted by the regression at x as defined in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide.

RWMathVec<double> RWLinearRegression::residuals (  )  const

Returns the vector of residuals $\mathbf{e = Y - \hat{Y}}$ See Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide.

double RWLinearRegression::variance (  )  const

Returns the variance for the model. This is the residual sum of squares divided by its degrees of freedom.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.