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.
- Select Summary Data.
- Enter the significance level, α.
- Give the categorical variable a descriptive name.
- Choose the expected distribution.
- Enter each category and its observed count.
- Add more categories as needed.
- 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:
- Select Raw Data.
- Enter the significance level.
- Enter a name for the categorical variable.
- Paste the individual responses.
- Choose equal proportions, expected proportions, or expected counts.
- Enter the expected values when required.
- 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 i 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 k categories, the hypotheses may be written as:
H₀: 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.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=∑Ei(Oi−Ei)2
Where:
- χ2 is the chi-square test statistic.
- Oi is the observed count in category i.
- Ei is the expected count in category i.
- ∑ 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=npi
Where:
- n is the total sample size.
- pi is the expected proportion for category i.
For example, suppose a sample contains 200 observations and a category is expected to contain 30% of the population:E=200(0.30)=60
The expected count is 60.
Expected Counts for Equal Proportions
When k categories are expected to occur equally often:pi=k1
Therefore:Ei=kn
For a sample of 120 observations distributed equally across four categories:Ei=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=k−1
Where k is the number of categories.
For four categories:df=4−1=3
For six categories:df=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 method | Expected proportion |
|---|---|
| Campus bookstore | 0.40 |
| Publisher website | 0.30 |
| Online marketplace | 0.20 |
| Rental service | 0.10 |
At the beginning of a new academic year, a random sample of 200 students produces these results:
| Purchasing method | Observed count |
|---|---|
| Campus bookstore | 104 |
| Publisher website | 52 |
| Online marketplace | 28 |
| Rental service | 16 |
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.10
H₁: At least one population proportion differs from its historical value.
Step 2: State the Significance Level
α=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)=80
For the publisher website:E2=200(0.30)=60
For the online marketplace:E3=200(0.20)=40
For the rental service:E4=200(0.10)=20
The observed and expected counts are:
| Purchasing method | Observed, O | Expected, E |
|---|---|---|
| Campus bookstore | 104 | 80 |
| Publisher website | 52 | 60 |
| Online marketplace | 28 | 40 |
| Rental service | 16 | 20 |
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:80(104−80)2=7.2000
For the publisher website:60(52−60)2=1.0667
For the online marketplace:40(28−40)2=3.6000
For the rental service:20(16−20)2=0.8000
The calculations can be summarized as follows:
| Purchasing method | Observed, O | Expected, E | (O−E)2/E |
|---|---|---|---|
| Campus bookstore | 104 | 80 | 7.2000 |
| Publisher website | 52 | 60 | 1.0667 |
| Online marketplace | 28 | 40 | 3.6000 |
| Rental service | 16 | 20 | 0.8000 |
Add the category contributions:χ2=7.2000+1.0667+3.6000+0.8000 χ2=12.6667
The degrees of freedom are:df=k−1 df=4−1=3
Therefore:χ2(3)=12.6667
Step 4: Find the P-Value and Critical Value
For χ2=12.6667 with df=3:p=0.005416
At α=0.05 and df=3:χcritical2=7.8147
Step 5: Make the Decision
Using the p-value:0.005416<0.05
Using the critical value:12.6667>7.8147
Both methods lead us to reject H0.
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:
| Category | Observed count | Expected proportion |
|---|---|---|
| Campus bookstore | 104 | 0.40 |
| Publisher website | 52 | 0.30 |
| Online marketplace | 28 | 0.20 |
| Rental service | 16 | 0.10 |
The calculator returns:
- χ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.25
H₁: At least one population proportion is not 0.25.
Step 2: State the Significance Level
α=0.05
Step 3: Count the Raw Responses and Calculate the Test Statistic
Counting the observations produces:
| Study location | Observed count |
|---|---|
| Library | 18 |
| Residence Hall | 11 |
| Student Center | 7 |
| Off Campus | 4 |
| Total | 40 |
Because equal proportions are expected:E=kn E=440=10
The expected count is 10 for every location.
| Study location | Observed, O | Expected, E |
|---|---|---|
| Library | 18 | 10 |
| Residence Hall | 11 | 10 |
| Student Center | 7 | 10 |
| Off Campus | 4 | 10 |
Calculate the category contributions.
For Library:10(18−10)2=6.4000
For Residence Hall:10(11−10)2=0.1000
For Student Center:10(7−10)2=0.9000
For Off Campus:10(4−10)2=3.6000
Add the contributions:χ2=6.4000+0.1000+0.9000+3.6000 χ2=11.0000
The degrees of freedom are:df=4−1=3
Therefore:χ2(3)=11.0000
Step 4: Find the P-Value and Critical Value
For χ2=11.0000 with df=3:p=0.011726
At α=0.05 and df=3:χcritical2=7.8147
Step 5: Make the Decision
The p-value is less than the significance level:0.011726<0.05
The calculated chi-square statistic is also greater than the critical value:11.0000>7.8147
Therefore, reject H0.
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:
- Detects the four categories.
- Counts the observations in each category.
- Assigns an expected proportion of 0.25 to each category.
- Calculates an expected count of 10 for each category.
- Returns χ2(3)=11.0000, p=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.
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.
When the p-value is below .001, report p<.001 rather than p=.000.
Chi-Square Goodness of Fit vs Test of Independence
These tests use the same general chi-square formula but answer different questions.
| Feature | Goodness-of-fit test | Test of independence |
|---|---|---|
| Number of variables | One categorical variable | Two categorical variables |
| Main question | Does the observed distribution match an expected distribution? | Are the variables associated? |
| Data structure | One set of category counts | Contingency table |
| Expected counts | Based on specified proportions or counts | Calculated from row and column totals |
| Degrees of freedom | k−1 | (r−1)(c−1) |
| Example | Are 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(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 H0 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 k categories:df=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.
