SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWLinRegModelSelector< F > Class Template Reference

Encapsulates four different model selection algorithms for linear regression: forward, backward, stepwise, and exhaustive. More...

#include <rw/analytics/lnrmodsel.h>

Inheritance diagram for RWLinRegModelSelector< F >:
RWRegressionModelSelector< double, double, F >

Public Member Functions

 RWLinRegModelSelector ()
 
 RWLinRegModelSelector (const RWLinearRegression &reg, RWSearchMethod s)
 
 RWLinRegModelSelector (const RWLinRegModelSelector< F > &ms)
 
RWLinRegModelSelector< F > & operator= (const RWLinRegModelSelector< F > &ms)
 
- Public Member Functions inherited from RWRegressionModelSelector< double, double, F >
 RWRegressionModelSelector ()
 
 RWRegressionModelSelector (const RWRegression< double, double > &reg, RWSearchMethod s)
 
 RWRegressionModelSelector (const RWRegressionModelSelector< double, double, F > &rhs)
 
virtual ~RWRegressionModelSelector ()
 
const RWRegressionCalc< double, double > & calcMethod () const
 
double evalFunctionForSelected () const
 
bool fail () const
 
RWCString failMessage () const
 
RWRegressionModelSelector< double, double, F > & operator= (const RWRegressionModelSelector< double, double, F > &rhs)
 
RWSearchMethod searchMethod () const
 
const RWBitVecselectedParamIndices () const
 
const RWBitVecselectedParamIndices (RWSearchMethod s)
 
const RWMathVec< double > & selectedParamValues () const
 
void setCalcMethod (const RWRegressionCalc< double, double > &c)
 
void setRegression (const RWRegression< double, double > &r)
 
void setSearchMethod (RWSearchMethod s)
 

Detailed Description

template<class F>
class RWLinRegModelSelector< F >

Class RWLinRegModelSelector encapsulates four different model selection algorithms for linear regression. The algorithms are forward, backward, stepwise, and exhaustive. Refer to Chapter 4, "Model Selection," in the Business Analysis Module User's Guide for more details about model selection and differences between the four algorithms.

The template parameter F determines the model evaluation criterion object used during model selection search. In the synopsis above, the F statistic is used as the model evaluation criterion. You can substitute your own model evaluation object, provided that it defines the operator() method in the same way as the class RWLinRegressFStatistic.

An instance of the class RWLinRegModelSelector is constructed with a linear regression and a choice of model selection algorithm. At any time, the user may change the selection algorithm or the specific linear regression model. The class provides results of model selection search, including the indices of the predictor variables that were selected, the parameter values for the selected indices, and the model evaluation criterion for the selected predictor variables.

To be used as a template parameter for RWLinRegModelSelector, a class F must implement the following interface:

class F {
double operator()(const RWGenMat<double>& regressionMatrix,
const RWMathVec<double>& observationVector,
const RWMathVec<double>& parameterEstimates);
}
A templatized general matrix class.
Definition genmat.h:741
A templatized vector class.
Definition mathvec.h:667
Synopsis
#include <rw/analytics/ffunc.h>
#include <rw/analytics/linregress.h>
#include <rw/analytics/lnrmodsel.h>
#include <rw/math/genmat.h>
#include <rw/math/mathvec.h>
RWGenMat<double> predictorMatrix;
RWMathVec<double> observationVector;
RWLinearRegression lr(predictorMatrix, observationVector);
Encapsulates four different model selection algorithms for linear regression: forward,...
Definition lnrmodsel.h:132
Constructs a linear regression model from a matrix of predictor variable data and a vector of observa...
Definition linregress.h:96
@ rwForwardSelection
Definition regsel.h:26
Example

The following example performs forward selection search on a linear regression model, where the model evaluation criterion is the F statistic.

#include <rw/analytics/ffunc.h>
#include <rw/analytics/linregress.h>
#include <rw/analytics/lnrmodsel.h>
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]";
RWLinearRegression lr(predictorMatrix, observationVector);
if (!selector.fail()) {
cout << "selected indices: " << selector.selectedParamIndices()
<< endl;
cout << "selected parameter values: "
<< selector.selectedParamValues() << endl;
cout << "model criterion value: "
<< selector.evalFunctionForSelected() << endl;
} else {
cout << "search failed: " << selector.failMessage() << endl;
}
return 0;
}

Constructor & Destructor Documentation

◆ RWLinRegModelSelector() [1/3]

template<class F >
RWLinRegModelSelector< F >::RWLinRegModelSelector ( )
inline

Default constructor. Behavior undefined.

◆ RWLinRegModelSelector() [2/3]

template<class F >
RWLinRegModelSelector< F >::RWLinRegModelSelector ( const RWLinRegModelSelector< F > & ms)
inline

Copy constructor.

◆ RWLinRegModelSelector() [3/3]

template<class F >
RWLinRegModelSelector< F >::RWLinRegModelSelector ( const RWLinearRegression & reg,
RWSearchMethod s )
inline

Constructs a model selector using the search method s.

Member Function Documentation

◆ operator=()

template<class F >
RWLinRegModelSelector< F > & RWLinRegModelSelector< F >::operator= ( const RWLinRegModelSelector< F > & ms)
inline

Assignment operator.

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