Chi Square Calculate | Formula, Table, And Worked Math

A chi-square total comes from summing each category’s squared gap from expectation, divided by the expected count.

Chi-square looks scary when you first see the symbol. The math itself is plain. You compare what you observed with what you expected, turn each gap into a score, and add the scores together. That’s it.

This test works with counts in categories. Think survey answers, product defects, traffic sources, or test outcomes. If your data lives in buckets instead of decimals, chi-square is often the right place to start.

What A Chi-Square Score Tells You

A chi-square score answers one simple question: are the gaps between observed counts and expected counts small enough to shrug off, or large enough to treat as real? Small gaps give you a small score. Bigger gaps push the score up.

You’ll usually meet chi-square in two settings. One checks whether one set of counts matches a stated pattern. The other checks whether two categorical variables seem tied together. In both cases, the engine under the hood is the same.

  • You need count data, not averages or percentages by themselves.
  • Each item should land in one category only.
  • Each observation should be independent of the others.
  • Expected counts should not be tiny across the table.

Chi Square Calculate In A Four-Step Method

If you want to work it out by hand, use a clean sequence and write each line down. Most errors come from rushing the setup, not from the arithmetic.

Step 1: List The Observed Counts

Observed counts are the numbers you actually collected. Say 200 people chose one of four snacks, and the counts came out like this: 62, 41, 55, and 42.

Step 2: Work Out The Expected Counts

Expected counts come from the pattern you want to test. If all four snacks were meant to be equally popular, each category would get 200 ÷ 4 = 50.

Step 3: Compute Each Category’s Piece

Use the formula χ2 = Σ (O – E)2 / E. For the four snack counts, the pieces are 2.88, 1.62, 0.50, and 1.28.

Step 4: Add The Pieces

Add them: 2.88 + 1.62 + 0.50 + 1.28 = 6.28. That is your chi-square statistic. Then match that result to the right degrees of freedom and p-value rule.

For a one-way goodness-of-fit setup with four categories, the degrees of freedom are k – 1, so here that’s 3. The raw score alone is not the finish line. You still need the degrees of freedom to read it properly.

Part Of The Job What You Do Slip That Trips People Up
Observed counts Write the actual category totals from your data Using percentages instead of counts
Expected counts Set counts from your null pattern or table totals Guessing instead of deriving them
Cell difference Subtract expected from observed Dropping the minus sign too soon
Square the gap Multiply the difference by itself Squaring only one part of the gap
Divide by expected Compute each cell’s contribution Dividing by observed instead
Total score Add all cell contributions Skipping a category
Degrees of freedom Use the rule that fits your table type Using the wrong formula
Decision Read the score against a p-value or critical value Treating a big score as proof of cause

Calculating A Chi-Square Score For Categorical Data

The setup shifts a bit when you move from one list of categories to a two-way table. In a goodness-of-fit test, expected counts come from a stated pattern, such as equal shares or a known ratio. In a test of independence, expected counts come from the row and column totals.

That second case uses this rule for each cell: (row total × column total) ÷ grand total. Once you have the expected count for every cell, the rest is the same old chi-square formula repeated across the full table.

If you want a formal source for the formula and the way grouped counts are handled, NIST’s chi-square goodness-of-fit test lays it out clearly. For a plain teaching walk-through on expected counts and the split between goodness-of-fit and independence work, Penn State’s chi-square lessons are a solid read.

What Degrees Of Freedom Mean Here

Degrees of freedom tell you which chi-square curve to use. In a goodness-of-fit test, it is often the number of categories minus one. In a two-way table, it is (rows – 1) × (columns – 1).

That matters because the same chi-square score can look mild in one setup and pretty strong in another. A score of 6 does not carry one fixed meaning. The table shape changes the reading.

Chi-Square Test Type Use It When Degrees Of Freedom
Goodness Of Fit One categorical variable is checked against a target pattern k – 1
Independence You want to know whether two categorical variables are linked (r – 1) × (c – 1)
Homogeneity You compare category shares across separate groups (r – 1) × (c – 1)

How To Read The Result Without Stretching It

A larger chi-square score means the observed counts stray farther from the expected counts. If the p-value lands below your chosen cutoff, you reject the null hypothesis. That tells you the gap is unlikely to be random noise alone.

That does not mean the pattern is huge, useful, or causal. It only says the counts do not sit well with the null model. Big samples can make small gaps look statistically strong. Small samples can hide a gap you’d care about in practice.

  • A low p-value says the counts and the null model do not sit together well.
  • A high p-value says the data do not give you enough reason to reject the null model.
  • The test does not tell you why a pattern appeared.
  • The test does not tell you how large the real-world effect feels.

Common Mistakes That Warp The Math

Most bad chi-square work comes from four habits. One, using percentages instead of raw counts. Two, stuffing the same person or item into more than one category. Three, ignoring tiny expected counts. Four, treating a rejected null as proof of cause and effect.

There’s also a plain data-entry trap. If your row totals or grand total are off by even one or two entries, every expected count shifts. Check totals before you trust the last line.

When Hand Calculation Helps More Than A Calculator

A calculator or spreadsheet is fine once your table gets wide. Still, doing one full problem by hand is worth the effort. You see where each cell’s weight comes from, which categories drive the result, and whether one odd count is doing most of the work.

That kind of read is easy to miss when you paste numbers into a tool and stare only at the p-value. Hand math slows you down in a good way. It shows whether the setup makes sense before software turns it into a polished output.

If you’re learning the method, start with a four- or five-category problem and write every intermediate line. Once that feels natural, move to a two-way table. After that, a calculator becomes a time-saver instead of a crutch.

Chi-square is one of those methods that looks dense from a distance and feels plain once you run it twice. Count what you saw. Build what you expected. Compute each cell’s share. Add them up. Then read the score with the right degrees of freedom, and your result will make sense.

References & Sources