SourcePro® API Reference Guide

 
List of all members | Public Member Functions

Calculates linear regression parameters using QR decomposition. More...

#include <rw/analytics/lsqqr.h>

Inheritance diagram for RWLeastSqQRCalc:
RWRegressionCalc< double, double >

Public Member Functions

 RWLeastSqQRCalc ()
 
virtual void addPredToBaseCalc (const RWAddPredictors< double, double > &dataChange)
 
virtual void calc (const RWGenMat< double > &r, const RWMathVec< double > &o)
 
virtual RWRegressionCalc< double, double > * clone () const
 
virtual bool fail () const
 
virtual RWCString name () const
 
virtual RWMathVec< double > parameters () const
 
virtual void removePredFromBaseCalc (const RWRemovePredictors< double, double > &dataChange)
 
virtual void setBaseCalc (const RWGenMat< double > &, const RWMathVec< double > &)
 
- Public Member Functions inherited from RWRegressionCalc< double, double >
 RWRegressionCalc ()
 
virtual void addObsToBaseCalc (const RWAddObservations< double, double > &dataChange)
 
virtual void removeObsFromBaseCalc (const RWRemoveObservations< double, double > &dataChange)
 

Detailed Description

Class RWLeastSqQRCalc implements the calculation of linear regression parameters using QR decomposition, as described in Section 5.5.1.1, "RWLeastSqQRCalc," in the Business Analysis Module User's Guide.

Synopsis
#include <rw/analytics/lsqqr.h>
Example
#include <rw/analytics/lsqqr.h>
#include <rw/rstream.h> // Handles proper inclusion of iostream.
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]";
qr.calc(predictorMatrix, observationVector);
if ( !qr.fail() )
cout << "Model parameters: " << qr.parameters() << endl;
else
cout << "Parameter calculation failed." << endl;
return 0;
}

Constructor & Destructor Documentation

RWLeastSqQRCalc::RWLeastSqQRCalc ( )

Constructs an empty RWLeastSqQRCalc object.

Member Function Documentation

virtual void RWLeastSqQRCalc::addPredToBaseCalc ( const RWAddPredictors< double, double > &  dataChange)
virtual

Expands the regression model to include new predictor variables. This method has the option of using results from the base calculation to calculate the coefficients for the larger predictor set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable contains the data for the added predictor variables. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented from RWRegressionCalc< double, double >.

virtual void RWLeastSqQRCalc::calc ( const RWGenMat< double > &  r,
const RWMathVec< double > &  o 
)
virtual

Calculates the parameters for the regression model. Invoking this method does not affect the state of any existing base calculation.

Implements RWRegressionCalc< double, double >.

virtual RWRegressionCalc<double, double>* RWLeastSqQRCalc::clone ( ) const
inlinevirtual

Allocates and creates a clone, or exact copy, of the current instance, and returns a pointer to the copy. Caller is responsible for deleting the returned object.

Implements RWRegressionCalc< double, double >.

virtual bool RWLeastSqQRCalc::fail ( ) const
inlinevirtual

Returns true if the calculation failed.

Implements RWRegressionCalc< double, double >.

virtual RWCString RWLeastSqQRCalc::name ( ) const
inlinevirtual

Returns the name of the calculation method.

Implements RWRegressionCalc< double, double >.

virtual RWMathVec<double> RWLeastSqQRCalc::parameters ( ) const
virtual

Returns the parameters from the last calculation performed. If the calculation failed, and this method is called, an exception of type RWInternalErr is thrown.

Implements RWRegressionCalc< double, double >.

virtual void RWLeastSqQRCalc::removePredFromBaseCalc ( const RWRemovePredictors< double, double > &  dataChange)
virtual

Shrinks the regression model to exclude previously used predictor variables. This method offers the option of using results from the base calculation to calculate the coefficients for the smaller predictor set. Consequently, this method can be called only when a base calculation has been set using setBaseCalc(). The input variable indicates the indices of the columns to be removed from the regression matrix used in the base calculation. The default implementation simply recalculates the parameters from scratch using the calc() method.

Reimplemented from RWRegressionCalc< double, double >.

virtual void RWLeastSqQRCalc::setBaseCalc ( const RWGenMat< double > &  r,
const RWMathVec< double > &  o 
)
virtual

Calculates the coefficients for the input regression data and sets the base calculation to this calculation. Deriving classes need not override this method if they do not store base calculation results. The default implementation calls the calc() method.

Reimplemented from RWRegressionCalc< double, double >.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.