# How to Chi-Square Test ••• Design Pics/Design Pics/Getty Images

Experiments test predictions. These predictions are often numerical, meaning that, as scientists gather data, they expect the numbers to break down in a certain way. Real-world data rarely match exactly the predictions scientists make, so scientists need a test to tell them whether the difference between observed and expected numbers is because of random chance, or because of some unforeseen factor that will force the scientist to adjust the underlying theory. A chi-square test is a statistical tool that scientists use for this purpose.

## The Type of Data Required

You need categorical data to use a chi-square test. An example of categorical data is the number of people who answered a question "yes" versus the number of people who answered the question "no" (two categories), or the numbers of frogs in a population that are green, yellow or gray (three categories). You cannot use a chi-square test on continuous data, such as might be collected from a survey asking people how tall they are. From such a survey, you would get a broad range of heights. However, if you divided the heights into categories such as "under 6 feet tall" and "6 feet tall and over," you could then use a chi-square test on the data.

## The Goodness-of-Fit Test

A goodness-of-fit test is a common, and perhaps the simplest, test performed using the chi-square statistic. In a goodness-of-fit test, the scientist makes a specific prediction about the numbers she expects to see in each category of her data. She then collects real-world data -- called observed data -- and uses the chi-square test to see whether the observed data match her expectations.

For example, imagine a biologist is studying the inheritance patterns in a species of frog. Among 100 offspring of a set of frog parents, the biologist's genetic model leads her to expect 25 yellow offspring, 50 green offspring and 25 gray offspring. What she actually observes is 20 yellow offspring, 52 green offspring and 28 gray offspring. Is her prediction supported or is her genetic model incorrect? She can use a chi-square test to find out.

## Calculating the Chi-Square Statistic

Begin calculating the chi-square statistic by subtracting each expected value from its corresponding observed value and squaring each result. The calculation for the example of the frog offspring would look like this:

yellow = (20 - 25)^2 = 25 green = (52 - 50)^2 = 4 gray = (28 - 25)^2 = 9

Now divide each result by its corresponding expected value.

yellow = 25 ÷ 25 = 1 green = 4 ­÷ 50 = 0.08 gray = 9 ÷ 25 = 0.36