SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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
 
RWMathVec< S > observationVector ()
 
const RWMathVec< S > observationVector () const
 
const RWMathVec< T > parameters () const
 
RWGenMat< T > predictorMatrix ()
 
const RWGenMat< T > predictorMatrix () const
 
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

◆ InterceptOption

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

◆ addInterceptParameter()

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.

◆ addObservation()

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

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.

◆ addObservations()

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.

◆ addPredictor()

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.

◆ addPredictors()

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.

◆ calcMethod()

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

Returns the calculation method currently in use.

◆ fail()

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.

◆ hasInterceptParameter()

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

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

◆ numObservations()

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}\)

◆ numParameters()

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.

◆ numPredictors()

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.

◆ observationVector() [1/2]

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}\)

◆ observationVector() [2/2]

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

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

◆ parameters()

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

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

◆ predictorMatrix() [1/2]

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.

◆ predictorMatrix() [2/2]

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.

◆ reCalculateParameters()

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

◆ regressionMatrix()

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.

◆ removeInterceptParameter()

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.

◆ removeObservations()

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.

◆ removePredictors()

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.

◆ setCalcMethod()

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.

◆ setRegressionData()

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