Understand the idea
Imagine you have a die you suspect might be unfair, and you roll it 60 times. If it were perfectly fair, you'd expect each of the six faces to come up 10 times. This test compares what you actually OBSERVED against what you'd EXPECT under some hypothesized pattern (for fair rolls, an equally-likely 'uniform' pattern across all categories) and asks whether the difference is bigger than ordinary random variation would explain. In KernelStats you can test equal shares (the default) or your own proportions: type them in Expected shares, one value per category, in the order the form lists the categories (numbers smallest first, words alphabetically); check the expected counts on the card, because a wrong order tests a different pattern without any error. Ratios such as 9:3:3:1 are scaled to add to 1.
The test statistic adds up, across every category, the squared difference between observed and expected counts, scaled by how big the expected count was. A large total means the observed pattern departs substantially from what you hypothesized; a small total means the data are broadly consistent with your hypothesis (though consistent is not the same as PROVEN true; a non-significant result never proves the hypothesized distribution is exactly correct).
Cohen's w measures the SIZE of the mismatch, separate from whether it's statistically significant: 0.10 is conventionally 'small', 0.30 'medium', 0.50 'large'. With a big enough sample, even a trivially small w can produce a significant p-value: always look at w itself, not just whether the test crossed the significance threshold.
It is also called the GOF test, or Pearson's chi-square test (after Karl Pearson, who also gave his name to the correlation coefficient, a different method).
Practitioner explanation
KernelStats computes chi2 = sum((O_i - E_i)^2 / E_i) with E_i = N*p_i and p_i = 1/k for k categories by default, or p_i from the Expected shares input (one value per level in level order, rescaled to sum to 1, as R's chisq.test(x, p = ..., rescale.p = TRUE) does; a wrong count, a non-number or a zero share for an observed level is a clear error), df = k-1, via scipy.stats.chisquare. Cohen's w = sqrt(chi2/N) is reported with the standard 0.10/0.30/0.50 verbal benchmarks. The expected-counts-per-category >= 5 rule of thumb is ACTUALLY CHECKED (not just mentioned) and reported as an explicit assumption check, naming the minimum expected count and how many categories fall below 5 when the condition fails, with concrete remedies named directly (combine sparse categories, or use an exact multinomial test: not in KernelStats; in R, EMT::multinomial.test or chisq.test(x, p = ..., simulate.p.value = TRUE)).
An alternative test statistic is computed and reported alongside the primary result for cross-checking: the likelihood-ratio (G-test), asymptotically equivalent to Pearson's chi-square but computed via a different route (SciPy's power-divergence function with the log-likelihood option); close agreement between the two is a form of built-in confirmation that the primary chi-square result is not an artifact of that specific statistic's approximation. With exactly two categories this test is the one-proportion z-test without continuity correction (χ² = z²; R's prop.test(..., correct = FALSE) gives the same X²). It approximates the exact binomial test, which is preferred at small samples because it avoids the approximation; on 165 female and 168 male penguins the chi-square p is .869 and the exact p is .913.
When to use it
Consider it when
You have one categorical variable with two or more categories and want to test whether its observed frequencies match equal shares or proportions you specify in advance (a 9:3:3:1 cross, last year's market shares).
Use caution when
Expected counts fall well below 5 in multiple categories (combine sparse categories that belong together; an exact multinomial test is the textbook remedy, but KernelStats does not have one), or exactly two categories are involved and the sample is small (use the Proportion Test with one proportion, whose card gives the exact binomial p-value).
Formulas and symbols
Pearson chi-square goodness-of-fit statistic
O_i the observed count in category i; E_i = N*p_i the expected count from the hypothesized probability p_i and total N.
Cohen's w (effect size)
Cohen's benchmarks: 0.10 small, 0.30 medium, 0.50 large.
Likelihood-ratio (G-test) alternative
Asymptotically equivalent to the Pearson chi-square statistic; reported as a cross-check alongside the primary result.
Assumptions and checks
- Adequate expected counts (chi-square). When too many categories have an expected count below 5, the chi-square distribution is a poor approximation to the goodness-of-fit statistic's true sampling distribution, making the p-value unreliable.
In KernelStats: Checked directly: the card computes the minimum expected count across categories and the count of categories below 5, flagging it as a warning and recommending combining sparse categories or an exact multinomial test (an exact multinomial test is not in KernelStats).
- Independence of observations. The goodness-of-fit test assumes each observation is counted once and independently of the others; violating this invalidates the test regardless of the expected-count check.
In KernelStats: Not checked by KernelStats; assumed by design: each observation is counted once.
Alternatives
- Proportion Test (Proportion Test (z-test)) with Kind of test set to one_proportion. There are exactly two categories: the question is then one proportion against a hypothesized value. In Analyze > Categorical > Proportion Test (z-test), set Kind of test to one_proportion, choose the two-category column as the yes/no column, the category you are testing in Value to count, and type the hypothesized share in Proportion to compare with; the card names the counted category (for example "Share of male"), gives the z-test (the same p-value as this chi-square) and lists the exact binomial test, which is the one to read when there are fewer than about 10 of either category.
- Chi-Square Test of Independence. You have TWO categorical variables and want to test whether they are associated with each other, rather than testing one variable against a hypothesized distribution.
Worked example
Scenario
Testing whether the three penguin species are equally common (uniform hypothesis) in a sample of 344 birds (152 Adelie, 68 Chinstrap, 124 Gentoo).
Result
χ²(2) = 31.91, p < .001, Cohen's w = 0.305 (a medium effect by Cohen's benchmarks).
Interpretation
The species are clearly not equally represented in this sample: the significant p-value and the Cohen's w show a departure of medium size by Cohen's benchmarks; whether that matters depends on the question being asked.
Dataset: penguins.csv
Common misconceptions
Misconception
A significant chi-square goodness-of-fit test tells you how large or important the deviation from the hypothesized distribution is.
Correction
Statistical significance only says the observed deviation is unlikely under the hypothesized distribution: it says nothing about the SIZE of that deviation. With a large enough sample, even a trivially small departure (a small Cohen's w) can produce a significant p-value. Read Cohen's w itself, not just whether the test crossed the significance threshold, to judge practical importance.
Read more: Misconception: statistical significance means practical importance
Misconception
A non-significant chi-square goodness-of-fit test proves the categories truly follow the hypothesized distribution exactly.
Correction
A non-significant result means the data did not provide strong evidence AGAINST the hypothesized distribution: it does not prove the distribution is exactly correct. Absence of evidence is not evidence that the null hypothesis is true.
Read more: Misconception: a non-significant result proves there is no effect
References
- NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.11 Chi-square goodness-of-fit test, NIST/SEMATECH (2012), §1.3.5.11.
- Statistical Power Analysis for the Behavioral Sciences, Cohen, J. (1988).
