Business Analysis Module User’s Guide : Chapter 5 Using the Classes : Parameter Calculation Classes
Parameter Calculation Classes
The parameter calculation method used for models is determined by classes that derive from the abstract base class RWRegressionCalc. The parameter calculation method used by a particular regression object may be specified by providing an instance of a class derived from RWRegressionCalc to the regression object at construction time, or through the regression class member function setCalcMethod(). If you do not specify a calculation method at construction time, a default method is provided.
Encapsulating parameter calculations in a class yields two benefits:
Calculation methods can be changed at runtime. For example, if you choose a calculation method that is fast but fails on a particular set of data, you can switch to a slower, more robust method.
You can use your own calculation method by deriving a class from RWRegressionCalc and providing the calculation method.
Here is an example of how to switch calculation methods at runtime:
 
RWMathVec<double> observations;
RWGenMat<double> predictorMatrix;
.
.
.
// Construct a linear regression object using the default
// calculation method class RWLeastSqQRCalc. This
// method is fast, but will fail if the regression matrix does
// not have full rank.
 
RWLinearRegression lr( predictorMatrix, observations);
if ( lr.fail() )
{
// Try the more robust, but slower QR with pivoting method:
lr.setCalcMethod(RWLeastSqQRPvtCalc());
if ( lr.fail() )
{
// Matrix must have a column of 0s or something.
// Deal with the error.
cerr << “Parameter calculation failed for input data.” << endl;
}
else
{
cout << “Parameters calculated using the QR with pivoting
method: “ << lr.parameters() << endl;
}
}
else
{
cout << “Parameters calculated using the QR method: “ << lr.parameters() << endl;
}
.
.
.
All parameter calculation classes have a member function, called name(), which returns a string identifying the calculation method. In the convention used by the Business Analysis Module, name() returns the class static variable methodName. For example, if you want to know whether a particular logistic regression object uses the Levenberg-Marquardt calculation method, you would proceed as follows:
 
.
.
.
RWMathVec<double> observations;
RWGenMat<double> predictorMatrix;
.
.
.
RWLogisticRegression lr(predictorMatrix, observations);
.
.
.
// Check which calculation method is being used by the regression.
if ( lr.calcMethod().name() == RWLogisticLevenbergMarquardt::methodName )
{
cout << “using Levenberg-Marquardt calculation method” << endl;
}
else
{
cout << “using something else” << endl;
}
.
.
.