Atlas
statminds
Categorical GLM (Alignment Model)The underlying model family class (e.g. GLM, linear model, categorical matrix, log-linear).Parametric ReferenceStatistical methods that assume a specific probability distribution family (typically normal).12-stage workflow

Chi-Square Goodness-of-Fit

The engine for Distribution Discovery. This model audits how well your observed sample frequencies align with a hypothesized or theoretical distribution, revealing if your data fits the expected blueprint.

Model familyCategorical GLM (Alignment Model)
Hypothesisomnibus
AliasesChi-Square One-Variable Test · Distributional Alignment Audit · Proportional Fit Test
G1
Alignment Audit
Determine if the proportions in your sample deviate significantly from a known standard or theoretical ratio.
G2
Theoretical Validation
Verify if your data follows a specific probability distribution (e.g., Uniform, Normal, or Mendelian).
G3
Representation Discovery
Quantify the 'Fit' of your data against a benchmark to identify systematic sampling biases.
1

What is it?

Chi-Square Goodness-of-Fit compares observed categorical counts against expected counts computed from a theoretical model or ratio.

2

When to use it

  • Single Nominal Variable: e.g. distribution of blood types.
  • Target Proportions: Compare observed proportions to historical averages or genetics ratios.
3

Core Idea

We measure sum of squared normalized differences between observed and expected counts:

X2 = Sum of (O - E)2 / E

If the observed counts (O) depart heavily from expected counts (E), the resulting statistic will be large, indicating a poor model fit.

4

Hypotheses

H0: Observed distribution fits the expected proportions.
Ha: Observed counts differ significantly from expected ratios.
5

How it works

  1. Sum counts to get N and calculate expected ratios.
  2. For each cell, calculate the squared error divided by expected.
  3. Sum these values to get X2.
  4. Find p-value using df = categories - 1.
6

Assumptions

📊 Adequate Cell Sizes: Expected count in each cell should be >= 5.
👤 Independence: Each observation belongs to exactly one category.
7

Effect Size

Measured via Cohen's w (equivalent to Cramér's V for 1D arrays): w = sqrt(X2 / N). Values of 0.1, 0.3, and 0.5 indicate small, medium, and large deviations.

8

Quick Example

CategoryObservedExpected (Equal)
Cat A4533.3
Cat B3033.3
Cat C2533.3
Interactive Sandbox

Goodness-of-Fit Live Laboratory

Vary the observed category counts and expected ratios to watch the X2 statistic and p-value change.

Observed Count A45
Observed Count B30
Observed Count C25

Exp Weight A2
Exp Weight B2
Exp Weight C2
Observed vs. Expected side-by-side distribution chartExpected shown as dotted bars
Group A4533Group B3033Group C2533
Calculations Output
MetricValue
Total Sample Size (N)100
Chi-Square Statistic (X2)6.5000
Degrees of Freedom (df)2
p-value0.0305
Shorthand Verdict

Significant The observed distribution departs significantly from expected ratios (p = 0.0305). We reject the null hypothesis.

The 12-Stage Precision Workflow
01Alignment Logic
Hypotheses
We test the null of 'Perfect Fit' (Observed = Expected) against the discovery of a significant 'Breaking of the Blueprint'.
02Expected Minima
Assumptions
Ensuring every categorical level has an expected frequency of at least 5—protecting the χ² math from small-sample collapse.
03Blueprint Choice
Diagnostics
Carefully defining the 'Expected Ratios'—whether it is a 'Uniform' (Equal Chance) distribution or a specific clinical benchmark.
04focus
Comparing the gender distribution of FlowMotion users against the national demographic to ensure representative recruitment.
05Exact Multinomial
Alternatives
Knowing when to switch to an Exact Multinomial test if the sample size is tiny and the categories are sparse.
06The Fit Strike
Significance
Calculating the total discrepancy between the 'Hypothesized' world and your 'Observed' data—yielding the χ² Fit statistic.
07The W-Index
Effect Size
Interpreting Cohen’s w to quantify the magnitude of the 'Misfit'—where 0.1 is subtle and 0.5 is a massive departure from theory.
08Category Depth
Sample Size
Determining the N required to ensure that even small deviations from the expected blueprint reach the threshold of discovery.
09The Proportional Narrative
Reporting
Reporting the observed vs. expected percentages: 'Our sample significantly deviated from the uniform distribution, χ²(df) = X.XX, p = .XXX.'
10Vector Logic
Software
Executing 'chisq.test(x, p = ...)'—ensuring the 'p' vector correctly represents the hypothesized proportions.
11focus
The fatal error of providing expected counts that don't sum to 100% or to the total sample N.
12focus
Tracing the model back to the early 20th-century development of goodness-of-fit forensics in biological and social research.
01Hypothesis test logic

Hypotheses

Pragmatic null and alternative hypotheses defined in mathematical notation.

A hypothesis is a question sharpened to a point. Ambiguity is the enemy of inference.
Logic Core
Null · H₀

H₀: Observed frequencies match expected distribution

Alternative · Hₐ

Hₐ: Observed frequencies differ from expected distribution

Why it matters omnibus

Tests whether sample distribution matches theoretical distribution. Uses chi-square distribution with (k-1) df.

02Model diagnostics

Assumptions

The core mathematical criteria needed to ensure that statistical testing remains unbiased and valid.

Build your analysis on rock, not sand. Verify the mathematical foundation before building the model.
Integrity Shield
6
Assumptions
0
Critical / High Severity
How to check
Quick
Review study design: ensure no hierarchical structure (e.g., students within classrooms), no time series autocorrelation, and random sampling from population.
Rigorous
If clustering suspected, calculate intraclass correlation (ICC). For time series, check autocorrelation function (ACF). Use runs test to detect systematic patterns.
If violated
Adjust for clustering using design effects, thin time series to reduce autocorrelation, or use specialized sampling weights. Alternatives: Use mixed-effects models for clustered data, GEE for correlated observations, or McNemar's test for paired data.
mcnemargee
How to check
Quick
Calculate expected frequencies E_i = n × p_i for each category i. Count categories with E_i < 5.
Rigorous
Simulate Type I error rate via Monte Carlo: generate data under H₀ with actual sample size and proportions, apply test, check if rejection rate ≈ α.
If violated
Combine adjacent or similar categories to achieve E_i ≥ 5, increase sample size if feasible. Alternatives: Use exact multinomial test for small samples (EMT package in R), G-test (likelihood ratio) which performs better with small frequencies, or bootstrap goodness-of-fit.
How to check
Quick
Verify that sum of observed frequencies equals total sample size. Check coding scheme for ambiguous cases.
Rigorous
Review raw data for missing/ambiguous categories. Cross-tabulate with secondary variables to detect misclassification.
If violated
Redefine categories to ensure mutual exclusivity; add 'Other' or 'Mixed' category to capture all observations. Recode ambiguous cases consistently. Alternatives: If categories naturally overlap, use different framework (e.g., set theory, latent class analysis).
How to check
Quick
Document theoretical rationale for expected proportions (e.g., genetic ratios, uniform distribution, census demographics) before data collection.
Rigorous
Check timestamps: was expected distribution documented before data were collected or analyzed? Review pre-registration or study protocol.
If violated
Use external data source for expected proportions (prior study, population census, theoretical model). Alternatives: If proportions are estimated from data, this is not a goodness-of-fit test; use mixture models, model comparison (AIC/BIC), or resampling-based approaches.
How to check
Quick
Calculate n/k ratio. For k = 4 categories, aim for n ≥ 20-40. For k = 10 categories, aim for n ≥ 50-100.
Rigorous
Conduct power analysis using G*Power or pwr package. For given effect size (Cohen's w), determine required n to achieve 80% power at α = .05.
If violated
Increase sample size, reduce number of categories by combining conceptually similar groups. Alternatives: Use exact tests for small samples, or report results as exploratory with appropriate caveats about power.
How to check
Quick
Verify data are raw counts (integers), not means, medians, percentages, or ordinal rankings. Confirm measurement scale is categorical.
Rigorous
Check data type in software. Ensure no decimal values unless representing aggregated data (which requires different approach).
If violated
If data are continuous, discretize into meaningful bins based on theory or natural cut-points. Alternatives: For continuous data, use Kolmogorov-Smirnov test, Anderson-Darling test, or Shapiro-Wilk for normality. For ordinal data, use ordinal-specific tests.
shapiro wilkkolmogorov smirnovanderson darling
03Residual Forensics

Diagnostics

Checking residual plots and indices to examine model deviations and ensure standard error integrity.

Trust, but verify. The outliers often hold more truth than the averages.
System Health
Essential checks
  1. Check expected vs. observed frequencies
  2. Verify sample size adequacy (n/k ratio)
  3. Calculate standardized residuals: (O_i - E_i) / sqrt(E_i) for each category
  4. Examine which categories contribute most to chi-square statistic
  5. Verify all expected frequencies ≥ 5
Recommended checks
  1. Create bar plot comparing observed vs. expected frequencies
  2. Plot standardized residuals to identify categories driving rejection
  3. Check for outliers or unusual patterns in residuals
  4. Assess whether deviations are systematic or random
  5. Bootstrap confidence intervals for effect sizes
  6. Sensitivity analysis: test with alternative expected proportions
  7. Q-Q plot of standardized residuals
  8. Power analysis for detected effect size
  9. Compare with G-test (likelihood ratio test) for robustness
04Live Instances

Applied Minds

Review concrete study examples, data layout guidelines, and copy executable syntax scripts.

Theory is the map. Practice is the terrain. Simulation bridges the gap.
Applied Wisdom
Example 01

Testing 9:3:3:1 Ratio in Dihybrid Cross

A classic genetics experiment crossing pea plants heterozygous for two traits (seed shape and color). Mendel's law predicts a 9:3:3:1 ratio for the four phenotypes. We test whether observed offspring frequencies match this theoretical distribution, including bootstrap confidence intervals and comprehensive diagnostics.

05Tactical Pivots

Alternatives

Structured fallback pathways for choosing alternative tests when normality or slopes requirements fail.

When the path is blocked, pivot. Rigor is not rigidity; it is the intelligent adaptation to reality.
Adaptive Strategy
Measurement Precision Ladder Ideal · Single-Variable Nominal
Ratio
Consider Kolmogorov-Smirnov or Shapiro-Wilk if you are testing for fit to a continuous distribution (e.g., Normal).
Logic Mismatch
Ordinal
Pivot to One-Sample Wilcoxon if the distance between ranks is meaningful for the fit.
Threshold Compression
Nominal
Maintain Goodness-of-Fit logic. The definitive audit for alignment with theoretical blueprints.
Peak Signal
Temporal Trajectory Audit Static Alignment Snapshot
Static Audit
Observed vs. Expected.
Stay with Chi-Square GoF. Verify if your sample fits the categorical law.
Sequential Shifts
Trajectory fit.
Pivot to Sequential Probability Ratio Tests (SPRT) to audit fit as data streams in.
Adaptive Technical Safeguards · adaptive safeguards
sparsity detected
  • Exact Multinomial Test — The required strike when categories have very low expected frequencies.
  • Category Collapsing — Merge adjacent rare categories to stabilize the Chi-Square basis.
estimated parameters
  • Lilliefors Correction — Apply if you estimated the population parameters from your own sample.
large sample inflation
  • G-Test (Likelihood Ratio) — Use for large datasets to maintain better additive properties across strata.
06Adjusted Comparisons

Post-hoc

Group mean comparisons and correction controls (e.g. Tukey HSD, Bonferroni) to protect against Family-Wise Error Rates.

The omnibus test opens the door; post-hoc analysis explores the room.
Forensic Detail
Adjusted Comparisons
  • Examine standardized residuals for each category (values > |2| indicate poor fit)
  • Collapse sparse categories and re-test
  • Compare with exact multinomial test for small samples
  • Use G-test (likelihood ratio) as alternative
  • Bootstrap confidence intervals for expected vs observed differences
Interpretation Guidelines

Chi-square goodness-of-fit tests overall distribution fit. Traditional post-hoc tests are not applicable.

07Standardized scale impact

Effect Size

Understanding effect sizes (e.g., Cohen's d, Partial Eta-Squared) and clinical impact benchmarks.

Significance is noise. Magnitude is the signal. Measure the impact, not just the probability.
Impact Magnitude
small

0.1

medium

0.3

large

0.5

formula

w = sqrt(sum((O_i - E_i)^2 / E_i) / n)

note

Measures overall deviation from expected distribution; independent of sample size

confidence intervals

Use bootstrap resampling (1000-2000 iterations) to obtain 95% CI for Cohen's w

small

0.07

medium

0.21

large

0.35

formula

V = sqrt(chi-square / (n * (k-1)))

note

Standardized effect size ranging 0-1; adjusts for number of categories

confidence intervals

Bootstrap CI preferred; alternatively use Fisher's z-transformation

interpretation

Individual category contributions to total chi-square statistic

formula

(O_i - E_i)^2 / E_i for each category i

use

Identifies which specific categories drive overall significance

note

Components sum to chi-square statistic; compare relative magnitudes

Recommended Metric: Cramér's V with bootstrap 95% CI
Small
0.2
Medium
0.5
Large
0.8
0.50
Cramér's V with bootstrap 95% CI
Recommended Measure
3
Available Metrics
ReportUse Cramér's V with bootstrap 95% CI to represent clinical impact magnitude.
08Statistical Power

Sample Size

Guidelines for minimum sample requirements and power analysis parameters.

An underpowered study is an ethical failure. Respect the data by collecting enough of it.
Power Protocol
Floor Requirements

A minimum of 5 participants per categorical level is required to ensure the 'Blueprint Fit' math reaches statistical authority.

Effect SizeParametersRequired n
Small Effectw=0.10 (Small)n ≈ 964
Medium Effectw=0.30 (Medium)n ≈ 108
Large Effectw=0.50 (Large)n ≈ 39
Key considerations

Blueprint Precision: If the 'Expected' proportions are based on a clinical standard with its own error, increase N by 10% to ensure your 'Misfit' detection is mathematically robust.

G*Power StrategyBenchmark: χ² tests → Goodness-of-fit: Contingency tables. Parameters: Effect size w, α = .05, Power = .80, df = 2 (for 3 categories). Note: Power is a function of the number of categories being audited.
09APA narrative blueprint

Reporting

How to compile statistical results into publication prose matching APA and journal style guides.

Data does not speak for itself. It requires a translator. Be clear, be precise, be honest.
Narrative Arc
Worked APA paragraph example
A chi-square goodness-of-fit test was performed to determine whether observed phenotype frequencies in F2 pea plants followed the expected 9:3:3:1 Mendelian ratio. The analysis included 556 offspring across four phenotypic categories. Expected frequencies in all categories exceeded 5, satisfying the assumption for valid chi-square approximation. The test revealed that observed frequencies were consistent with the expected Mendelian ratio, χ²(3) = 0.47, p = .925, Cramér's V = .013 (95% CI [.000, .045]). Standardized residuals ranged from -0.47 to 0.54, with no category showing significant deviation (|residual| < 2). Bootstrap analysis (1500 iterations) confirmed negligible effect size (Cohen's w = 0.013, 95% CI [0.000, 0.038]). These findings support the hypothesis of independent assortment for the two genetic loci examined.
Reusable template

A chi-square goodness-of-fit test was conducted to examine whether the observed frequencies matched the expected distribution. The test was significant, χ²(df) = X.XX, p = .XXX, suggesting that observed frequencies deviated from expected. Effect size was medium (Cramér's V = .XX, 95% CI .XX, .XX). Post-hoc examination of standardized residuals indicated that specific categories contributed most to the deviation.

10Exhibit Builder

Manuscript Lab

Copy standard summary tables and forensic reporting grids to outline analysis details.

Table 1: Chi-Square Goodness of Fit for Population Proportions
CategoryObservedExpectedχ² (Contribution)p
Group A1501255.0.012
Group B2002252.8
Group C1501500.0
Total5005007.8 (Omnibus)
Note. N = 500. Comparing observed sample to Census 2024 expected proportions.
χ² (7.8)Confirms Sampling Bias. The sample differs significantly from the census benchmark, specifically over-representing Group A.
Header glossary

The 'Benchmark'. The frequency we would see if our sample matched the known population exactly.

The Discrepancy Driver. Shows which specific category is deviating most from the population norm.

11Algorithmic Logic

Command Center

Syntax libraries and function parameters for executing calculations in stats packages.

Code is the modern laboratory. Clean execution ensures reproducible discovery.
Execution Engine
# 1. Execute Goodness of Fit
chisq.test(x = observed_counts, p = expected_proportions)
Library stack
R
stats
Python
scipy.stats
Elite Forensic Strike

Use this test to prove your sample is 'Representative'. If p > .05, your sample proportions match your target population proportions.

# Generate Narrative
report::report(chisq.test(counts, p=props))
12The Over-adjustment Trap

Common Mistakes

Analytical caveats and corrections to maintain modeling integrity.

Wisdom is learning from the failures of others. Anticipate the error before it occurs.
Defensive Logic
Why it's wrong
Chi-square is influenced by sample size; larger n inflates chi-square even with trivial deviations. A significant p-value does not indicate practical importance. With n=10,000, even a 1% deviation from expected can be 'significant'.
The correction
Always report and interpret effect size (Cramér's V or Cohen's w) with bootstrap 95% CI alongside p-value. A significant test with V < 0.1 suggests negligible practical effect despite statistical significance. Report: 'χ²(3)=15.2, p=.002, V=.039 (95% CI [.015, .068]), negligible effect'.
Why it's wrong
When expected frequencies fall below 5, the chi-square approximation becomes inaccurate, inflating Type I error rates up to 10-15% (vs. nominal 5%). Many analysts skip this critical check, relying on software defaults without verification.
The correction
Calculate and examine all expected frequencies BEFORE running test: E_i = n × p_i. If any E_i < 5, combine adjacent/similar categories (e.g., merge 'Other' with smallest substantive category), increase sample size, or use exact multinomial test (EMT::multinomial.test() in R). Document any category combinations.
Why it's wrong
Categories with very small expected frequencies (E_i < 1) or extreme imbalances (e.g., one category with 95% of observations) violate distributional assumptions even more severely than E_i < 5. Software may still compute results without warnings.
The correction
Restructure categories to achieve more balanced expected frequencies (ideally E_i ≥ 10). Consider whether rare categories are substantively meaningful or should be combined. If imbalance is inherent (e.g., rare disease), increase total sample size to ensure adequate frequencies or use exact tests.
Why it's wrong
Estimating expected proportions from the same data being tested is circular reasoning and invalidates the test. Common error: using sample proportions as 'expected' values, which guarantees no significant deviation. Expected distribution must be independent of observed data.
The correction
Define expected proportions BEFORE data collection based on: (1) theoretical distributions (e.g., Mendelian ratios, 9:3:3:1), (2) prior research, (3) population parameters (census data), or (4) null hypothesis of uniformity. Document source of expected proportions in methods section with citations or theoretical justification.
Why it's wrong
A significant omnibus test (p < .05) indicates some deviation exists but does not identify which categories differ. Analysts often stop at the p-value without investigating the pattern, missing key insights about nature of misfit (e.g., which phenotype drives genetic deviation).
The correction
Calculate standardized residuals (O_i - E_i)/sqrt(E_i) for each category. Values > 2 or < -2 indicate significant deviations (roughly p < .05 per category). Plot residuals and report: 'Category X showed significant over-representation (residual = 3.2, contributes 45% to χ²), while Category Y was under-represented (residual = -2.5, contributes 28% to χ²)'.
Why it's wrong
Goodness-of-fit tests examine one variable's distribution against a theoretical model (univariate). Testing association between two categorical variables requires chi-square test of independence (bivariate). Confusion arises because both use chi-square distribution but have different hypotheses and degrees of freedom.
The correction
Use chi-square goodness-of-fit only for single variable against expected distribution (e.g., 'Do birth months follow uniform distribution?'). Use chi-square test of independence (contingency table) for two-variable associations (e.g., 'Is treatment outcome associated with age group?'). Independence test has df = (r-1)(c-1), goodness-of-fit has df = k-1.
Why it's wrong
Standard chi-square goodness-of-fit ignores ordinal structure, potentially missing important patterns (e.g., monotonic trends) and losing statistical power. Test may fail to detect systematic linear deviations that ordinal tests would identify.
The correction
For ordered categories, consider partitioning chi-square into trend (linear) and departure (non-linear) components: χ²_total = χ²_trend + χ²_departure. Use Cochran-Armitage test for linear trend in proportions, or Jonckheere-Terpstra for ordinal alternatives. Alternatively, use ordinal logistic regression for richer modeling.
Why it's wrong
Researcher degrees of freedom: trying multiple category combinations until p < .05 is p-hacking. Inflates Type I error rate dramatically. Example: testing 5 different ways to group data until one yields p = .04.
The correction
Pre-specify category structure before analysis based on theory or prior research. If combining categories is necessary due to sparse cells, do so based on substantive similarity (not statistical convenience), document decision transparently, and apply Bonferroni correction if multiple grouping schemes tested. Better: report all attempted analyses or pre-register analysis plan.
13Academic Lineage

References

Scholarly lineage and citation keys grounding the statistical framework.

We stand on the shoulders of giants. Honor the source of the method.
Academic Lineage
[1]
[2]
[3]
[4]
[5]
[6]
A perfect fit is a mathematical ideal; a significant misfit is a clinical discovery. Find the break in the blueprint to find the story in the data.
The Interpretive Rigor Directive
statminds · Chi-SquareMind reference · v2.2 · updated 2026-01-1715 of 15 sections