SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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/logfit.h>
#include <rw/stats/logregress.h>
Calculates a number of goodness of fit quantities for a given RWLogisticRegression instance.
Definition logfit.h:89
Performs basic logistic regression on a matrix of predictor variables and a vector of observations.
Definition logregress.h:82
Example
#include <rw/analytics/logfit.h>
#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);
// 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;
}
A templatized general matrix class.
Definition genmat.h:741
A templatized vector class.
Definition mathvec.h:667
@ rwUninitialized
Definition defs.h:105

Constructor & Destructor Documentation

◆ RWLogisticFitAnalysis() [1/3]

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( )

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

◆ RWLogisticFitAnalysis() [2/3]

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( const RWLogisticFitAnalysis & rhs)

Constructs a copy of rhs.

◆ RWLogisticFitAnalysis() [3/3]

RWLogisticFitAnalysis::RWLogisticFitAnalysis ( const RWLogisticRegression & reg)

Constructs an analysis object for the logistic regression object reg.

◆ ~RWLogisticFitAnalysis()

RWLogisticFitAnalysis::~RWLogisticFitAnalysis ( )
inline

Destructor.

Member Function Documentation

◆ deviance()

double RWLogisticFitAnalysis::deviance ( ) const
inline

Returns the deviance from the saturated model.

◆ GStatistic()

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.

◆ GStatisticCriticalValue()

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

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

◆ GStatisticDegreesOfFreedom()

int RWLogisticFitAnalysis::GStatisticDegreesOfFreedom ( ) const
inline

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

◆ GStatisticPValue()

double RWLogisticFitAnalysis::GStatisticPValue ( ) const
inline

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

◆ HLStatistic()

double RWLogisticFitAnalysis::HLStatistic ( ) const
inline

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

◆ HLStatisticCriticalValue()

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

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

◆ HLStatisticDegreesOfFreedom()

int RWLogisticFitAnalysis::HLStatisticDegreesOfFreedom ( ) const
inline

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

◆ HLStatisticOutputHistogram()

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.

◆ HLStatisticPosObsHistogram()

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.

◆ HLStatisticPValue()

double RWLogisticFitAnalysis::HLStatisticPValue ( ) const
inline

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

◆ logLikelihood()

double RWLogisticFitAnalysis::logLikelihood ( ) const
inline

Returns log likelihood of the logistic regression model.

◆ modelOutputGroups()

size_t RWLogisticFitAnalysis::modelOutputGroups ( ) const
inline

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

◆ operator=()

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

Sets self equal to rhs.

◆ PearsonStatistic()

double RWLogisticFitAnalysis::PearsonStatistic ( ) const
inline

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

◆ PearsonStatisticCriticalValue()

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

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

◆ PearsonStatisticDegreesOfFreedom()

int RWLogisticFitAnalysis::PearsonStatisticDegreesOfFreedom ( ) const
inline

Returns degrees of freedom for the Pearson statistic test value.

◆ PearsonStatisticPValue()

double RWLogisticFitAnalysis::PearsonStatisticPValue ( ) const
inline

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

◆ predictorDataGroups()

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

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

◆ regressionDegreesOfFreedom()

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.

◆ residualDegreesOfFreedom()

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.

◆ setLogisticRegression()

void RWLogisticFitAnalysis::setLogisticRegression ( const RWLogisticRegression & lr)

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

◆ setModelOutputGroups()

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.

◆ setPredictorDataGroups()

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