SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Member Functions
RWLogisticFitAnalysis Class Reference

Calculates a number of goodness of fit quantities for a given RWLogisticRegression instance. More...

#include <rw/analytics/logfit.h>

Public Member Functions

 RWLogisticFitAnalysis ()
 
 RWLogisticFitAnalysis (const RWLogisticFitAnalysis &rhs)
 
 RWLogisticFitAnalysis (const RWLogisticRegression &reg)
 
 ~RWLogisticFitAnalysis ()
 
double deviance () const
 
double GStatistic () const
 
double GStatisticCriticalValue (double alpha=.05) const
 
int GStatisticDegreesOfFreedom () const
 
double GStatisticPValue () const
 
double HLStatistic () const
 
double HLStatisticCriticalValue (double alpha=.05) const
 
int HLStatisticDegreesOfFreedom () const
 
const HistogramHLStatisticOutputHistogram () const
 
const HistogramHLStatisticPosObsHistogram () const
 
double HLStatisticPValue () const
 
double logLikelihood () const
 
size_t modelOutputGroups () const
 
RWLogisticFitAnalysisoperator= (const RWLogisticFitAnalysis &rhs)
 
double PearsonStatistic () const
 
double PearsonStatisticCriticalValue (double alpha=.05) const
 
int PearsonStatisticDegreesOfFreedom () const
 
double PearsonStatisticPValue () const
 
const RWMathVec< size_t > predictorDataGroups () const
 
int regressionDegreesOfFreedom () const
 
int residualDegreesOfFreedom () const
 
void setLogisticRegression (const RWLogisticRegression &lr)
 
void setModelOutputGroups (size_t ngroups)
 
void setPredictorDataGroups (const RWMathVec< size_t > &groups)
 

Detailed Description

Given RWLogisticRegression instance, class RWLogisticFitAnalysis calculates several goodness of fit quantities, including the G-statistic, Pearson statistic, and Hosmer and Lemeshow statistic, along with their P-values and critical values. These statistics are described in the Business Analysis Module User's Guide.

Synopsis
#include <rw/stats/logregress.h>
#include <rw/stats/logfit.h>
Example
#include <rw/analytics/logregress.h>
#include <rw/analytics/logfit.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);
// Analyze the model; print out some summaries of the model's
// goodness of fit.
RWLogisticFitAnalysis logfit(model);
std::cout << "Pearson statistic: " << logfit.PearsonStatistic()
<< std::endl;
std::cout << "Pearson statistic P-value: "
<< logfit.PearsonStatisticPValue() << std::endl;
std::cout << "Pearson statistic 10% critical value: "
<< logfit.PearsonStatisticCriticalValue(0.10) << std::endl;
std::cout << "Pearson statistic degrees of freedom: "
<< logfit.PearsonStatisticDegreesOfFreedom() << std::endl;
std::cout << "Predictor data groups for Pearson statistic: "
<< logfit.predictorDataGroups() << std::endl;
std::cout << std::endl;
std::cout << "HL statistic: " << logfit.HLStatistic() << std::endl;
std::cout << "HL statistic P-value: " << logfit.HLStatisticPValue()
<< std::endl;
std::cout << "HL statistic 10% critical value: "
<< logfit.HLStatisticCriticalValue(0.10) << std::endl;
std::cout << "HL statistic degrees of freedom: "
<< logfit.HLStatisticDegreesOfFreedom() << std::endl;
std::cout << "Bin counts for predictions: "
<< logfit.HLStatisticOutputHistogram() << std::endl;
std::cout << "Bin counts for predictions associated\n"
<< "with positive observations: "
<< logfit.HLStatisticPosObsHistogram() << std::endl;
std::cout << std::std::endl;
return 0;
}

Constructor & Destructor Documentation

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( )

Constructs an empty logistic regression fit analysis object. Behavior is undefined.

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( const RWLogisticFitAnalysis rhs)

Constructs a copy of rhs.

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( const RWLogisticRegression reg)

Constructs an analysis object for the logistic regression object reg.

RWLogisticFitAnalysis::~RWLogisticFitAnalysis ( )
inline

Destructor.

Member Function Documentation

double RWLogisticFitAnalysis::deviance ( ) const
inline

Returns the deviance from the saturated model.

double RWLogisticFitAnalysis::GStatistic ( ) const
inline

Returns the G statistic value, described in the Business Analysis Module User's Guide, relative to the intercept only model.

double RWLogisticFitAnalysis::GStatisticCriticalValue ( double  alpha = .05) const
inline

Returns the critical value for the G statistic at the specified significance level.

int RWLogisticFitAnalysis::GStatisticDegreesOfFreedom ( ) const
inline

Returns the degrees of freedom for the G statistic test value.

double RWLogisticFitAnalysis::GStatisticPValue ( ) const
inline

Returns the P-value for the G statistic according to a chi-square distribution.

double RWLogisticFitAnalysis::HLStatistic ( ) const
inline

Returns the Hosmer-Lemeshow test statistic, described in the Business Analysis Module User's Guide.

double RWLogisticFitAnalysis::HLStatisticCriticalValue ( double  alpha = .05) const
inline

Returns the critical value for the Hosmer-Lemeshow statistic according to a chi-square distribution.

int RWLogisticFitAnalysis::HLStatisticDegreesOfFreedom ( ) const
inline

Returns degrees of freedom for the Hosmer-Lemeshow statistic test value.

const Histogram& RWLogisticFitAnalysis::HLStatisticOutputHistogram ( ) const
inline

Returns the histogram of model predictions used in computing the Hosmer-Lemeshow statistic. This can be used to verify the exact bin boundaries, which can be critical to the statistic's value.

const Histogram& RWLogisticFitAnalysis::HLStatisticPosObsHistogram ( ) const
inline

Returns the histogram of model predictions whose corresponding observation value is positive. Seeing this histogram can be very useful for understanding the value for the statistic.

double RWLogisticFitAnalysis::HLStatisticPValue ( ) const
inline

Returns the P-value for the Hosmer-Lemeshow statistic according to a chi-square distribution.

double RWLogisticFitAnalysis::logLikelihood ( ) const
inline

Returns log likelihood of the logistic regression model.

size_t RWLogisticFitAnalysis::modelOutputGroups ( ) const
inline

Returns the number of groups used for computing the Hosmer-Lemeshow statistic.

RWLogisticFitAnalysis& RWLogisticFitAnalysis::operator= ( const RWLogisticFitAnalysis rhs)

Sets self equal to rhs.

double RWLogisticFitAnalysis::PearsonStatistic ( ) const
inline

Returns the Pearson test statistic. See the Business Analysis Module User's Guide for more information.

double RWLogisticFitAnalysis::PearsonStatisticCriticalValue ( double  alpha = .05) const
inline

Returns the critical value for the Pearson statistic according to a chi-square distribution.

int RWLogisticFitAnalysis::PearsonStatisticDegreesOfFreedom ( ) const
inline

Returns degrees of freedom for the Pearson statistic test value.

double RWLogisticFitAnalysis::PearsonStatisticPValue ( ) const
inline

Returns the P-value for the Pearson statistic according to a chi-square distribution.

const RWMathVec<size_t> RWLogisticFitAnalysis::predictorDataGroups ( ) const
inline

Returns the grouping used for the predictor matrix during computation of a Pearson statistic.

int RWLogisticFitAnalysis::regressionDegreesOfFreedom ( ) const
inline

Returns the regression degrees of freedom for a regression model. This is defined as the number of predictor variables in the model.

int RWLogisticFitAnalysis::residualDegreesOfFreedom ( ) const
inline

Returns the residual degrees of freedom for a regression model. This is defined as the number of predictor patterns minus the number of parameters in the regression model.

void RWLogisticFitAnalysis::setLogisticRegression ( const RWLogisticRegression lr)

Specifies which regression model will be used for the fit analysis.

void RWLogisticFitAnalysis::setModelOutputGroups ( size_t  ngroups)

Sets the grouping that should be used for the model's predicted values when computing a Hosmer-Lemeshow statistic. The model's predicted values are organized into a number of equal-mass bins; the number of bins is equal to ngroups.

void RWLogisticFitAnalysis::setPredictorDataGroups ( const RWMathVec< size_t > &  groups)

Sets the grouping that should be used for the predictor matrix when computing a Pearson statistic. The length of groups should equal the number of predictor variables in the model. The element groups[k] specifies the number of equally-spaced groups to be used for predictor variable k's data. Each element of groups must have a positive (nonzero) value.

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