Skip to content
DeviceCheckHub

Chi-Square Calculator

Test whether two categorical variables are related, or whether counts fit an expected pattern. Paste a table straight from a spreadsheet and get the expected counts, p-value, effect size and each step.

Your counts

χ² = 12.99 with 4 degrees of freedom, p = 0.01132.

χ² = 12.99, p = 0.01132

Significant at α = 0.05: the row and column variables appear to be related (not independent).

051015
χ²
12.99
Degrees of freedom
4
p-value
0.01132
Critical χ² (α = 0.05)
9.488
Total count
839
Cramér’s V
0.088
Largest contribution
Community college, 1–3 hours: 4.607 (more than expected)

Observed and expected counts

Each cell shows the observed count above the expected count. Cells well above expected are marked in red, well below in blue.

1–3 hours4–6 hours7–9 hours
Community college11190.5796115.24849.24
Four-year college961031331316156
Nonstudents91104.4150132.85356.77

In R: chisq.test(matrix(c(111, 96, 91, 96, 133, 150, 48, 61, 53), nrow = 3))

Step by step

  1. Expected count for each cell = (row total × column total) / grand total. For the first cell: 255 × 298 / 839 = 90.57.
  2. χ² = Σ (O − E)² / E over all 9 cells = 12.99.
  3. Degrees of freedom = (rows − 1) × (columns − 1) = 4.
  4. p-value = P(χ² ≥ 12.99) with 4 df = 0.01132. That is below α = 0.05, so reject H₀.

How to use the chi-square calculator

  1. Choose Independence to test whether two categorical variables are related, using a table of counts, or Goodness of fit to compare one set of counts with an expected pattern.
  2. Paste or type your counts. A first row and first column of names are optional; if your names contain spaces, paste from a spreadsheet so the columns are separated by tabs.
  3. The test statistic, p-value, expected counts and steps update as you type.

What the chi-square test does

The chi-square (χ²) test compares the counts you observed (O) with the counts you would expect (E) if the null hypothesis were true. Each cell adds (O − E)² / E to the total, so the statistic grows when the observed counts are far from the expected ones. In OpenStax’s words, when they aren’t close, “the test statistic can get very large and will be way out in the right tail of the chi-square curve.” The p-value is the area of that right tail.

Test of independence

A test of independence asks whether two variables, such as type of volunteer and hours volunteered, are related. The null hypothesis is that they are independent. The expected count for each cell comes from the row and column totals: E = (row total × column total) / grand total, and the degrees of freedom are (rows − 1) × (columns − 1). OpenStax adds that “the test of independence is always right-tailed because of the calculation of the test statistic.”

The starting table is OpenStax’s volunteer example: 839 adult volunteers classified by type and by hours volunteered each week. The expected count for community college students volunteering 1–3 hours is 255 × 298 / 839 = 90.57, against 111 observed. Over all nine cells, χ² = 12.99, p = 0.01132 with 4 degrees of freedom, so at the 5% level the hours volunteered depend on the type of volunteer. The biggest single contribution is Community college, 1–3 hours: 4.607 (more than expected).

Goodness-of-fit test

A goodness-of-fit test compares one row of counts with a distribution you specify, with “df = (number of categories – 1).” Leave the expected box blank to test for equal shares, or enter expected counts, proportions or percentages. In another OpenStax example, an employer records 60 absences over the work week: 15, 12, 9, 9 and 15 from Monday to Friday. If absences were spread evenly, each day would expect 12. The test gives χ² = 3, p = 0.5578 with 4 degrees of freedom, so there is no evidence that absences favor particular days.

Working it out by hand

For the absence example, each day expects 12. The contributions are (15 − 12)²/12 = 0.75 for Monday, (12 − 12)²/12 = 0 for Tuesday, (9 − 12)²/12 = 0.75 for Wednesday and for Thursday, and (15 − 12)²/12 = 0.75 for Friday. They add up to χ² = 3, with 5 − 1 = 4 degrees of freedom. The area to the right of 3 under the chi-square curve with 4 df is the p-value, 0.5578. The calculator’s table shows the same numbers for your data.

Test of homogeneity

The same calculation answers a slightly different question when you sample each group separately, for example 250 men and 300 women asked about their living arrangements. Then the test asks whether the groups share the same distribution: OpenStax describes it as a test “about whether two populations have the same distribution,” and says that to calculate it you “follow the same procedure as with the test of independence.” Enter the table in Independence mode; the χ², degrees of freedom and p-value are identical.

The rule of five

The chi-square p-value is an approximation that works well only when the expected counts aren’t too small. OpenStax states the usual rule: “The expected value for each cell needs to be at least five in order for you to use this test.” The calculator counts any cells below 5 and warns you. Combining neighboring categories is the usual fix.

Reading the cells

A significant result says the table as a whole doesn’t fit, not where the difference is. To find it, compare each observed count with its expected count. The calculator also works out the residual (O − E) / √E for each cell and marks the cells beyond ±2, which are clearly above (red) or below (blue) expectation. In the volunteer table only one cell is beyond ±2: community college students volunteering 1–3 hours, 111 observed against about 91 expected.

Effect size: Cramér’s V

With a large sample, even a weak relationship can be significant. Cramér’s V, √(χ² / (n × (k − 1))) where k is the smaller of the number of rows and columns, puts the strength on a scale from 0 (no association) to 1 (complete association). For the volunteer data V = 0.088: significant, but small on that scale.

The Yates correction for 2 × 2 tables

For tables with two rows and two columns, the Yates continuity correction subtracts 0.5 from each |O − E| before squaring. It lowers χ² and raises the p-value. R’s chisq.test applies it to 2 × 2 tables unless you add correct = FALSE; OpenStax’s examples don’t use it. Tick the box to match a result that did.

In Excel or R

Excel’s CHISQ.TEST(actual_range, expected_range) returns the p-value, but you have to build the expected table yourself first. In R, chisq.test on a matrix does the whole test, and the calculator shows the exact call for your table under the result.

What the test doesn’t tell you

The chi-square test works on counts of independent observations, where each person or item appears in exactly one cell. Percentages, averages and measurements have to be turned back into counts of people or items before you use it. It can show that two variables are associated, but not why, and not that one causes the other.

Your data stays on your device

Everything is worked out in your browser. Nothing you type or paste is sent anywhere or stored.

Frequently asked questions

How do I enter a table from Excel or Google Sheets?

Select the counts, with the row and column names if you like, copy them and paste into the table box. Each row goes on its own line, and the columns are separated by tabs. You can also type the counts with spaces or commas between them.

What if some expected counts are below 5?

The p-value may not be reliable. Combine small categories that make sense together, collect more data, or, for a 2 × 2 table, use Fisher’s exact test. The calculator tells you how many cells are below 5.

Can I use percentages?

Not for the observed values: the test needs the actual counts, because 50% of 10 people is much weaker evidence than 50% of 1,000. For goodness of fit, the expected values can be counts, proportions or percentages; they are scaled to your total.

Should I use the Yates correction?

It is an option for 2 × 2 tables that makes the test more conservative. R applies it to 2 × 2 tables by default, while OpenStax’s examples don’t, so tick it if you need to match a result that used it.

What does a significant result tell me?

That the counts are unlikely if the variables were independent (or if the expected distribution were true). It doesn’t say how strong the relationship is or what causes it. Look at Cramér’s V and at which cells are far from their expected counts.

Is my data uploaded?

No. Everything is worked out in your browser and nothing you type is sent anywhere or stored.

Last updated · About DeviceCheckHub