SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWLogisticRegression Class Reference

Performs basic logistic regression on a matrix of predictor variables and a vector of observations. More...

#include <rw/analytics/logregress.h>

Inheritance diagram for RWLogisticRegression:
RWRegression< double, bool >

Public Member Functions

 RWLogisticRegression ()
 
 RWLogisticRegression (const RWGenMat< double > predictorData, const RWMathVec< bool > obsVector, const RWRegressionCalc< double, bool > &calcObject, InterceptOption interceptOpt=addIntercept)
 
 RWLogisticRegression (const RWGenMat< double > predictorData, const RWMathVec< bool > obsVector, InterceptOption interceptOpt=addIntercept)
 
 RWLogisticRegression (const RWLogisticRegression &rhs)
 
RWLogisticRegressionoperator= (const RWLogisticRegression &rhs)
 
RWGenMat< double > paramDispersionMatrix () const
 
RWTValVector< RWLogisticRegressionParamparameterEstimates () const
 
RWMathVec< double > predictedProbSuccess () const
 
RWMathVec< double > predictedProbSuccess (const RWGenMat< double > &m) const
 
double predictedProbSuccess (const RWMathVec< double > &v) const
 
RWMathVec< double > residuals () const
 
RWMathVec< double > variance () const
 
- Public Member Functions inherited from RWRegression< double, bool >
void addInterceptParameter ()
 
void addObservation (const RWMathVec< double > &, bool)
 
void addObservations (const RWGenMat< double > &, const RWMathVec< bool > &)
 
void addPredictor (const RWMathVec< double > &)
 
void addPredictors (const RWGenMat< double > &)
 
const RWRegressionCalc< double, bool > & calcMethod () const
 
bool fail () const
 
bool hasInterceptParameter () const
 
size_t numObservations () const
 
size_t numParameters () const
 
size_t numPredictors () const
 
RWMathVec< bool > observationVector ()
 
const RWMathVec< bool > observationVector () const
 
const RWMathVec< double > parameters () const
 
RWGenMat< double > predictorMatrix ()
 
const RWGenMat< double > predictorMatrix () const
 
void reCalculateParameters ()
 
const RWGenMat< double > regressionMatrix () const
 
void removeInterceptParameter ()
 
void removeObservations (size_t startingIndex, size_t numToRemove)
 
void removePredictors (size_t startingIndex, size_t numToRemove)
 
void setCalcMethod (const RWRegressionCalc< double, bool > &c, bool recalculate=true)
 
void setRegressionData (const RWGenMat< double > &r, const RWMathVec< bool > &o, InterceptOption interceptOpt=addIntercept)
 

Additional Inherited Members

- Public Types inherited from RWRegression< double, bool >
enum  InterceptOption
 

Detailed Description

RWLogisticRegression is the class for performing basic logistic regression, described in the Business Analysis Module User's Guide. RWLogisticRegression receives data input in the form of a matrix of values for the predictor variables, and a vector of values for the observations. In addition, an intercept option must be specified. The interception option is an enumeration type defined in the RWRegression class. It can have three possible values:

  • intercept - The regression model contains an intercept parameter, and the input matrix of predictor variable values contains a leading column of 1s corresponding to the intercept parameter.
  • noIntercept - The regression model does not contain an intercept parameter.
  • addIntercept - The regression model has an intercept parameter, but it is not represented in the input predictor data matrix as a leading column of 1s. In this case, the RWLogisticRegression class prepends a column of 1s to the input predictor data matrix to obtain the full regression matrix.

For a more detailed discussion of the intercept option, see the Business Analysis Module User's Guide.

Synopsis
#include <rw/analytics/logregress.h>
A templatized general matrix class.
Definition genmat.h:741
Performs basic logistic regression on a matrix of predictor variables and a vector of observations.
Definition logregress.h:82
A templatized vector class.
Definition mathvec.h:667
Example
#include <rw/analytics/logregress.h>
#include <iostream>
int main() {
RWGenMat<double> predData = "5x2 [1 234 2 431 3 333 4 654 5 788]";
obsData[0] = obsData[3] = obsData[4] = true;
obsData[1] = obsData[2] = false;
// Create a logistic regression object.
RWLogisticRegression model(predData, obsData);
if (model.fail()) {
std::cout << "Parameter calculation failed" << std::endl;
} else {
// Print parameters from the full model.
std::cout << "Model parameters: " << model.parameters() << std::endl;
}
return 0;
}
@ rwUninitialized
Definition defs.h:105

Constructor & Destructor Documentation

◆ RWLogisticRegression() [1/4]

RWLogisticRegression::RWLogisticRegression ( )
inline

Constructs an empty logistic regression object. Behavior is undefined.

◆ RWLogisticRegression() [2/4]

RWLogisticRegression::RWLogisticRegression ( const RWLogisticRegression & rhs)
inline

Constructs a copy of rhs.

◆ RWLogisticRegression() [3/4]

RWLogisticRegression::RWLogisticRegression ( const RWGenMat< double > predictorData,
const RWMathVec< bool > obsVector,
InterceptOption interceptOpt = addIntercept )
inline

Constructs a regression object with predictor matrix predictorData and observation vector obsVector. The interceptOpt parameter indicates whether or not the model contains an intercept parameter. The default parameter calculation method is iterative least squares.

◆ RWLogisticRegression() [4/4]

RWLogisticRegression::RWLogisticRegression ( const RWGenMat< double > predictorData,
const RWMathVec< bool > obsVector,
const RWRegressionCalc< double, bool > & calcObject,
InterceptOption interceptOpt = addIntercept )
inline

Constructs a regression object with predictor matrix predictorData and observation vector obsVector. The interceptOpt parameter indicates whether or not the model contains an intercept parameter. Parameter calculation is done using the method calcObject. Methods currently available include iterative least squares and an algorithm based on the Levenberg-Marquardt approach.

Member Function Documentation

◆ operator=()

RWLogisticRegression & RWLogisticRegression::operator= ( const RWLogisticRegression & rhs)
inline

Assigns rhs to self.

◆ paramDispersionMatrix()

RWGenMat< double > RWLogisticRegression::paramDispersionMatrix ( ) const

Returns the parameter variance-covariance matrix.

◆ parameterEstimates()

RWTValVector< RWLogisticRegressionParam > RWLogisticRegression::parameterEstimates ( ) const

Returns the list of estimated parameters.

◆ predictedProbSuccess() [1/3]

RWMathVec< double > RWLogisticRegression::predictedProbSuccess ( ) const

Returns the model's predicted success probabilities for the input predictor data.

◆ predictedProbSuccess() [2/3]

RWMathVec< double > RWLogisticRegression::predictedProbSuccess ( const RWGenMat< double > & m) const

Returns the model's predicted success probabilities for the input predictor data.

◆ predictedProbSuccess() [3/3]

double RWLogisticRegression::predictedProbSuccess ( const RWMathVec< double > & v) const

Returns the success probabilities predicted for the predictor data used to construct the model.

◆ residuals()

RWMathVec< double > RWLogisticRegression::residuals ( ) const

Returns the vector of differences between the probabilities of success predicted by the model and those predicted by the observed value.

◆ variance()

RWMathVec< double > RWLogisticRegression::variance ( ) const
inline

Returns the variance estimate for each observation. If \( p_i \) is the predicted probability of success for the ith observation, then \( var(i) = p_i * (1-p_i) \).

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