AI Glossary / Statistics and probability / Intermediate

Chi-square test

Definition

A chi-square test is a statistical hypothesis test that compares a calculated statistic with a chi-squared reference distribution. In common categorical-data applications, Pearson's chi-square test measures differences between observed and expected counts. It can test whether category frequencies fit specified probabilities or whether two categorical variables are independent, subject to the assumptions of the selected procedure.

What it means

Counts fluctuate even when a proposed model is correct. The test asks whether the observed discrepancies are unusually large under that model. Expected counts are not necessarily equal: they follow the stated probabilities or an independence model derived from table margins. The term also covers other tests using a chi-squared reference distribution, including certain variance tests. The data type, null hypothesis and degrees of freedom must therefore be specified rather than relying on the name alone.

How it works

For Pearson's count statistic, calculate the sum of (observed minus expected) squared divided by expected across relevant cells. In a goodness-of-fit test with k categories and fully specified probabilities, the usual degrees of freedom are k - 1. Estimating parameters from the same data can change the reference distribution or degrees of freedom. In a standard r-by-c independence table, expected counts are row total times column total divided by the grand total, and degrees of freedom are (r - 1)(c - 1). Assess expected-count adequacy and independence of observations. Use exact or suitable simulation methods when the asymptotic approximation is inappropriate.

Three practical examples

  • Quality monitoring: compare observed defect categories with a prespecified distribution to identify a possible change in process patterns.
  • Customer research: examine whether contact channel and response category are associated in appropriately collected data.
  • AI evaluation: compare a model's predicted category frequencies with a specified reference distribution, while recognizing that a frequency match alone does not establish accurate predictions for individuals.

Think of it this way

Think of comparing how items actually filled several labeled boxes with how a model expected them to be distributed. The test combines the discrepancies while allowing for their expected scale. It signals incompatibility with a particular allocation model, not the reason for that incompatibility.

Worked example

Suppose a hypothetical random sample of 120 independent service requests is classified into three mutually exclusive categories. A prespecified null model assigns each category probability one-third, so each expected count is 40. The observed counts are 60, 30 and 30. Pearson's statistic is (60 - 40) squared/40 + (30 - 40) squared/40 + (30 - 40) squared/40 = 10 + 2.5 + 2.5 = 15. No category probabilities were estimated from these data, so the reference has 3 - 1 = 2 degrees of freedom. For two degrees of freedom, the upper-tail probability is exp(-15/2), approximately 0.000553. Under the stated sampling model, this is strong evidence against equal category probabilities. It is not the probability that the null hypothesis is true. The first category's observed proportion is 60/120 = 50%, compared with the null value of about 33.3%, providing an interpretable descriptive difference. The omnibus test alone does not justify every possible post-hoc comparison without further analysis.

Illustrative case study

Fictional case: Harbor Service Analytics examines whether complaint type differs by support channel. Analysts build a count table, check that one customer's repeated tickets are not being treated as independent people, and inspect sparse categories before selecting a test. They report the table, an appropriate association measure and uncertainty alongside significance. A detected association prompts investigation of customer mix and channel routing rather than an immediate causal claim. This fictional case illustrates responsible interpretation and does not report a real service finding.

Common misconceptions and mistakes

Do not enter percentages as though they were raw counts without their denominators. A large sample can make a small, operationally unimportant difference statistically significant. A nonsignificant result does not prove exact independence or perfect model fit. Sparse expected cells, clustered observations, paired responses and complex survey designs can invalidate a simple calculation. Structural zeros require special treatment because some combinations are impossible. A two-by-two continuity correction or alternative exact procedure can produce a different p-value, so report the actual method rather than describing all results as the same chi-square test.

Business use

Businesses can use chi-square procedures for categorical comparisons when the question and sampling design fit the method. Define categories before inspecting results, preserve counts and denominators, and distinguish a descriptive dashboard from a formal inferential study. For AI-generated analyses, verify how expected counts and degrees of freedom were obtained. Pair significance with effect sizes, practical consequences and checks for confounding. If many tables or subgroup comparisons are examined, account for multiple testing and separate exploratory findings from planned confirmation.

People also ask

Must expected counts be equal?

No. They depend on the null hypothesis; an independence table usually has unequal expected counts.

Does a significant test prove causation?

No. It identifies a discrepancy or association under a specified model.

Can it analyze paired before-and-after categories directly as independent groups?

A simple independent-observation test is generally unsuitable; a method reflecting the paired design is needed.

Check your understanding

Q: Why are there two degrees of freedom in the worked example?

Answer: A: There are three categories, but their counts must sum to the fixed total of 120. With fully specified null probabilities, only two count deviations can vary freely.

Related terms

  • Chi-squared distribution
  • Contingency table
  • Goodness-of-fit
  • Degrees of freedom
  • independence test
  • expected count
  • Fisher's exact test and Cramér's V
  • inferential question and measures of association

Learn next

reconstruct an independence table's expected counts from its margins. Then compare a large and small sample with the same proportions to see how evidence changes while the descriptive effect remains the same. Examine exact alternatives for sparse tables.

More in Statistics and probability

  • Chain linking - Chain linking constructs an index or volume series by connecting changes measured between successive periods.
  • Chauvenet's criterion - Chauvenet's criterion is a traditional rule for flagging an unusually distant observation under an assumed normal distribution.
  • Chen distribution - The Chen distribution is a continuous probability model for positive lifetimes that can represent either increasing or bathtub-shaped hazard rates.
  • Choice set - A choice set is the collection of alternatives available to a decision-maker for a particular decision.
  • Class interval - A class interval is a defined range of numerical values used to group observations in a frequency table or histogram.
  • Clifford's method - Clifford's method is a median-based procedure for calculating robust control limits for an individuals control chart.

Sources

Sources: SciPy, Pearson goodness-of-fit test and assumptions: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html ; SciPy, contingency-table independence testing: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chi2_contingency.html ; Penn State STAT 200, chi-square tests: https://online.stat.psu.edu/stat200/Lesson11 .

Previous: Chi-square automatic interaction detection Next: Chi-squared distribution

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer