Loona Calculators
Loona Calculators › Maths › Chi-Square Test Calculator

▦ Chi-Square Test Calculator

Test categorical data two ways: independence in a table (rows × columns of observed counts) or goodness of fit (observed counts against expected counts). Get the chi-square statistic, degrees of freedom, the expected table and the p-value.

Quick answer: Chi-square = Σ (observed − expected)² ÷ expected. For the 2×2 table [[10, 20], [20, 10]], every expected count is 15, so χ² = 4 × (25 ÷ 15) = 6.667 on 1 df, p ≈ 0.0098.

How to use the Chi-Square Test Calculator

  1. Choose Independence (a table) or Goodness of fit.
  2. For a table, enter one row per line with counts separated by spaces or commas — all rows the same length.
  3. For goodness of fit, enter the observed counts and the expected counts in the same order.
  4. Read χ², df, p and the expected values used.
Example: A 2×2 survey table [[10, 20], [20, 10]] (60 people): χ² = 6.667, df = 1, p ≈ 0.0098 — the two variables are unlikely to be independent.

Frequently Asked Questions

What are the degrees of freedom?

For independence: (rows − 1) × (columns − 1). For goodness of fit: categories − 1 (minus any parameters estimated from the data, which this calculator does not do).

How large should expected counts be?

The standard rule of thumb wants most expected counts at least 5. With tiny expected counts the chi-square approximation weakens — Fisher's exact test is the classic alternative for small 2×2 tables.

What does a significant result tell me?

For independence: the two variables are associated — not that one causes the other. For goodness of fit: the observed pattern departs from the expected model more than chance alone would typically produce.

Why does the calculator show the expected table?

Because checking expected counts is part of doing the test honestly — you can see exactly which cells drive the statistic.

Related Calculators

%

Percentage Calculator

Maths

📊

Statistics Calculator

Maths

½

Fraction Calculator

Maths

🧮

Equation Solver

Maths

🔬

Scientific Calculator

Maths

📐

Average Calculator

Maths

🔔

Z-Score Calculator

Maths

🎲

Probability Calculator

Maths

How it works — the formula

χ² = Σ (O − E)² ÷ E over all cells. For independence, E for a cell = (row total × column total) ÷ grand total, and df = (r − 1)(c − 1). For goodness of fit, E values are supplied by the model and df = categories − 1. The p-value is the right tail of the chi-square distribution, computed via the incomplete gamma function.

Worked example

Inputs: table [[10, 20], [20, 10]].

Steps: Row totals 30 and 30; column totals 30 and 30; grand total 60. Every E = 30 × 30 ÷ 60 = 15. Each cell contributes (5² ÷ 15) = 1.667; four cells give χ² = 6.667. df = (2−1)(2−1) = 1. p = P(χ²₁ ≥ 6.667) ≈ 0.0098.

Result: χ² = 6.667, df 1, p ≈ 0.0098. Goodness-of-fit check: observed [10, 20, 30] against expected [20, 20, 20] gives χ² = 5 + 0 + 5 = 10 on 2 df, p ≈ 0.0067.

Embed this calculator on your website — free

Add this calculator to your own website or blog — it is completely free, needs no sign-up, and always shows the latest version. Copy the code below and paste it into your page where you want the calculator to appear. Keeping the small “Powered by Loona Automation” credit line under the embed helps keep this tool free — but you are free to style or remove it; the tool works either way.