>
Data Types | |
RWSearchMethod |
Member Functions | |||
calcMethod() evalFunctionForSelected() fail() |
failMessage() operator=() searchMethod() |
selectedParamIndices() selectedParamValues() setCalcMethod() |
setRegression() setSearchMethod() |
>#include <rw/math/genmat.h> #include <rw/math/mathvec.h> #include <rw/analytics/linregress.h> #include <rw/analytics/lnrmodsel.h> #include <rw/analytics/ffunc.h> RWGenMat<double> predictorMatrix; RWMathVec<double> observationVector; RWLinearRegression lr(predictorMatrix, observationVector); RWLinRegModelSelector<RWLinRegressFStatistic>
modelSelector(lr,rwForwardSelection);
Class RWLinRegModelSelector<F> encapsulates four different model selection algorithms for linear regression. The algorithms are forward, backward, stepwise, and exhaustive selection. Refer to Chapter 4, "Model Selection," 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<F> 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 ); }>
The following example performs forward selection search on a linear regression model, where the model evaluation criterion is the F statistic.
#include <rw/analytics/linregress.h> #include <rw/analytics/lnrmodsel.h> #include <rw/analytics/ffunc.h> 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); RWLinRegModelSelector<RWLinRegressFStatistic> selector(lr, rwForwardSelection); 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; }>
RWLinRegModelSelector();
Default constructor. Behavior undefined.
RWLinRegModelSelector(const RWLinRegModelSelector<F>&);
Copy constructor.
RWLinRegModelSelector(const RWLinearRegression& reg, RWSearchMethod s);
Constructs a model selector using the search method s.
const RWRegressionCalc<double,double>& calcMethod() const;
Returns the parameter estimate calculation method currently in use by the model selector.
double evalFunctionForSelected() const;
Returns the value of the evaluation function F for the selected parameters.
RWBoolean fail() const;
Returns TRUE if the search failed.
RWCString failMessage() const;
Returns an error message if the search fails, that is, if fail() returns TRUE.
RWSearchMethod searchMethod() const;
Returns the search method currently in use by the model selector.
const RWBitVec& selectedParamIndices(RWSearchMethod s);
Returns the parameters selected by the model's selector using the search method s.
const RWBitVec& selectedParamIndices() const;
Returns the indices of the parameters selected by the currently set search calculation methods.
const RWMathVec<double>& selectedParamValues() const;
Returns the currently selected parameters.
void setCalcMethod(const RWRegressionCalc<double,double>& c);
Sets the parameter calculation method used to calculate the model parameters.
void setRegression(const RWLinearRegression&);
Sets the full regression model from which the subset of predictors is selected.
void setSearchMethod(RWSearchMethod s);
Sets the search method used.
RWLinRegModelSelector<F>& operator=(const RWLinRegModelSelector<F>& ms);
Assignment operator.
enum RWSearchMethod {rwForwardSelection, rwBackwardSelection, rwStepwiseSelection, rwExhaustiveSelection}
Designates the search method.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.