SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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 (void) const
 
virtual bool fail (void) const
 
virtual RWCString name (void) const
 
virtual RWMathVec< double > parameters (void) 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>
Calculates linear regression parameters using QR decomposition.
Definition lsqqr.h:68
virtual void calc(const RWGenMat< double > &r, const RWMathVec< double > &o)
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;
}
A templatized general matrix class.
Definition genmat.h:741
virtual RWMathVec< double > parameters(void) const
virtual bool fail(void) const
Definition lsqqr.h:99
A templatized vector class.
Definition mathvec.h:667

Constructor & Destructor Documentation

◆ RWLeastSqQRCalc()

RWLeastSqQRCalc::RWLeastSqQRCalc ( )

Constructs an empty RWLeastSqQRCalc object.

Member Function Documentation

◆ addPredToBaseCalc()

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

◆ calc()

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

◆ clone()

virtual RWRegressionCalc< double, double > * RWLeastSqQRCalc::clone ( void ) 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 >.

◆ fail()

virtual bool RWLeastSqQRCalc::fail ( void ) const
inlinevirtual

Returns true if the calculation failed.

Implements RWRegressionCalc< double, double >.

◆ name()

virtual RWCString RWLeastSqQRCalc::name ( void ) const
inlinevirtual

Returns the name of the calculation method.

Implements RWRegressionCalc< double, double >.

◆ parameters()

virtual RWMathVec< double > RWLeastSqQRCalc::parameters ( void ) 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 >.

◆ removePredFromBaseCalc()

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

◆ setBaseCalc()

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.