Home > Knowledge Base > Statistical Analysis > Chi-Square Test: Formula, Types and Examples

Chi-Square Test: Formula, Types and Examples

Published by at July 16th, 2026 , Revised On July 16, 2026

A chi-square test compares observed data against expected values to check whether a relationship between categorical variables is real or due to chance. Its two main types are goodness of fit and test of independence, both built on the formula χ² = Σ (O − E)² ÷ E.

What is a Chi-Square Test?

The chi-square (χ²) test is a non-parametric statistical test used to analyse categorical data. It checks whether observed frequencies differ significantly from the frequencies you would expect if no pattern or relationship existed.

Researchers rely on it across dissertations, surveys and lab reports whenever variables are grouped into categories rather than measured on a continuous scale — for example gender, grade band, subject choice or yes/no survey answers.

Unlike a t-test or ANOVA, chi-square never compares group means. It works purely with counts, frequencies and proportions across defined categories, which sets it apart within the wider family of hypothesis tests.

Because it does not assume a normal distribution, chi-square suits nominal or ordinal data well. For a wider view of when to use it, see our guide to choosing the right statistical test for your project.

The Chi-Square Formula Explained

The core formula is χ² = Σ (O − E)² ÷ E, where O is the observed frequency in each category and E is the expected frequency under the null hypothesis. You sum this across every cell.

The Greek letter chi (χ) gives the test its name; squaring the difference removes negative values, so every gap between observed and expected counts adds positively to the final statistic.

A larger χ² value signals a bigger gap between what you observed and what you expected, suggesting the variables are related. A small value suggests the data fits the expected pattern closely.

Expected frequency for a contingency table cell equals (row total × column total) ÷ grand total. Get this step wrong and the whole result becomes unreliable, so check every cell twice.

Types of Chi-Square Test: Goodness of Fit and Independence

There are two common chi-square tests. The goodness of fit test checks whether one categorical variable matches an expected distribution. The test of independence checks whether two categorical variables are associated.

Goodness of fit suits questions like “do dice rolls land evenly across six faces?” Test of independence suits questions like “is study method linked to pass or fail rate?” Both use the same core formula.

Dissertations tend to use the test of independence more often than goodness of fit, since most research questions ask whether two variables — such as treatment group and outcome — are connected.

Diagram comparing chi-square goodness of fit test and chi-square test of independence

Choosing between them depends entirely on how many categorical variables your research question involves, and whether you are checking one distribution or the relationship between two separate variables.

Assumptions of the Chi-Square Test

Chi-square tests rely on a few conditions. Data must be counts or frequencies, not percentages or measurements, and each observation must fall into exactly one category.

Categories must be mutually exclusive, and observations need to be independent of one another — one participant’s response should not influence another participant’s response.

Expected cell frequencies should generally reach five or higher. Where this is not possible, consider merging categories or applying an exact test such as Fisher’s exact test instead.

How to Calculate a Chi-Square Statistic Step by Step

Every chi-square test follows the same broad process, whether you are testing one variable or two. Working through it methodically avoids the calculation errors that most often trip up students.

Step one states the null and alternative hypotheses clearly. Step two builds a table of observed frequencies, then calculates the expected frequency for each cell using the formula above.

Flowchart showing the step-by-step process for running a chi-square test

Once you have χ², compare it against the critical value from a chi-square distribution table, or read the exact p-value from software such as SPSS — see our SPSS data analysis help guide if you are new to the package.

A chi-square test behaves like a one-tailed test in practice, since squaring the differences removes direction — only large discrepancies between observed and expected counts push the statistic toward significance.

Chi-Square Test of Independence and Goodness of Fit Compared

The table below summarises the practical differences between the two tests, including the variables involved and how degrees of freedom are worked out for each.

Feature Goodness of Fit Test of Independence
Variables tested One categorical variable Two categorical variables
Null hypothesis Sample matches expected distribution No association between the variables
Typical example Are survey answers evenly split? Is smoking status linked to gender?
Degrees of freedom Categories − 1 (Rows − 1) × (Columns − 1)
Data layout Single row or column of categories Contingency table (rows × columns)

Worked Example: Chi-Square Test of Independence

Worked Example: Coffee Habit by Year of Study

A researcher surveys 150 students (50 per year group) on whether they drink coffee daily. Observed counts: Year 1 = 35 coffee / 15 no; Year 2 = 28 coffee / 22 no; Year 3 = 20 coffee / 30 no.

Row totals are equal, so expected frequencies per row are 27.67 (coffee) and 22.33 (no coffee), from (row total × column total) ÷ grand total.

Summing (O − E)² ÷ E across all six cells gives χ² = 9.12. Degrees of freedom = (3 − 1) × (2 − 1) = 2.

The critical value at α = 0.05 with df = 2 is 5.991. Since 9.12 > 5.991, the researcher rejects H0 and concludes year of study is associated with coffee habit.

Degrees of Freedom and the Critical Value

Degrees of freedom (df) tell you which row of the chi-square distribution to check. For goodness of fit, df equals the number of categories minus one. For independence, df equals (rows − 1) × (columns − 1).

Once you have df and a significance level, usually 0.05, look up the critical value in a chi-square table. If your calculated χ² exceeds it, reject the null hypothesis.

Most statistics software reports an exact p-value instead of a table lookup. If p falls below your significance level, the result is statistically significant, following the same logic covered in our guide to hypothesis testing.

With small samples, consider Yates’ continuity correction for 2×2 tables, or switch to Fisher’s exact test, since standard chi-square can overstate significance when expected counts are low.

Reporting Chi-Square Results in APA Style

Most UK social science departments expect APA-style reporting for chi-square: the symbol, degrees of freedom and sample size in brackets, then the statistic and exact p-value.

Write it as χ²(df, N = sample size) = value, p = .xxx — for example χ²(2, N = 150) = 9.12, p = .010, matching the worked example above.

Round χ² to two decimal places and the p-value to three, dropping the leading zero in APA style, and switch to “p < .001” once the exact value rounds to zero.

Common Mistakes to Avoid

A handful of errors account for most marks lost on chi-square write-ups. Watch for these before you submit any results chapter or lab report.

  • Using chi-square on continuous data instead of categorical data — convert or bin the variable first, or choose a different test.
  • Leaving expected cell frequencies below five, which most textbooks flag as unreliable; combine categories where this happens.
  • Confusing association with causation — a significant result shows a relationship exists, not that one variable causes the other.
  • Omitting degrees of freedom or the exact p-value alongside χ² when reporting results.
  • Running chi-square repeatedly on the same dataset without adjusting for multiple comparisons, which inflates the risk of a false positive finding.

Template You Can Copy

Template You Can Copy: Reporting a Chi-Square Result

Use this checklist when writing up a chi-square result in a report or dissertation chapter:

  • Name the variables and state H0 and H1 clearly.
  • Report the sample size (N) and test type used.
  • Give χ², degrees of freedom, and the exact p-value.
  • State the significance level applied, e.g. α = 0.05.
  • Say whether H0 was rejected or retained.
  • Add one plain-English sentence explaining what the result means.

Example sentence: “χ²(2, N = 150) = 9.12, p = .010, indicating a significant association between year of study and coffee habit.”

Getting Help With Your Statistical Analysis

Running and reporting a chi-square test correctly takes practice, especially when you are also writing up methodology and results chapters against a deadline.

Our statistical analysis service supports UK students with SPSS, R and Excel workings, correct formula application, and clearly written results sections for dissertations and reports.

If you need broader support with your research project, explore our dissertation writing service, or browse more statistical analysis guides for step-by-step help with other tests.

Get Statistical Analysis Support

Frequently Asked Questions

A chi-square test checks whether categorical data fits an expected pattern (goodness of fit) or whether two categorical variables are related (test of independence). It compares observed frequencies against expected frequencies to reveal genuine relationships rather than random variation in survey or experimental data.

The chi-square formula is χ² = Σ (O − E)² ÷ E, where O is the observed frequency and E is the expected frequency for each category or cell. You calculate this for every cell, then sum the results to get the final chi-square statistic.

Goodness of fit tests whether one categorical variable matches an expected distribution, such as checking if dice rolls are fair. The test of independence checks whether two categorical variables are associated, such as year group and coffee habit, using a contingency table layout.

For goodness of fit, degrees of freedom equal the number of categories minus one. For a test of independence, degrees of freedom equal (number of rows − 1) multiplied by (number of columns − 1). This value determines which row of the chi-square table to check.

There is no fixed minimum, but guidance generally recommends expected frequencies of at least five in every cell. If several cells fall below this, results become unreliable, and you may need to combine categories or use an alternative such as Fisher’s exact test.

Compare your calculated χ² value to the critical value from a chi-square table at your chosen significance level and degrees of freedom, or check the p-value in your software output. If χ² exceeds the critical value, or p is below 0.05, reject the null hypothesis.

About Jesse Pinkman

Avatar for Jesse PinkmanJessie Pinkman has been writing since childhood when her mother gave her a book where she could write her stories. Since then Jessie has always loved to write about the topics she loves. She graduated from Birmingham University in 2012, worked as a teaching assistant, and then turned to full-time writing in 2016.

You May Also Like

WhatsApp Live Chat