>
>#include <rw/stats/logregress.h> #include <rw/stats/logfit.h> RWLogisticRegression lr; RWLogisticFitAnalysis logfit(lr);
Given an instance of the class RWLogisticRegression, 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 Section 3.3.3.
>#include <rw/analytics/logregress.h> #include <rw/analytics/logfit.h> #include <rw/rstream.h> int main() { RWGenMat<double> predData = "5x2 [1 234 2 431 3 333 4 654 5 788]"; RWMathVec<RWBoolean> obsData(5, rwUninitialized ); 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); cout << "Pearson statistic: " << logfit.PearsonStatistic() << endl; cout << "Pearson statistic P-value: " << logfit.PearsonStatisticPValue() << endl; cout << "Pearson statistic 10% critical value: " << logfit.PearsonStatisticCriticalValue(0.10) << endl; cout << "Pearson statistic degrees of freedom: " << logfit.PearsonStatisticDegreesOfFreedom() << endl; cout << "Predictor data groups for Pearson statistic: " << logfit.predictorDataGroups() << endl; cout << endl; cout << "HL statistic: " << logfit.HLStatistic() << endl; cout << "HL statistic P-value: " << logfit.HLStatisticPValue() << endl; cout << "HL statistic 10% critical value: " << logfit.HLStatisticCriticalValue(0.10) << endl; cout << "HL statistic degrees of freedom: " << logfit.HLStatisticDegreesOfFreedom() << endl; cout << "Bin counts for predictions: " << logfit.HLStatisticOutputHistogram() << endl; cout << "Bin counts for predictions associated \n with positive observations: " << logfit.HLStatisticPosObsHistogram() << endl; cout << endl; return 0; }>
RWLogisticFitAnalysis();
Constructs an empty logistic regression fit analysis object. Behavior is undefined.
RWLogisticFitAnalysis(const RWLogisticFitAnalysis& t);
Constructs a copy of t.
RWLogisticFitAnalysis(const RWLogisticRegression& lr);
Constructs an analysis object for the logistic regression object lr.
double deviance() const;
Returns the deviance from the saturated model.
double GStatistic() const;
Returns the G statistic value, described in Section 3.3.3.1, relative to the intercept only model.
double GStatisticCriticalValue(double alpha=.05) const;
Returns the critical value for the G statistic at the specified significance level.
int GStatisticDegreesOfFreedom() const;
Returns the degrees of freedom for the G statistic test value.
double GStatisticPValue() const;
Returns the P-value for the G statistic according to a chi-square distribution.
double HLStatistic() const;
Returns the Hosmer-Lemeshow test statistic, described in Section 3.3.3.3.
double HLStatisticCriticalValue(double alpha=.05) const;
Returns the critical value for the Hosmer-Lemeshow statistic according to a chi-square distribution.
int HLStatisticDegreesOfFreedom() const;
Returns degrees of freedom for the Hosmer-Lemeshow statistic test value.
const Histogram& HLStatisticOutputHistogram() const;
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& HLStatisticPosObsHistogram() const;
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 HLStatisticPValue() const;
Returns the P-value for the Hosmer-Lemeshow statistic according to a chi-square distribution.
double logLikelihood() const;
Returns log likelihood of the logistic regression model.
size_t modelOutputGroups() const;
Returns the number of groups used for computing the Hosmer-Lemeshow statistic.
double PearsonStatistic() const;
Returns the Pearson test statistic. See Section 3.3.3.2 for more information.
double PearsonStatisticCriticalValue(double alpha=.05) const;
Returns the critical value for the Pearson statistic according to a chi-square distribution.
int PearsonStatisticDegreesOfFreedom() const;
Returns degrees of freedom for the Pearson statistic test value.
double PearsonStatisticPValue() const;
Returns the P-value for the Pearson statistic according to a chi-square distribution.
const RWMathVec<size_t> predictorDataGroups() const;
Returns the grouping used for the predictor matrix during computation of a Pearson statistic.
int regressionDegreesOfFreedom() const;
Returns the regression degrees of freedom for a regression model. This is defined as the number of predictor variables in the model.
int residualDegreesOfFreedom() const;
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 setLogisticRegression(const RWLogisticRegression & lr);
Specifies which regression model will be used for the fit analysis.
void setModelOutputGroups(size_t groups);
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 groups.
void 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.
RWLogisticFitAnalysis& operator=(const RWLogisticFitAnalysis& lf);
Sets self equal to lf.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.