Chi-Square Calculator: P-Value & Goodness of Fit (2 Categories)

This chi-square calculator does two jobs. It runs a two-category goodness-of-fit test from observed and expected counts, and it looks up the p-value for any chi-square statistic and degrees of freedom you already have.

Math Calculators

Chi Square Calculator

Chi-square statistic and p-value for a goodness-of-fit test comparing observed vs. expected frequencies, or a direct p-value lookup from a chi-square value and degrees of freedom.

A commonly used significance threshold is p < 0.05, but the appropriate threshold depends on your field and study design — this tool computes the statistic and p-value only.

Starting values: the p-value mode opens with χ² = 7.815 and 3 degrees of freedom, which gives a p-value of about 0.05. The goodness-of-fit mode opens with observed counts of 45 and 55 against expected counts of 50 and 50, which gives χ² = 1.0 and a p-value of about 0.3173 with 1 degree of freedom.

What the calculator covers

There are two modes. The goodness-of-fit mode compares two observed counts with two expected counts. The p-value mode takes a chi-square statistic and degrees of freedom and returns the upper-tail probability, which is the chance of seeing a statistic larger than yours if the null hypothesis is true. The goodness-of-fit mode is fixed at two categories. The calculator does not run a test of independence on a contingency table. For tests with more categories, work out χ² by hand using the formula below, then enter the statistic and your degrees of freedom in the p-value mode.

The formulas

χ² = Σ (O − E)² ÷ E
Degrees of freedom (goodness of fit) = k − 1

Where:

  • O = an observed count
  • E = the expected count under the null hypothesis
  • k = the number of categories
  • Σ = add the term for every category

With two categories, k − 1 = 1, which is why the goodness-of-fit mode reports its p-value with 1 degree of freedom.

Reading the p-value

The p-value mode returns the upper-tail probability. A small p-value means the observed counts are far from what you expected, so the null hypothesis looks doubtful. A common rule is to reject the null hypothesis when the p-value is at or below your chosen significance level, often 0.05. The test is right-tailed because larger χ² values mean a poorer fit. Choose the significance level before you look at the data, not after.

Worked examples

Example 1: p-value lookup (the default)

Enter χ² = 7.815 and df = 3. The calculator returns a p-value of about 0.05. A critical value of 7.815 at 3 degrees of freedom is the standard 5 percent cut-off: a statistic larger than 7.815 has a p-value below 0.05.

Example 2: two-category goodness of fit (the default)

A coin is flipped 100 times, and you expect 50 heads and 50 tails. You see 45 heads and 55 tails.

  1. Heads term: (45 − 50)² ÷ 50 = 25 ÷ 50 = 0.5.
  2. Tails term: (55 − 50)² ÷ 50 = 25 ÷ 50 = 0.5.
  3. χ² = 0.5 + 0.5 = 1.0, with df = 1.
  4. The p-value is about 0.3173.

Since 0.3173 is well above 0.05, there is no good evidence that the coin is unfair. A 45–55 split in 100 flips is within the range chance often produces.

Example 3: a bigger gap

Suppose the same coin gives 40 heads and 60 tails. Each term is 100 ÷ 50 = 2, so χ² = 4.0 with df = 1. The p-value is about 0.0455, below 0.05, so at the 5 percent level you would reject the idea that the coin is fair.

Example 4: three categories, worked by hand then looked up

A statistics course uses a mixed-nut example. Observed counts are 30, 55 and 15, and the expected counts are 20, 60 and 20.

  1. (30 − 20)² ÷ 20 = 5.
  2. (55 − 60)² ÷ 60 = 0.4167.
  3. (15 − 20)² ÷ 20 = 1.25.
  4. χ² = 6.667, with df = 3 − 1 = 2.

Enter 6.667 and 2 in the p-value mode. The result is about 0.0357, which lies between 0.025 and 0.05, so the null hypothesis is rejected at the 5 percent level.

Conditions for a valid test

The chi-square approximation works best when expected counts are not tiny. A common guideline from a college statistics text is that every expected count should be at least 1, and no more than about 20 percent of them should be below 5. The observations should also be independent counts of whole items, not percentages or averages. If your expected counts are very small, a chi-square result may mislead.

Common mistakes

  • Entering percentages instead of counts in the goodness-of-fit mode. Use the actual numbers of observations.
  • Making the observed and expected totals different. Expected counts should add up to the same total as the observed counts.
  • Using the wrong degrees of freedom in the p-value mode. For a goodness-of-fit test it is the number of categories minus 1.
  • Treating a large p-value as proof that the null hypothesis is true. It only means the data gives no strong reason to reject it.

If you want to see how far a single value lies from an average rather than test counts, the z-score calculator covers that.

Choosing the right test for your data

The goodness-of-fit test asks whether counts across categories match a pattern you expected. Typical uses include checking whether a die is fair, whether customers choose products in the proportions you predicted, or whether a sample of people matches known population shares. A different design, a test of independence, asks whether two categorical variables are related, and it needs a table of counts. The tool here does not build that table, so it is the wrong tool for the question "is product choice related to age group".

Setting the expected counts

Expected counts come from your null hypothesis, not from the data. If you believe two outcomes are equally likely and you have 100 observations, expect 50 and 50. If you believe the split is 70 to 30, expect 70 and 30. In both cases the expected counts must add up to the observed total, so scale the proportions to the sample size before you enter them. A table of proportions on its own is not enough, because chi-square works on counts.

Effect of sample size

The same proportions give a larger chi-square as the sample grows. A 45–55 split in 100 flips gives χ² = 1.0. The same 45 percent to 55 percent split in 1,000 flips (450 and 550) gives (50² ÷ 500) × 2 = 10.0, a p-value far below 0.05. A small difference can be convincing when you have a lot of data, which is why the p-value should always be read together with the size of the difference.

Frequently asked questions

Does the calculator run a test of independence?

No. Its goodness-of-fit mode compares two observed counts with two expected counts. For other designs, compute the chi-square statistic yourself and use the p-value mode with the right degrees of freedom.

What degrees of freedom do I use?

For a goodness-of-fit test, use the number of categories minus 1. The two-category mode uses 1 automatically.

What p-value counts as significant?

Many fields use 0.05, so a p-value at or below 0.05 leads you to reject the null hypothesis. Set your level before looking at the data.

Is the p-value one-sided?

Yes. It is the upper-tail probability, the chance of a chi-square value larger than yours. That is the correct tail for a chi-square test.

Mark Danny

Mark Danny

Mark Danny builds and maintains the free calculators and guides on Area of Irregular Shapes Calculator. Every calculator page explains its formula and shows a worked example, so you can check the working yourself. Spotted a mistake or have a suggestion? Email gulsher.hingoro101@gmail.com.

Articles: 739