Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Business Analysis Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWLinearRegression


RWLinearRegression RWRegression<double,double>

Local Index

Members

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, "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.

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;
bool 
fail() const;
bool 
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, bool 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 DocumentContentsIndex pageNext file

© 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.