next up previous index
Next: Why It Works Up: How to ask questions Previous: Degrees of Freedom   Index

Click for printer friendely version of this HowTo

Chi-Square Goodness of Fit Test

In the study of genetics one frequently runs into situations that are resolved using what is called a Chi-Square Goodness of Fit Test. This is a test that is particularly adept at determining how well a model fits observed data. It allows us to evaluate how ``close'' the observed values are to those which would be expected given the model in question. Here is a brief explanation of how and why the Chi-Square Goodness of Fit Test is effective in these situations.3.2

In general, the chi-square test statistic has the form:

$\displaystyle \chi^2 = \sum \frac{(\textrm{observed} - \textrm{expected})^2}{\textrm{expected}},$ (3.7.1)

and if $ \chi^2$ is large, than the model is a poor fit to the data. Before we get into the details of the theory behind this statistic, let's begin with a short example of how it is used.

A Fair Coin?no_title

Example (A Fair Coin?)  

Imagine trying to determine if a coin is fair or not. If the coin is fair, than the probability of getting heads is $ p_1 = 0.5$ and the probability of getting tails is $ p_2 = 0.5$, other wise $ p_1 \ne 0.5$ and $ p_2 \ne 0.5$. It is important to note that since the coin has only two sides, $ p_2 = 1 - p_1$. While this equality may seem obvious, it will be useful when we are determining the degrees of freedom for our test. If we tossed the coin 100 times, we would expect to get heads $ 100 \times 0.5 = 50$ times. We know, however, that even though the probability of getting heads is $ 0.5$, there is a chance that we might get a few more or a few less than 50 heads in 100 tosses. The question is, how much variation in the number of heads will we allow before we are confident in rejecting the hypothesis that $ p = 0.5$? This is where the Chi-Square Goodness of Fit comes in handy.

In order to test the hypothesis that the coin is fair, you toss the coin 100 times and observe that it landed on heads 38 times. From this data alone, we are able to determine that the coin must have landed on tails 62 times and we note this in Table 3.7.1.

Table 3.7.1: Both observed and expected results of 100 coin tosses.
  Observed Expected
Heads 38 50
Tails 62 50

With this data in our hands, we can compute a $ \chi^2$ test statistic and use it to determine the fairness of the coin. That is,

$\displaystyle \chi^2$ $\displaystyle = \frac{(38 - 50)^2}{50} + \frac{(62 - 50)^2}{50}$    
  $\displaystyle =\frac{144}{50} + \frac{144}{50}$    
  $\displaystyle =5.76.$    

We can now see where this values lies in a $ \chi^2$ distribution. If it is in the tail of the distribution, then the probability of getting 37 heads using a fair coin would appear to be a very rare event. If it is in the middle of the distribution, then it might be quite common to obtain 38 heads in 100 tosses from a fair coin.

In order to examine our value in the context of a $ \chi^2$ distribution we must specify which one by determining its degrees of freedom. We calculate the total degrees of freedom by looking at the total number of parameters in our model, 2 ($ p_1$ and $ p_2$), and subtracting 1 because $ p_2$ is not independent from $ p_1$ since $ p_2 = 1 - p_1$. Thus, we must see how much area is under the curve of a $ \chi ^2_1$ distribution (the subscript 1 indicates the degrees of freedom) from 5.75 to $ \infty$. We can do this easily using Octave:

octave:1> 1 - chisquare_cdf(5.76, 1)
ans = 0.016395
The probability that a value of 5.76 or larger would come from the $ \chi ^2_1$ distribution is less 0.016395, which is very small (see Figure 3.7.1). Much smaller than the standard 5 percent used as a cutoff to determine whether we should accept 5.76 as coming from the $ \chi ^2_1$ distribution. Thus, we will reject the hypothesis that this coin is fair.
Figure: The area under the $ \chi ^2_1$ graph that represents the p-value, the probability our hypothesis that the coin is far is correct. Since the p-value/area is so small (1.6 percent) we will reject our hypothesis.
$ \vert\boldsymbol{\vert}$

next up previous index
Next: Why It Works Up: How to ask questions Previous: Degrees of Freedom   Index

Click for printer friendely version of this HowTo

Frank Starmer 2004-05-19