# NMath User's Guide

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

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

Code Example – C# logistic regression

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

Code Example – VB logistic regression

```Dim Fit As New LogisticRegressionFitAnalysis(Of
```
```  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 );
```

Code Example – VB logistic regression

```Console.WriteLine("Log likelihood: " & Fit.LogLikelihood)
```
```Console.WriteLine("G-statistic: " & Fit.GStatistic)
```
```Console.WriteLine("G-statistic P-value: " & Fit.GStatisticPValue)
```

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);
```
```Console.WriteLine(hosmerLemeshowStat);
```

Code Example – VB logistic regression

```Dim HosmerLemeshowStat = Fit.HLStatistic(10)
```
```Console.WriteLine(HosmerLemeshowStat)
```

Top

Top