## What Is a Chi-Square Statistic?

A chi-square (χ2) statistic is a test that measures how expectations compare to actual observed data (or model results). The data used in calculating a chi-square statistic must be random, raw, mutually exclusive, drawn from independent variables, and drawn from a large enough sample. For example, the results of tossing a coin 100 times meet these criteria.

Chi-square tests are often used in hypothesis testing.

## The Formula for Chi-Square Is

﻿\begin{aligned}&\chi^2_c = \sum \frac{(O_i - E_i)^2}{E_i} \\&\textbf{where:}\\&c=\text{Degrees of freedom}\\&O=\text{Observed value(s)}\\&E=\text{Expected value(s)}\end{aligned}﻿

## What Does a Chi-Square Statistic Tell You?

There are two main kinds of chi-square tests: the test of independence, which asks a question of relationship, such as, "Is there a relationship between gender and SAT scores?"; and the goodness-of-fit test, which asks something like "If a coin is tossed 100 times, will it come up heads 50 times and tails 50 times?"

For these tests, degrees of freedom are utilized to determine if a certain null hypothesis can be rejected based on the total number of variables and samples within the experiment.

For example, when considering students and course choice, a sample size of 30 or 40 students is likely not large enough to generate significant data. Getting the same or similar results from a study using a sample size of 400 or 500 students is more valid.

In another example, consider tossing a coin 100 times. The expected result of tossing a fair coin 100 times is that heads will come up 50 times and tails will come up 50 times. The actual result might be that heads will come up 45 times and tails will come up 55 times. The chi-square statistic shows any discrepancies between the expected results and the actual results.

## Example of a Chi-Squared Test

Imagine a random poll was taken across 2,000 different voters, both male and female. The people who responded were classified by their gender and whether they were republican, democrat, or independent. Imagine a grid with the columns labeled republican, democrat, and independent, and two rows labeled male and female. Assume the data from the 2,000 respondents is as follows:

The first step to calculate the chi squared statistic is to find the expected frequencies. These are calculated for each "cell" in the grid. Since there are two categories of gender and three categories of political view, there are six total expected frequencies. The formula for the expected frequency is:

﻿\begin{aligned}&E(r,c)=\frac{n(r)\times c(r)}{n}\\&\textbf{where:}\\&r=\text{Row in question}\\&c=\text{Column in question}\\&r=\text{Corresponding total}\end{aligned}﻿

In this example, the expected frequencies are:

﻿\begin{aligned}&E(1,1)=\frac{900\times800}{2,000}=360\\&E(1,2)=\frac{900\times800}{2,000}=360\\&E(1,3)=\frac{200\times800}{2,000}=80\\&E(2,1)=\frac{900\times1,200}{2,000}=540\\&E(2,2)=\frac{900\times1,200}{2,000}=540\\&E(2,3)=\frac{200\times1,200}{2,000}=120\end{aligned}﻿

Next, these are used values to calculate the chi squared statistic using the following formula:

﻿\begin{aligned}&\text{Chi-squared} = \sum \frac{[O(r, c) - E(r, c)]^2 }{E(r, c)} \\&\textbf{where:}\\&O(r, c)=\text{Observed data for the given row and column}\end{aligned}﻿

In this example, the expression for each observed value is:

﻿\begin{aligned}&O(1,1)=\frac{400-360}{360}^2=4.44\\&O(1,2)=\frac{300\times360}{360}^2=10\\&O(1,3)=\frac{100-80}{80}^2=5\\&O(2,1)=\frac{500-540}{540}^2=2.96\\&O(2,2)=\frac{600-540}{540}^2=6.67\\&O(2,3)=\frac{100-120}{120}^2=3.33\end{aligned}﻿

The chi-squared statistic then equals the sum of these value, or 32.41. We can then look at a chi-squared statistic table to see, given the degrees of freedom in our set-up, if the result is statistically significant or not.