Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWLinearRegression


RWLinearRegression RWRegression<double,double>

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

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);

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.

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.

Example

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

Public Enumeration

enum InterceptOption {noIntercept, intercept, addIntercept}

Public Constructors

RWLinearRegression();
RWLinearRegression(const RWLinearRegression& d);
RWLinearRegression(const RWGenMat<double>& predictorData, 
                   const RWMathVec<double>& observationVector,
                   InterceptOption intOpt=addIntercept);
RWLinearRegression(const RWGenMat<double>& predictorData,
                   const RWMathVec<double>& observationVector,
                   const RWRegressionCalc<double,double>& c, 
                   InterceptOption intOpt=addIntercept);

Public Member Functions

void 
addInterceptParameter();
void 
addObservation(const RWMathVec<double>&
               observedPredictorValues, double observation);
void 
addObservations(const RWGenMat<double>&
                observedPredictorValues,
                const RWMathVec<double>& observations);
void 
addPredictor(const RWMathVec<double>& predictorValues);
void 
addPredictors(const RWGenMat<double>& predictorValues);
const RWRegressionCalc<double,double>& 
calcMethod() const;
RWBoolean 
fail() const;
RWBoolean 
hasInterceptParameter() const;
size_t 
numObservations() const;
size_t 
numParameters() const;
size_t 
numPredictors() const;
const RWMathVec<double> 
observationVector() const;
RWMathVec<double> 
observationVector();
RWGenMat<double> 
paramDispersionMatrix() const;
RWTValSlist< RWLinearRegressionParam > 
parameterEstimates() const;
const RWMathVec<double> 
parameters() const;
double 
predictedObservation(const RWMathVec<double>& x ) const;
RWMathVec<double> 
predictedObservation(const RWGenMat<double>& r) const;
RWInterval<double> 
predictionInterval(const RWMathVec<double>& x,
                   double alpha) const;
const RWGenMat<double> 
predictorMatrix() const;
RWGenMat<double> 
predictorMatrix();
void 
reCalculateParameters();
const RWGenMat<double> 
regressionMatrix() const;
void 
removeInterceptParameter();
void 
removeObservations(size_t startingIndex, size_t numToRemove);
void 
removePredictors(size_t startingIndex, size_t numToRemove);
RWMathVec<double> 
residuals() const;
void 
setCalcMethod(const RWRegressionCalc<double,double>& c, 
              RWBoolean recalculate=TRUE);
void
setRegressionData(const RWGenMat<double>& predictorData, 
                  const RWMathVec<double>& observationVector,
                  InterceptOption intOpt=addIntercept);
double 
variance() const;

Public Member Operator

RWLinearRegression&   
operator=(const RWLinearRegression& r);


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.