Categorical

Chi-Square Goodness of Fit

Tests how closely the category counts of a single categorical variable match the counts expected from theory or from a known population distribution.

Method summary

The goodness-of-fit form of the chi-square test works with one column only. It counts how many people fall in each category of that column and weighs those counts against the distribution the researcher claims to expect. That expectation may come from outside the data, such as an official population composition or a set of proportions measured in an earlier wave; left unspecified, every category is assumed to hold an equal share. The statistic sums, over the categories, the squared gap between observed and expected divided by the expected value, which is why categories with small expected counts contribute more heavily than their size suggests. The null hypothesis is that the pattern of counts is consistent with the stated distribution, and rejecting it establishes a misfit without naming which category is over or under represented. Locating that category is a reading you make from the observed and expected tables. YouReply Analyze rescales your expected values onto the observed total regardless of how you typed them, so writing shares and writing counts lead to the same answer.

Which research questions does it answer?

  • Does the age composition of our sample match the composition recorded in address-based population registers?
  • Did the people who answered the invitation distribute across the four regions in the shares we anticipated?
  • Are the four product bundles chosen with equal frequency, or does one of them stand out?
  • Are complaint records spread evenly across the days of the week, or do they pile up on particular days?

When should you use it?

  • When a single categorical distribution is the object of interest and the comparison is against an external expectation rather than against a second variable.
  • When you want to check how closely the sample resembles the population on a categorical quota variable and to argue about representativeness on numerical grounds.
  • When the question is whether the options in a choice set attract equal interest, in which case the expected distribution field can simply be left empty.
  • When the categories may be ordered but only the pattern of counts is at issue and no test for trend is wanted.
  • When each participant falls into exactly one category; in select-all questions the counts exceed the number of participants and the test loses its footing.

Required variable types

  • A single categorical column, stored either as text labels or as integer category codes.
  • At least two categories must be present; a column that collapses to one category leaves zero degrees of freedom and the engine refuses to run.
  • The expected distribution is an optional text field: proportions or counts separated by commas or semicolons, with as many entries as there are observed categories.
  • Each row should stand for one participant, since the cells of a pre-aggregated frequency table are not read as people.
  • Bringing a continuous measure into this test means binning it first, which is done through the derived column feature on the Variable tab.

Key assumptions

Independence of observations
Every count has to come from a separate participant, and no participant may contribute to two categories at once. Designs that pool several answers from the same person inflate the frequencies and push the statistic upward.
Exhaustive and mutually exclusive categories
The set of categories should cover everyone and the categories must not overlap. A category split in two by inconsistent spelling also breaks the number of entries the expected distribution needs.
At least two categories
For the comparison to carry meaning, the number of observed categories must not fall below two.
Expected distribution matching the category count
If you type the expected distribution by hand, the number of values has to equal the number of categories that actually appear in the cleaned data. Supplying an expected value for a category nobody chose shifts every subsequent number.
Adequate expected counts
The chi-square approximation holds while the expected counts are not extremely small, and the familiar rule asks for an expected count of at least 5 in every category.

How YouReply checks these assumptions

  • Independence of observations: The panel does not check this assumption automatically; the researcher evaluates it.
  • Exhaustive and mutually exclusive categories: The panel derives the category list from the cleaned data and never merges spelling variants, so the category labels have to be inspected by eye in the grid on the Data tab.
  • At least two categories: This condition is enforced during the run, and a column that collapses to a single category stops the analysis with an error.
  • Expected distribution matching the category count: The mismatch is checked and the analysis halts with an error stating how many values were expected and how many arrived. Because missing values are dropped first, the category count can be lower than in the raw file, so the safest way to prepare the list is to read the category order off the observed frequency table.
  • Adequate expected counts: This method does report the minimum expected count as a field of its own, together with a flag saying whether the rule is satisfied. The flag is informational only: when the condition fails the analysis does not stop, the statistic is computed anyway, and nothing switches to an exact test. Reading the flag and deciding whether to merge sparse categories or to report the result with a caveat is left to the researcher.

How the analysis is run

  1. 1Drag your CSV or XLSX file onto the upload area and confirm in the grid on the Data tab that the columns were parsed as intended.
  2. 2Look over the category labels in the grid, since two spellings of the same category change both the degrees of freedom and the number of entries the expected distribution needs.
  3. 3On the Variable tab mark the column as nominal, declare the missing-value codes, and build a derived column if sparse categories need combining.
  4. 4On the Analysis tab type the method name into the search box. Methods that do not fit your data stay in the list, dimmed, with a plain-language note on why.
  5. 5In the parameter form pick the column to test, then either leave the expected distribution empty to test a uniform spread or type your own proportions separated by commas.
  6. 6Run the analysis. The results arrive as collapsible sections, and no method-specific chart is drawn for this method.
  7. 7Read the minimum expected count and the assumption flag first, then set the observed and expected tables against one another.
  8. 8Check the library call and version on the computation credits card, export the result to Excel, and find the run listed on the history tab.

Statistics and tables produced

Chi-square statistic
The sum of the scaled gaps between observed and expected counts. The larger it grows, the further the distribution sits from the expectation you stated.
Degrees of freedom
One less than the number of categories observed in the cleaned data. This value is not adjusted when the expected distribution was itself estimated from a parameter.
Significance value and significance flag
The p value from the chi-square distribution arrives together with a boolean flag stating whether it falls below the 0.05 threshold.
Observed frequency table
The count of people per category. When typing an expected distribution by hand, take the category order from this table.
Expected frequency table
The expected value for each category. Since your entries are rescaled onto the observed total whether written as shares or as counts, this table adds up to the number of observations.
Minimum expected count and assumption flag
The smallest of the expected counts, plus a flag saying whether all expected values clear the threshold of 5. The flag reports rather than blocks.
Total observations
The number of valid observations that entered the analysis once missing values were dropped; the effect size is scaled by this same number.
Cohen's w
The effect size, given as the square root of the chi-square value divided by the total number of observations. No verbal magnitude label accompanies it.

Effect size and confidence intervals

Cohen's w
Summarises how far the distribution departs from expectation with the sample size taken out, and takes values above zero. The customary reading in the literature treats roughly 0.1 as small, 0.3 as medium and 0.5 and above as large, but those thresholds are not applied by the engine and no interpretive label is printed with the result, so the judgement is yours to make in the write-up. As the sample grows the chi-square value and the p value sharpen on their own while Cohen's w stays put, which is why the practical weight of a finding is best argued through w.

No confidence interval of any kind is returned here. The chi-square statistic, the p value and Cohen's w are all reported as point estimates, and nothing is computed for the category proportions or for the gap between an observed and an expected share. If you need an interval around a single category's proportion, run the proportion test separately or work it out outside the panel.

Example research question and example result

The numbers below are a representative example, not data from a real study or a real user.

Research question
In an illustrative customer study, is the channel through which support requests arrive spread equally across four options?
Variables
Variable tested: support channel (in-app chat, telephone, electronic mail, social media) · Expected distribution: the field was left empty, so a uniform spread across four categories
Example result
420 valid records were tested. Observed counts were 132 for in-app chat, 118 for telephone, 96 for electronic mail and 74 for social media. With a uniform distribution assumed, every category expects 105, so the minimum expected count is also 105 and the assumption flag reports the rule as satisfied. Chi-square = 18.48, degrees of freedom = 3, p = 0.0004, Cohen's w = 0.21.
Interpretation
The assumption of four equal shares is rejected: the percentages came out at 31.4, 28.1, 22.9 and 17.6, and across 420 records a spread like that would rarely occur if the channels really were used equally. At 0.21, Cohen's w places the divergence between small and medium, so channel use is uneven without any one channel dominating. Because the test names no culprit, the reading had to come from comparing the two tables, where social media, 31 below expectation, contributes most to the total. It is also worth discussing whether differences in how reachable each channel is have shaped the records. The figures are illustrative.

Real output on a sample dataset

The results below were produced by the analysis engine from this data file. Changing the variable changes the research question as well; every run was computed in advance, so the page sends no request to the engine.

Variable examined

General customer survey (synthetic)

A wide survey of three hundred respondents: two and three category grouping variables, continuous measures, a five point ordinal scale, a binary purchase outcome, a four category brand choice, three repeated measurements, paired binary questions, three raters, four price questions and deliberately empty cells.

Rows
300
Columns
respondent_id, gender, education, region, age, income, satisfaction, service_score, price_score, quality_score, loyalty, nps_score, purchased, brand_choice, satisfaction_level, pre_score, post_score, measure_1, measure_2, measure_3, use_before, use_after, use_followup, rater_1, rater_2, rater_3, price_too_cheap, price_cheap, price_expensive, price_too_expensive, feedback_score, followup_rating
Download the dataset as CSV

The data is synthetic: it comes from a fixed random seed, not from a real study. The values below were produced by the analysis engine from this file, so uploading the same file to the panel gives the same results.

Research question: Are the respondents spread evenly across the four regions?

Analyzed column
region
column
region
Chi-square
0.667
Degrees of freedom
3
p value
0.881
Valid observations
300
Effect size w (Cohen)
0.047
Minimum expected frequency
75
Expected frequency assumption met
Yes
Significant
No

Observed frequency

Aegean
76
Central Anatolia
69
Marmara
77
Mediterranean
78

Expected frequency

Aegean
75
Central Anatolia
75
Marmara
75
Mediterranean
75

Computation credits: scipy 1.18.0 · statsmodels 0.14.6 · scikit-learn 1.9.0 · numpy 2.5.1 · pandas 3.0.5 · semopy 2.3.11 · 89fc29a · Data seed: 20260914

How to report the result

The distribution of support channels departed significantly from uniform, chi-square(3, N = 420) = 18.48, p < .001, Cohen's w = .21, with a minimum expected count of 105 satisfying the expected-count criterion.

An example sentence close to APA style; the numbers are representative.

When you should not use it

  • It says nothing about a relationship between two variables, so a question about one classification varying with another calls for the test of independence instead.
  • The expected-count criterion is reported but never applied, and a result is produced even when the flag comes back negative, which leaves reading the flag up to the researcher.
  • Degrees of freedom are not reduced when the expected distribution was estimated from the same data, so an externally sourced distribution makes the interpretation sturdier.
  • Any ordering among the categories goes unused, leaving the test insensitive to a rising or falling trend.
  • No residuals are returned to identify which category is responsible for the misfit, so the category-level reading is done by hand.
  • With many categories each holding few observations the statistic becomes unstable, and nothing should be reported before a conceptually justified merge.

What to use when the assumptions are not met

  • Chi-Square Test of IndependenceWhy: When the question concerns whether two categorical variables are independent rather than how one distribution fits an expectation.
  • Proportion TestWhy: When interest narrows to a single category's share and testing that share against a fixed value is enough.
  • Frequency DistributionWhy: When no test is needed and describing the spread through percentages and cumulative percentages will do.
  • WeightingWhy: When a misfit has been established and the aim turns to bringing the sample closer to the population composition.

Frequently asked questions

Should I enter the expected distribution as percentages or as counts?
Either is accepted and neither changes the answer, because whatever you enter is rescaled onto the observed total. Percentages need not even add up to exactly one hundred, since the values are read relative to one another. The only things that matter are that the order of the values lines up with the category order in the observed frequency table and that you supply as many values as there are categories.
What exactly is tested if I leave the expected distribution empty?
An empty field means every category is assumed to hold an equal share, so what gets tested is fit to a uniform spread. That is often a sensible opening question, for instance whether the options in a choice set attract comparable interest. Where the issue is resemblance to a population, uniformity is usually the wrong baseline and the external proportions have to be typed in.
Some categories expect fewer than 5 cases. Will the analysis stop?
It will not. The method reports the minimum expected count and a flag for whether the criterion holds, yet the statistic is computed and printed even when that flag is negative. Nothing moves to an exact probability calculation on its own. When the flag is negative, weigh merging categories on defensible grounds and rerunning, or reporting the result with the limitation spelled out.
How do I work out which category causes the misfit?
No category-level follow-up or residual table is returned. The workable route is to read the observed and expected tables side by side, divide each squared gap by its expected value, and see which category contributes most to the total. Including the percentages in the write-up lets your reader repeat that comparison.

References

  • Agresti, A. (2018). An Introduction to Categorical Data Analysis
  • Field, A. (2018). Discovering Statistics Using IBM SPSS Statistics
  • Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences
  • scipy.stats.chisquare documentation

Try it with your own data

The free plan includes 50 analysis runs a month and needs no card.