SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions
RWRegression< T, S > Class Template Reference

Abstract base class that defines the interface for the regression classes. More...

#include <rw/analytics/regress.h>

Public Types

enum  InterceptOption { noIntercept, intercept, addIntercept }
 

Public Member Functions

void addInterceptParameter ()
 
void addObservation (const RWMathVec< T > &, S)
 
void addObservations (const RWGenMat< T > &, const RWMathVec< S > &)
 
void addPredictor (const RWMathVec< T > &)
 
void addPredictors (const RWGenMat< T > &)
 
const RWRegressionCalc< T, S > & calcMethod () const
 
bool fail () const
 
bool hasInterceptParameter () const
 
size_t numObservations () const
 
size_t numParameters () const
 
size_t numPredictors () const
 
const RWMathVec< S > observationVector () const
 
RWMathVec< S > observationVector ()
 
const RWMathVec< T > parameters () const
 
const RWGenMat< T > predictorMatrix () const
 
RWGenMat< T > predictorMatrix ()
 
void reCalculateParameters ()
 
const RWGenMat< T > regressionMatrix () const
 
void removeInterceptParameter ()
 
void removeObservations (size_t startingIndex, size_t numToRemove)
 
void removePredictors (size_t startingIndex, size_t numToRemove)
 
void setCalcMethod (const RWRegressionCalc< T, S > &c, bool recalculate=true)
 
void setRegressionData (const RWGenMat< T > &r, const RWMathVec< S > &o, InterceptOption interceptOpt=addIntercept)
 

Detailed Description

template<class T, class S>
class RWRegression< T, S >

The abstract base class RWRegression defines the interface for the regression classes in Linear Algebra Module. Classes derived from this class include RWLinearRegression and RWLogisticRegression.

The template parameter T specifies the datatype for elements in the predictor matrix (double), and the template parameter S specifies the datatype for elements in the observation vector (double for linear regression and bool for logistic regression).

Note
See the Reference Guide entries for RWLinearRegression and RWLogisticRegression for information about the interface.

Member Enumeration Documentation

template<class T, class S>
enum RWRegression::InterceptOption

Used at construction time to indicated the intercept option used for the model.

Enumerator
noIntercept 

no intercept.

intercept 

an intercept with an input matrix that contains a column of 1s prepended to the predictor data matrix.

addIntercept 

an intercept that does not contain a column of 1s prepended to the predictor matrix.

Member Function Documentation

template<class T, class S>
void RWRegression< T, S >::addInterceptParameter ( )

Adds an intercept parameter to the model and recalculates the parameters. If the model already has an intercept parameter, this function does nothing.

template<class T, class S>
void RWRegression< T, S >::addObservation ( const RWMathVec< T > &  ,
 
)

Appends the given row of observed predictor variable values to the predictor data matrix, appends the observation value to the observation vector, then recalculates the model parameters. The input predictor variable values should not contain a leading 1 for the intercept parameter, regardless of whether or not the model has an intercept parameter. The model accounts for a leading 1 that corresponds to the intercept parameter.

template<class T, class S>
void RWRegression< T, S >::addObservations ( const RWGenMat< T > &  ,
const RWMathVec< S > &   
)

Appends the given rows of observed predictor variable values to the predictor data matrix, appends the observation values to the observation vector, then recalculates the model parameters. The input predictor variable values should not contain a leading 1 for the intercept parameter, regardless of whether or not the model has an intercept parameter. The model accounts for any leading 1s that correspond to the intercept parameter.

template<class T, class S>
void RWRegression< T, S >::addPredictor ( const RWMathVec< T > &  )

Appends the given column of predictor values to the predictor data matrix and recalculates the regression.

template<class T, class S>
void RWRegression< T, S >::addPredictors ( const RWGenMat< T > &  )

Appends the given columns of predictor values to the predictor data matrix and recalculates the regression.

template<class T, class S>
const RWRegressionCalc<T, S>& RWRegression< T, S >::calcMethod ( ) const
inline

Returns the calculation method currently in use.

template<class T, class S>
bool RWRegression< T, S >::fail ( ) const
inline

Returns true if the most recent parameter calculation fails. Returns false if the calculation is successful.

template<class T, class S>
bool RWRegression< T, S >::hasInterceptParameter ( ) const
inline

Returns true if the model has an intercept parameter, otherwise returns false.

template<class T, class S>
size_t RWRegression< T, S >::numObservations ( ) const
inline

Returns the length, n, of the vector input response vector, \(\mathbf{Y}\)

template<class T, class S>
size_t RWRegression< T, S >::numParameters ( ) const
inline

Returns the number of parameters being estimated. If the model contains an intercept parameter, this is the same as the number of predictor variables plus 1.

template<class T, class S>
size_t RWRegression< T, S >::numPredictors ( ) const
inline

Returns the number of predictor variables in the model. If the model contains an intercept parameter, this is 1 less than the number of parameters. If the model does not contain an intercept parameter, this is the same as the number of parameters.

template<class T, class S>
const RWMathVec<S> RWRegression< T, S >::observationVector ( ) const
inline

Returns the current observation vector, \(\mathbf{Y}\)

template<class T, class S>
RWMathVec<S> RWRegression< T, S >::observationVector ( )
inline

Non-const version of the observationVector() function. May be used to modify \(\mathbf{Y}\)

template<class T, class S>
const RWMathVec<T> RWRegression< T, S >::parameters ( ) const
inline

Returns \(\hat{\boldsymbol{\beta}}\) , the vector of estimated parameter values.

template<class T, class S>
const RWGenMat<T> RWRegression< T, S >::predictorMatrix ( ) const
inline

Returns the predictor data matrix, \(\mathbf{R}\) as defined in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide. If the model does not have an intercept parameter, this method is the same as the regressionMatrix() method. If the model does contain an intercept parameter, be aware that the first column of the returned matrix contains the values for the first predictor variable, not the column of 1s associated with the intercept parameter.

template<class T, class S>
RWGenMat<T> RWRegression< T, S >::predictorMatrix ( )
inline

Non-const version of the predictorMatrix() function. May be used to modify the contents of the predictor data matrix, \(\mathbf{R}\) If the model does not have an intercept parameter, this method is the same as the regressionMatrix() method. If the model does contain an intercept parameter, be aware that the first column of the returned matrix contains the values for the first predictor variable, not the column of 1s associated with the intercept parameter.

template<class T, class S>
void RWRegression< T, S >::reCalculateParameters ( )

Recalculates the regression parameters. Should be called only if you modify the regression data through the methods observationVector() or predictorMatrix().

template<class T, class S>
const RWGenMat<T> RWRegression< T, S >::regressionMatrix ( ) const
inline

Returns regression matrix \(\mathbf{X}\) as defined in Section 3.2, "Multiple Linear Regression," in the Business Analysis Module User's Guide. Note that if the model does not contain an intercept parameter, this method returns the same matrix as the predictorMatrix() method.

template<class T, class S>
void RWRegression< T, S >::removeInterceptParameter ( )

Removes the intercept parameter from the model and recalculates the parameters. If the model currently has no intercept parameter, this function does nothing.

template<class T, class S>
void RWRegression< T, S >::removeObservations ( size_t  startingIndex,
size_t  numToRemove 
)

Removes numToRemove rows from the predictor data matrix beginning with row startingIndex, removes the corresponding elements from the observation vector, then recalculates the regression. The first row has index 0.

template<class T, class S>
void RWRegression< T, S >::removePredictors ( size_t  startingIndex,
size_t  numToRemove 
)

Removes numToRemove columns from the predictor data matrix beginning with column startingIndex, then recalculates the regression. The first column has an index of 0. Note that an index of 0 refers to the first predictor variable and not to the intercept parameter, if the model contains one.

template<class T, class S>
void RWRegression< T, S >::setCalcMethod ( const RWRegressionCalc< T, S > &  c,
bool  recalculate = true 
)

Sets the regression calculation object that is used for computing model parameters to c. Recalculates the model parameters if recalculate is true.

template<class T, class S>
void RWRegression< T, S >::setRegressionData ( const RWGenMat< T > &  r,
const RWMathVec< S > &  o,
InterceptOption  interceptOpt = addIntercept 
)
inline

Sets the predictor matrix, observation vector, and intercept option to the specified values.

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