NMath Stats User's Guide

TOC | Previous | Next | Index

7.4 Goodness of Fit (.NET, C#, CSharp, VB, Visual Basic, F#)

Class LogisticRegressionFitAnalysis calculates goodness of fit statistics for a logistic regression model.

Code Example – C# logistic regression

var fit = new 
  LogisticRegressionFitAnalysis<NewtonRaphsonParameterCalc>( lr );

Provided properties access the model statistics:

GStatistic gets the G statistic for the model. The G statistic is

   G = -2*ln[(likelihood without the variables)/
             (likelihood with the variables)]

GStatisticPValue gets the p-value for the G statistic.

LogLikelihood gets the log likelihood for the model.

For instance:

Code Example – C# logistic regression

Console.WriteLine( "Log likelihood: " + fit.LogLikelihood );
Console.WriteLine( "G-statistic: " + fit.GStatistic );
Console.WriteLine( "G-statistic P-value: " + 
  fit.GStatisticPValue );

Two methods on LogisticRegressionFitAnalysis provide access to additional statistics:

PearsonStatistic() computes the Pearson chi-square statistic, and related quantities from the Pearson residuals, to determine if two observations share the same covariate pattern.

HLStatistic() calculates the Hosmer Lemeshow statistic for the model. This test assesses whether or not the observed event rates match expected event rates in subgroups of the model population.

For instance, this code calculates the Hosmer Lemeshow statistic using 10 groups.

Code Example – C# logistic regression

var hosmerLemeshowStat = fit.HLStatistic(10);