---
title: "The Chi-Squared Goodness-of-Fit Statistic"
canonical: "https://modelassist.epixanalytics.com/space/EA/26575333/The%20Chi-Squared%20Goodness-of-Fit%20Statistic"
format: markdown
---
The Chi-squared (c<sup>2</sup>) statistic measures how well the expected frequency of the fitted distribution compares with the observed frequency of a histogram of the observed data. The Chi-squared test makes the following assumptions:

 

1.     The observed data consists of a random sample of *n* independent data points

2.     The measurement scale can be nominal (i.e. non-numeric) or numerical

3.     The *n* data points can be arranged into histogram form with *N* non-overlapping classes or bars that cover the entire possible range of the variable.

 

The Chi-Squared statistic is calculated as follows:

 

 

![image](media://ce637be6-1fc5-4e6e-9829-d78f0bf47115)

> Macro (mathblock)

 

where *O(i)* is the observed frequency of the *i*th histogram class or bar and *E(i)* is the expected frequency from the fitted distribution of *x* values falling within the *x* range of the *i*th histogram bar. *E(i)* is calculated as:

 

![image](media://9de577b4-f02b-4210-a720-4ecce3e197b8)

> Macro (mathblock)

 

where: 

![image](media://ece54888-de38-4ad6-aa2a-3ea0414eb90f)

  > Macro (inline-media-image)

 = distribution function of the fitted distribution

             > Macro (mathinline)

 = the x-value upper bound of the i<sup>th</sup> histogram bar

             > Macro (mathinline)

= the x-value lower bound of the i<sup>th</sup> histogram bar

 

A [ChiSquared(i) distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575221/) is the sum of i independent Normal(0,1)<sup>2</sup>. The formula above is based on the idea that of a total of n observations, the number of observations Oi in some interval F(imin) to F(imax) will be:

 

![image](media://ae683632-d1bb-4d39-b3cf-ab798fdc9578)

> Macro (mathblock)

 

In n is sufficiently large, the [Binomial looks roughly Normal](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575260/):

 

 

![image](media://a503dc56-4f47-4692-ad36-36aae10b124d)

> Macro (mathblock)

 

Allowing:

![image](media://54859ded-ff3f-40bf-8d18-a0c71e4f67f9)


 

> Macro (mathblock)

 

and then rearranging, we get:

![image](media://15082005-1e16-4e90-9490-f607b5286199)


 

> Macro (mathblock)

 

Then summing this expression for all i histogram classes is equivalent to a [ChiSquared(i) distribution](https://epixanalytics.atlassian.net/wiki/spaces/EA/pages/26575221/).

 

In order for the Chi-squared GOF statistic to be robust therefore, we must have two conditions:

 

  > Macro (mathinline)
2. The Normal distribution is a good approximation to the Binomial,which happens when the Binomial probability is near 0.5 (inconsistent with first condition), or the number of trials is large (very large if the probability is very small).

 

In other words, for the Chi-squared statistic to work correctly we need a very large number of data values, and the intervals have to be selected to have a significant number in each (making the intervals equally spaced in percentile terms of the fitted distribution is ideal).

 

As Crystal Ball only takes raw data to fit to continuous distributions, to perform the Chi-Squared Goodness-of-Fit test, it will break down the distribution into areas of equal probability (e.g. make a 'histogram') and compare the number of data points within each area to the number of expected data points.

 

c2 is the most commonly used of the goodness-of-fit statistics described here. From the explanation above, you'll realize that it is very dependent on the number of bars *N* that are used. By changing the value of *N*, one can quite easily switch ranking between two distribution types. Unfortunately, there are no hard and fast rules for selecting the value of *N*. A good guide, however, is Scott's Normal Approximation which generally appears to work very well:

 

                *N* = (4*n*)<sup>2/5</sup>

 

where *n* is the number of data points.

 

 

 

 

---