Advertisement
Hypothesis Testing

Chi-Square Goodness-of-Fit Calculator

Use this chi-square goodness-of-fit calculator to determine whether observed category frequencies follow an expected distribution. Enter summary frequencies or raw categorical data to find the chi-square statistic, p-value, critical value, expected counts, and a complete step-by-step solution.

Categories
Enter the category labels and observed counts. Expected proportions must be entered as decimals.
Enter one observation per line, or separate entries with commas or semicolons. Spaces inside category names such as “Very satisfied” are preserved.
Detected Categories

Observed counts are calculated automatically from the raw data. Enter the expected proportions or expected counts when required.

Observed counts must be nonnegative whole numbers. Expected proportions must be positive decimals that total 1. Expected counts must be positive numbers that total the observed sample size. The calculator also checks whether every expected count is at least 5.

Step-by-Step Solution

How to Use the Chi-Square Goodness-of-Fit Calculator

Use this calculator to determine whether the observed frequencies for one categorical variable follow an expected distribution. You can enter summarized category counts or paste the original categorical observations.

The calculator returns:

  • The chi-square statistic
  • Degrees of freedom
  • P-value
  • Chi-square critical value
  • Observed and expected counts
  • The contribution of each category to the test statistic
  • An expected-count assumption check
  • A complete step-by-step hypothesis test

Using Summary Data

Choose Summary Data when you already know how many observations fall within each category.

  1. Select Summary Data.
  2. Enter the significance level, α.
  3. Give the categorical variable a descriptive name.
  4. Choose the expected distribution.
  5. Enter each category and its observed count.
  6. Add more categories as needed.
  7. Click Calculate.

Observed counts must be nonnegative whole numbers because they represent actual numbers of observations.

Choosing the Expected Distribution

The calculator provides three options.

Equal Proportions

Select Equal Proportions when all categories are expected to occur equally often.

For example, if a survey has four response categories and each response is equally likely, the expected proportion for every category is:

Expected proportion = 1/4 = 0.25

The calculator obtains each expected count by dividing the total sample size by the number of categories.

Expected Proportions

Select Expected Proportions when the expected distribution is unequal and the question provides proportions or probabilities.

Enter each proportion as a decimal. For example:

0.40, 0.30, 0.20, 0.10

The entered proportions must total 1.

The calculator converts each proportion to an expected count using:

Expected count = Sample size × Expected proportion

Expected Counts

Select Expected Counts when the expected number of observations in each category is already known.

The expected counts must add up to the observed sample size. Unlike observed counts, expected counts may contain decimals because they are calculated or theoretically predicted values.

Using Raw Data

Choose Raw Data when you have the individual categorical responses rather than summarized counts.

For example:

Online, In Person, Online, Hybrid, Online, In Person

The calculator identifies the unique categories and counts how many times each one appears.

To use raw data:

  1. Select Raw Data.
  2. Enter the significance level.
  3. Enter a name for the categorical variable.
  4. Paste the individual responses.
  5. Choose equal proportions, expected proportions, or expected counts.
  6. Enter the expected values when required.
  7. Click Calculate.

You may separate entries using commas, semicolons, or new lines. Spaces within category names such as Very satisfied are preserved.

Raw-data mode is intended for categorical observations. Do not paste continuous measurements such as heights, test scores, or reaction times and expect the calculator to create statistical intervals automatically.

What Is a Chi-Square Goodness-of-Fit Test?

A chi-square goodness-of-fit test determines whether the observed distribution of one categorical variable differs significantly from a specified expected distribution.

It answers questions such as:

  • Are customers equally likely to choose four product designs?
  • Do student majors follow the distribution reported by the university?
  • Does the distribution of blood types in a sample match known population proportions?
  • Are visits to a website equally distributed across the seven days of the week?
  • Do genetic outcomes follow a specified inheritance ratio?
  • Does the observed distribution of survey responses match the organization’s expected pattern?

The test compares the number of observations actually found in each category with the number that would be expected if the null hypothesis were true. Penn State describes the expected count for category iii as the sample size multiplied by the hypothesized population proportion for that category.

The test uses one categorical variable with two or more categories. When the observed counts differ substantially from the expected counts, the chi-square statistic becomes larger and provides evidence against the expected distribution.

When Should You Use a Goodness-of-Fit Test?

Use a chi-square goodness-of-fit test when:

  • You have one categorical variable.
  • The observations are recorded as category counts.
  • Each observation belongs to only one category.
  • You have a theoretical, historical, or otherwise specified expected distribution.
  • You want to test the entire distribution rather than one category in isolation.
  • The observations are independent.
  • The expected counts are sufficiently large.

The expected distribution should be established before examining the sample results. It may come from a theory, previous research, established population percentages, a company target, or the assumption that every category is equally likely.

When Is the Test Not Appropriate?

Do not use this test when:

  • You are examining the relationship between two categorical variables.
  • Your outcome is a continuous measurement.
  • The same participant provides several related observations.
  • Your values are means, percentages, or standard deviations rather than counts.
  • The expected distribution was created merely by copying the observed sample distribution.
  • One or more expected counts are too small for the chi-square approximation.

To test whether two categorical variables are associated, use a chi-square test of independence instead.

Hypotheses for a Chi-Square Goodness-of-Fit Test

The null hypothesis states that the population follows the specified distribution.

The alternative hypothesis states that at least one population proportion differs from the specified value.

For kkk categories, the hypotheses may be written as:

H₀: p1=p10,p2=p20,,pk=pk0p_1 = p_{10}, p_2 = p_{20}, \ldots, p_k = p_{k0}p1​=p10​,p2​=p20​,…,pk​=pk0​

H₁: At least one population proportion is not equal to its specified value.

For example, suppose four categories are expected to have proportions of 0.40, 0.30, 0.20, and 0.10.

The hypotheses are:

H₀: p1=0.40, p2=0.30, p3=0.20, p4=0.10p_1 = 0.40,\ p_2 = 0.30,\ p_3 = 0.20,\ p_4 = 0.10p1​=0.40, p2​=0.30, p3​=0.20, p4​=0.10

H₁: At least one of the population proportions differs from the specified proportion.

The alternative hypothesis does not claim that every proportion is different. A difference in only one category is enough for the null distribution to be incorrect.

Chi-Square Goodness-of-Fit Formula

The Pearson chi-square statistic is:χ2=(OiEi)2Ei\chi^2=\sum\frac{(O_i-E_i)^2}{E_i}χ2=∑Ei​(Oi​−Ei​)2​

Where:

  • χ2\chi^2χ2 is the chi-square test statistic.
  • OiO_iOi​ is the observed count in category iii.
  • EiE_iEi​ is the expected count in category iii.
  • \sum∑ means that the contributions from all categories are added.

The statistic measures the combined difference between the observed and expected counts. Squaring each difference prevents positive and negative deviations from canceling one another. Dividing by the expected count places the differences on a comparable scale across categories.

How to Calculate Expected Counts

When the expected proportion for a category is known:Ei=npiE_i=np_iEi​=npi​

Where:

  • nnn is the total sample size.
  • pip_ipi​ is the expected proportion for category iii.

For example, suppose a sample contains 200 observations and a category is expected to contain 30% of the population:E=200(0.30)=60E=200(0.30)=60E=200(0.30)=60

The expected count is 60.

Expected Counts for Equal Proportions

When kkk categories are expected to occur equally often:pi=1kp_i=\frac{1}{k}pi​=k1​

Therefore:Ei=nkE_i=\frac{n}{k}Ei​=kn​

For a sample of 120 observations distributed equally across four categories:Ei=1204=30E_i=\frac{120}{4}=30Ei​=4120​=30

Each category has an expected count of 30.

Degrees of Freedom

For the standard goodness-of-fit test performed by this calculator:df=k1df=k-1df=k−1

Where kkk is the number of categories.

For four categories:df=41=3df=4-1=3df=4−1=3

For six categories:df=61=5df=6-1=5df=6−1=5

The degrees of freedom determine which chi-square distribution is used to calculate the p-value and critical value.

How to Do a Chi-Square Goodness-of-Fit Test

The procedure begins with a proposed population distribution. You calculate the counts expected under that distribution, compare them with the observed counts, and determine whether the differences are too large to attribute reasonably to sampling variation.

The following examples demonstrate the test using both summary data and raw categorical observations.

Example 1: Goodness-of-Fit Test Using Summary Data

A university bookstore reports that, historically, students obtain required textbooks through the following methods:

Purchasing methodExpected proportion
Campus bookstore0.40
Publisher website0.30
Online marketplace0.20
Rental service0.10

At the beginning of a new academic year, a random sample of 200 students produces these results:

Purchasing methodObserved count
Campus bookstore104
Publisher website52
Online marketplace28
Rental service16

At the 5% significance level, test whether the current distribution of textbook-purchasing methods follows the historical distribution.

Step 1: State the Hypotheses

The expected population proportions are 0.40, 0.30, 0.20, and 0.10.

Therefore:

H₀: p1=0.40, p2=0.30, p3=0.20, p4=0.10p_1=0.40,\ p_2=0.30,\ p_3=0.20,\ p_4=0.10p1​=0.40, p2​=0.30, p3​=0.20, p4​=0.10

H₁: At least one population proportion differs from its historical value.

Step 2: State the Significance Level

α=0.05\alpha=0.05α=0.05

Step 3: Calculate the Chi-Square Statistic

First, calculate the expected count for every category.

For the campus bookstore:E1=200(0.40)=80E_1=200(0.40)=80E1​=200(0.40)=80

For the publisher website:E2=200(0.30)=60E_2=200(0.30)=60E2​=200(0.30)=60

For the online marketplace:E3=200(0.20)=40E_3=200(0.20)=40E3​=200(0.20)=40

For the rental service:E4=200(0.10)=20E_4=200(0.10)=20E4​=200(0.10)=20

The observed and expected counts are:

Purchasing methodObserved, OExpected, E
Campus bookstore10480
Publisher website5260
Online marketplace2840
Rental service1620

All expected counts are at least 5, so the expected-count condition is met.

Now calculate the contribution from each category.

For the campus bookstore:(10480)280=7.2000\frac{(104-80)^2}{80}=7.200080(104−80)2​=7.2000

For the publisher website:(5260)260=1.0667\frac{(52-60)^2}{60}=1.066760(52−60)2​=1.0667

For the online marketplace:(2840)240=3.6000\frac{(28-40)^2}{40}=3.600040(28−40)2​=3.6000

For the rental service:(1620)220=0.8000\frac{(16-20)^2}{20}=0.800020(16−20)2​=0.8000

The calculations can be summarized as follows:

Purchasing methodObserved, OExpected, E(OE)2/E(O-E)^2/E(O−E)2/E
Campus bookstore104807.2000
Publisher website52601.0667
Online marketplace28403.6000
Rental service16200.8000

Add the category contributions:χ2=7.2000+1.0667+3.6000+0.8000\chi^2=7.2000+1.0667+3.6000+0.8000χ2=7.2000+1.0667+3.6000+0.8000 χ2=12.6667\chi^2=12.6667χ2=12.6667

The degrees of freedom are:df=k1df=k-1df=k−1 df=41=3df=4-1=3df=4−1=3

Therefore:χ2(3)=12.6667\chi^2(3)=12.6667χ2(3)=12.6667

Step 4: Find the P-Value and Critical Value

For χ2=12.6667\chi^2=12.6667χ2=12.6667 with df=3df=3df=3:p=0.005416p=0.005416p=0.005416

At α=0.05\alpha=0.05α=0.05 and df=3df=3df=3:χcritical2=7.8147\chi^2_{\text{critical}}=7.8147χcritical2​=7.8147

Step 5: Make the Decision

Using the p-value:0.005416<0.050.005416<0.050.005416<0.05

Using the critical value:12.6667>7.814712.6667>7.814712.6667>7.8147

Both methods lead us to reject H0H_0H0​.

Step 6: Write the Conclusion

At the 5% significance level, there is sufficient evidence to conclude that the current distribution of textbook-purchasing methods differs from the historical distribution.

The test establishes that the overall distribution has changed. Examining the observed and expected counts suggests that the campus bookstore was used more frequently than expected, while the other methods were used less frequently. The formal goodness-of-fit conclusion, however, concerns the distribution as a whole.

Verify the Summary-Data Example with the Calculator

Select Summary Data and enter:

  • Significance level: 0.05
  • Variable name: Textbook Purchasing Method
  • Expected distribution: Expected Proportions

Then enter:

CategoryObserved countExpected proportion
Campus bookstore1040.40
Publisher website520.30
Online marketplace280.20
Rental service160.10

The calculator returns:

  • χ2(3)=12.6667\chi^2(3)=12.6667χ2(3)=12.6667
  • P-value = 0.005416
  • Critical value = 7.8147

It also shows how every expected count and category contribution was calculated.

Example 2: Goodness-of-Fit Test Using Raw Data

A student affairs office wants to know whether first-year students are equally likely to choose four locations as their primary place to study:

  • Library
  • Residence Hall
  • Student Center
  • Off Campus

The office randomly selects 40 first-year students and records each student’s preferred location.

The raw responses are:

Library, Residence Hall, Library, Student Center, Library,
Off Campus, Library, Residence Hall, Library, Student Center,
Residence Hall, Library, Library, Residence Hall, Off Campus,
Library, Student Center, Library, Residence Hall, Library,
Student Center, Library, Residence Hall, Library, Off Campus,
Residence Hall, Library, Student Center, Library, Residence Hall,
Library, Off Campus, Student Center, Library, Residence Hall,
Library, Student Center, Residence Hall, Library, Residence Hall

At the 5% significance level, test whether the four study locations are equally preferred.

Step 1: State the Hypotheses

If the four locations are equally preferred, each has a population proportion of 0.25.

Therefore:

H₀: p1=p2=p3=p4=0.25p_1=p_2=p_3=p_4=0.25p1​=p2​=p3​=p4​=0.25

H₁: At least one population proportion is not 0.25.

Step 2: State the Significance Level

α=0.05\alpha=0.05α=0.05

Step 3: Count the Raw Responses and Calculate the Test Statistic

Counting the observations produces:

Study locationObserved count
Library18
Residence Hall11
Student Center7
Off Campus4
Total40

Because equal proportions are expected:E=nkE=\frac{n}{k}E=kn​ E=404=10E=\frac{40}{4}=10E=440​=10

The expected count is 10 for every location.

Study locationObserved, OExpected, E
Library1810
Residence Hall1110
Student Center710
Off Campus410

Calculate the category contributions.

For Library:(1810)210=6.4000\frac{(18-10)^2}{10}=6.400010(18−10)2​=6.4000

For Residence Hall:(1110)210=0.1000\frac{(11-10)^2}{10}=0.100010(11−10)2​=0.1000

For Student Center:(710)210=0.9000\frac{(7-10)^2}{10}=0.900010(7−10)2​=0.9000

For Off Campus:(410)210=3.6000\frac{(4-10)^2}{10}=3.600010(4−10)2​=3.6000

Add the contributions:χ2=6.4000+0.1000+0.9000+3.6000\chi^2=6.4000+0.1000+0.9000+3.6000χ2=6.4000+0.1000+0.9000+3.6000 χ2=11.0000\chi^2=11.0000χ2=11.0000

The degrees of freedom are:df=41=3df=4-1=3df=4−1=3

Therefore:χ2(3)=11.0000\chi^2(3)=11.0000χ2(3)=11.0000

Step 4: Find the P-Value and Critical Value

For χ2=11.0000\chi^2=11.0000χ2=11.0000 with df=3df=3df=3:p=0.011726p=0.011726p=0.011726

At α=0.05\alpha=0.05α=0.05 and df=3df=3df=3:χcritical2=7.8147\chi^2_{\text{critical}}=7.8147χcritical2​=7.8147

Step 5: Make the Decision

The p-value is less than the significance level:0.011726<0.050.011726<0.050.011726<0.05

The calculated chi-square statistic is also greater than the critical value:11.0000>7.814711.0000>7.814711.0000>7.8147

Therefore, reject H0H_0H0​.

Step 6: Write the Conclusion

At the 5% significance level, there is sufficient evidence to conclude that first-year students do not prefer the four study locations equally.

Verify the Raw-Data Example with the Calculator

Select Raw Data, enter 0.05 as the significance level, and use Primary Study Location as the variable name.

Paste the 40 responses into the Raw Data field and choose Equal Proportions.

The calculator automatically:

  1. Detects the four categories.
  2. Counts the observations in each category.
  3. Assigns an expected proportion of 0.25 to each category.
  4. Calculates an expected count of 10 for each category.
  5. Returns χ2(3)=11.0000\chi^2(3)=11.0000χ2(3)=11.0000, p=0.011726p=0.011726p=0.011726, and a critical value of 7.8147.

Assumptions of the Chi-Square Goodness-of-Fit Test

The chi-square result should only be interpreted when the test conditions are reasonable.

The Variable Is Categorical

The observations must be placed into categories such as:

  • Yes, No, or Unsure
  • Freshman, Sophomore, Junior, or Senior
  • Red, Blue, Green, or Yellow
  • Very dissatisfied through Very satisfied

The test is based on the number of observations in each category.

Categories Are Mutually Exclusive

Each observation must belong to only one category.

A student cannot be counted under both Library and Student Center when the variable records the student’s single primary study location.

The categories should also cover every valid response so that observations are not unintentionally excluded.

Observations Are Independent

Each person, object, or event should contribute one observation to the analysis.

Repeated responses from the same participant are not independent and generally require a method that accounts for the paired or repeated structure.

The Data Are Counts

Observed values must represent numbers of cases.

Do not enter:

  • Percentages as observed counts
  • Sample proportions as observed counts
  • Means
  • Standard deviations
  • Test scores
  • Measurement values

When you have observed percentages and know the sample size, convert the percentages to counts before performing the test.

Expected Counts Are Sufficiently Large

A commonly taught condition for the chi-square goodness-of-fit test is that every expected count should be at least 5. The calculator checks this condition and displays a warning when it is not met. Penn State and NIST both describe an expected-frequency threshold of 5 for using the chi-square approximation in introductory applications.

When expected counts are too small, reasonable options may include collecting more observations or combining categories that are substantively similar. Categories should not be combined solely to force a desired result.

How to Report a Goodness-of-Fit Test

A concise statistical report should identify:

  • The categorical variable
  • The expected distribution
  • The chi-square statistic
  • Degrees of freedom
  • Sample size
  • P-value
  • The hypothesis-test conclusion

For the textbook-purchasing example:

A chi-square goodness-of-fit test showed that the distribution of textbook-purchasing methods differed significantly from the historical distribution, χ2(3,N=200)=12.67, p=.005\chi^2(3, N=200)=12.67,\ p=.005χ2(3,N=200)=12.67, p=.005.

For the study-location example:

A chi-square goodness-of-fit test indicated that the four study locations were not equally preferred, χ2(3,N=40)=11.00, p=.012\chi^2(3, N=40)=11.00,\ p=.012χ2(3,N=40)=11.00, p=.012.

When the p-value is below .001, report p<.001p<.001p<.001 rather than p=.000p=.000p=.000.

Chi-Square Goodness of Fit vs Test of Independence

These tests use the same general chi-square formula but answer different questions.

FeatureGoodness-of-fit testTest of independence
Number of variablesOne categorical variableTwo categorical variables
Main questionDoes the observed distribution match an expected distribution?Are the variables associated?
Data structureOne set of category countsContingency table
Expected countsBased on specified proportions or countsCalculated from row and column totals
Degrees of freedomk1k-1k−1(r1)(c1)(r-1)(c-1)(r−1)(c−1)
ExampleAre four brands equally preferred?Is brand preference associated with age group?

Use the goodness-of-fit test when you have one categorical variable and a hypothesized distribution.

Use the chi-square test of independence when every observation has values for two categorical variables. The distinction between the two procedures is also emphasized by Pearson and Penn State.

Common Mistakes to Avoid

Entering Expected Percentages Instead of Decimal Proportions

When Expected Proportions is selected, enter:

0.40, 0.30, 0.20, 0.10

Do not enter:

40, 30, 20, 10

The proportions must be expressed as decimals and must total 1.

Entering Proportions as Expected Counts

Expected counts must be on the same frequency scale as the observed counts.

For a sample of 200 with an expected proportion of 0.30, enter an expected count of 60—not 0.30—when Expected Counts is selected.

Requiring Expected Counts to Be Whole Numbers

Observed counts must be whole numbers. Expected counts do not have to be whole numbers.

For example:100(1838)=47.3684100\left(\frac{18}{38}\right)=47.3684100(3818​)=47.3684

An expected count of 47.3684 is valid.

Using Two Categorical Variables

A goodness-of-fit test does not evaluate relationships between variables. A contingency table involving variables such as gender and product preference requires a chi-square test of independence.

Ignoring the Total Expected Count

When expected counts are entered directly, their total must equal the observed sample size.

Treating a Nonsignificant Result as Proof of a Perfect Fit

Failing to reject H0H_0H0​ means there is insufficient evidence that the observed distribution differs from the expected one. It does not prove that the distributions are exactly identical.

Claiming Which Category Caused the Result Without Checking the Counts

The overall test determines whether the complete distribution differs significantly. Examine the individual category contributions and the observed-versus-expected differences to understand which categories contributed most strongly.

Frequently Asked Questions

What does the chi-square goodness-of-fit calculator calculate?

It calculates Pearson’s chi-square goodness-of-fit test for one categorical variable. The results include the chi-square statistic, degrees of freedom, p-value, critical value, expected counts, category contributions, assumption check, decision, and complete calculation steps.

Should I enter expected proportions or expected counts?

Select Expected Proportions when your expected values are probabilities expressed as decimals that total 1. Select Expected Counts when the predicted frequency for each category is already known and the counts total the observed sample size.

What does equal proportions mean?

Equal proportions means that every category is expected to have the same probability. With four categories, each expected proportion is 0.25. With five categories, each expected proportion is 0.20.

Can expected counts contain decimals?

Yes. Expected counts are theoretical values and may contain decimals. Observed counts must be whole numbers because they represent actual observations.

Can I use raw data?

Yes. Raw-data mode accepts individual categorical responses and counts the number of observations in each detected category automatically. It does not automatically group continuous measurements into intervals.

Why must the expected proportions total 1?

The expected proportions describe the full probability distribution across all categories. Because every observation must fall into one of the categories, the probabilities must add up to 1.

How are the degrees of freedom calculated?

For a goodness-of-fit test with kkk categories:df=k1df=k-1df=k−1

A test with four categories has 3 degrees of freedom.

Is a chi-square goodness-of-fit test right-tailed?

Yes. Larger chi-square values indicate greater disagreement between the observed and expected distributions. The p-value is therefore the area to the right of the calculated statistic in the applicable chi-square distribution.

What happens when the p-value is less than the significance level?

Reject the null hypothesis. The sample provides sufficient evidence that the observed population distribution differs from the expected distribution.

What happens when the p-value is greater than the significance level?

Fail to reject the null hypothesis. The sample does not provide sufficient evidence that the observed distribution differs from the expected distribution.

What should I do when an expected count is below 5?

Interpret the chi-square approximation cautiously. Depending on the research design, you may need a larger sample or may combine categories that are logically similar. Do not combine categories when doing so would remove an important substantive distinction.

Advertisement
Joseph Mburu

About This Calculator

Prepared by Joseph Mburu · Updated on

Joseph is an applied statistician and data analyst with over 6 years of experience helping students, researchers, and professionals solve statistics and data analysis problems. He holds a degree in Applied Statistics and a Master’s degree in Data…

We aim to keep our calculators accurate, easy to use, and helpful for learning. Always check that your inputs match the assumptions of the method you are using.