- Learn
- Mathematics
- Statistics
- Introduction to Statistics
- Chi-Square Test
Chi-Square Tests
BeginnerLesson 11 of 12 in Introduction to Statistics Course
What you will learn
- Describe the family of chi-square distributions, find tail areas and critical values, and see how one statistic measures the distance between the counts you observe and the counts a hypothesis predicts.
- Describe the chi-square distribution and find its tail areasRecognize the shape of chi-square curves, connect it to the degrees of freedom, and find right-tail areas and critical values with a table or technology.
- Compare observed counts with expected countsOrganize categorical data as counts, find the counts a hypothesis predicts, and combine the differences into the chi-square statistic.
- Describe the chi-square distribution and find its tail areas
- Carry out a chi-square goodness-of-fit test from the hypotheses and expected counts through to a conclusion in context, and explain which categories drive the result.
- Set up the hypotheses and expected countsTurn a claim about category proportions into hypotheses, compute the counts the claim predicts for the sample, and find the degrees of freedom.
- Carry out the goodness-of-fit testCheck the conditions, compute the statistic, degrees of freedom and p-value, and state the conclusion in the context of the question.
- Interpret the result and follow upFind the categories that contribute most, handle small expected counts and estimated parameters, and word the conclusion without claiming more than the test shows.
- Set up the hypotheses and expected counts
- Summarize two categorical variables in a contingency table, compute the counts expected under no association, and carry out and interpret the tests of independence and homogeneity.
- Read a two-way table and describe associationOrganize two categorical variables in a contingency table and use conditional percentages to describe whether and how they are associated in the sample.
- Find expected counts and degrees of freedom for a two-way tableCompute the count each cell would have if the variables were not associated, use the table's totals to check them, and find the degrees of freedom.
- Carry out and interpret the test of independenceTest whether two categorical variables measured on one sample are associated in the population, and explain what the result does and does not show.
- Carry out and interpret the test of homogeneityCompare the distribution of one categorical variable across several populations or treatment groups, and tell this design apart from the test of independence.
- Read a two-way table and describe association
- Decide which chi-square procedure fits a question and a study design, judge whether its conditions hold and what to do when they fail, report results responsibly, and use the chi-square distribution to test a claim about one population variance.
- Check the conditions and handle small expected countsExplain why the chi-square tests on counts need random, independent count data with large enough expected counts, and know what to do when a condition fails.
- Choose the right test and report the resultsMatch a question and a study design to the right test, connect chi-square tests with z tests, and report results with their size and limits.
- Test a claim about one population varianceUse the chi-square distribution to test a claim about the variance or standard deviation of a normal population, with right-, left- or two-tailed alternatives.
- Check the conditions and handle small expected counts
Chi-Square Test study guide
1Understand the curve and the statistic
Counts rarely match a prediction exactly. A useful test needs a way to measure the gaps and a reference curve that shows how much variation to expect. Chi-square methods provide both. Start by reading the family of curves and their tail areas, then build the statistic from observed and expected counts. The degrees of freedom connect the calculation to the curve; the sample size explains why identical percentages can carry different amounts of evidence.
1.1 Read chi-square curves and tail areas
A chi-square curve describes how a nonnegative statistic varies from sample to sample. Its shape depends on the degrees of freedom, usually shortened to df. Read the symbol as “chi-square”; “chi-squared” means the same thing.
Where the curve comes from
Start with independent standard normal variables, each centered at 0 with standard deviation 1. Square each value and add the squares. With variables, the sum has a chi-square distribution with df. Squares cannot be negative, so neither can their sum.
For 1 or 2 df, the curve is highest near the left edge and falls toward the right. For 3 or more df, it rises from 0 to a peak at and then falls with a long right tail. Increasing df moves the curve right, spreads it out, and makes it more symmetric. At large df it looks close to a normal curve.
The mean is df, the variance is , and the standard deviation is . At 4 df these are 4, 8, and about 2.83. The mean lies to the right of the peak because large values in the right tail pull it upward. A statistic of 8 is above the mean at 4 df but below the mean at 10 df: its size has meaning only alongside its df.
Turn a statistic into an area
The total area under the curve is 1. In tests of categorical counts, large statistics represent large gaps from the null model. The p-value is the area to the right of the observed statistic:
With 4 df and a statistic of 3, that area is about 0.558. A value at least this large is common under the null model. No doubling is needed: the right tail already represents all discrepancies at least this large, in either direction in the original counts.
A critical value marks the cutoff for a selected tail area. For a 0.05 right-tail area, the values are:
| df | Critical value |
|---|---|
| 1 | 3.841 |
| 2 | 5.991 |
| 3 | 7.815 |
| 4 | 9.488 |
| 5 | 11.070 |
| 10 | 18.307 |
Find the df row first, then the tail-area column. With 3 df, 10.19 lies between 9.348, the cutoff for 0.025, and 11.345, the cutoff for 0.01. Thus . A larger cutoff leaves a smaller area to its right. Check whether a table labels left areas or right areas before reading it.
Use technology
In Excel or Google Sheets, CHISQ.DIST.RT(3, 4) returns about 0.558. CHISQ.INV.RT(0.05, 4) returns about 9.488. CHISQ.DIST(3, 4, TRUE) gives the left area, about 0.442. In R, use pchisq(3, 4, lower.tail = FALSE) for the right area. On a TI-84, use χ²cdf with lower limit 3, upper limit 1E99, and 4 df.
The 1-df case connects to a familiar normal cutoff: . Squaring combines the two normal tails beyond −1.96 and +1.96 into the single chi-square right tail beyond about 3.84.
Key Takeaways
- A chi-square value is nonnegative; df determines the curve used to interpret it.
- The mean is df and the standard deviation is .
- Count tests use the right-tail area as the full p-value.
- A table brackets an area; technology can calculate it more precisely.
- Check the df and the tail convention before using a critical value.
1.2 Measure gaps between counts
Categorical data sort individuals into groups, such as car, public transit, bike, and walk for a commuter’s main way to work. Categories must cover everyone and must not overlap. Each individual contributes one count to one category of each variable.
Observed and expected counts
An observed count, , is what the sample contains. An expected count, , is what the null hypothesis predicts on average for a sample of the same size. If a category has claimed proportion in a sample of size , then . Both sets of counts must add to . Expected counts describe an average over possible samples, so values such as 312.75 are valid. Keep them as decimals.
The chi-square statistic combines the gaps:
For every category, subtract expected from observed, square the gap, divide by expected, and add. Squaring stops positive and negative gaps from canceling. Dividing by expected puts the gap on a scale that reflects the category’s size. A gap of 10 contributes 5 when 20 are expected, since . The same gap contributes only 0.1 when 1,000 are expected.
A coin example
A coin lands heads 58 times and tails 42 times in 100 independent tosses. Under a fair-coin hypothesis the expected counts are 50 and 50.
| Result | Observed | Expected | Contribution |
|---|---|---|---|
| Heads | 58 | 50 | |
| Tails | 42 | 50 |
The sum is . There are 1 df, and the right-tail area is about 0.11. At a 0.05 significance level, do not reject the fair-coin hypothesis: these tosses give no convincing evidence of unfairness.
The one-proportion z statistic is . Squaring gives . For two categories, the uncorrected chi-square test agrees with the two-sided one-proportion z test. Squaring removes the sign, which is why the chi-square result corresponds to a two-sided z test.
What the statistic and p-value mean
The statistic is 0 exactly when every observed count equals its expected count. Large values indicate disagreement with the null model. With large enough expected counts, the statistic’s null distribution is approximately chi-square. The p-value asks how often a statistic at least this large would occur assuming the null hypothesis is true. It does not assign a probability to the truth of that hypothesis.
Use the chosen significance level : reject when ; otherwise, do not reject. The test needs actual counts. If the same 58% heads comes from 200 tosses, the observed counts are 116 and 84, the expectations are 100 each, and the statistic doubles to 5.12, with p about 0.024. Treating percentages as counts would lose this sample-size information.
Include every category, even an observed zero. Use expected counts in the denominators. Goodness of fit compares one variable to a claimed distribution; independence examines two variables in one sample; homogeneity compares one variable across groups. All three use this same sum of contributions.
Key Takeaways
- Observed counts come from the data; expected counts come from the null model.
- Add over every category or cell, including observed zeros.
- Keep decimal expected counts and calculate with counts, not percentages.
- A p-value describes possible data under the null hypothesis.
- The same percentages can produce different p-values at different sample sizes.
- With two categories, the uncorrected statistic equals the squared two-sided z statistic.
2Test a claimed category distribution
A claim about category shares predicts a complete set of counts for a random sample. Goodness of fit compares those predictions with the sample and turns the overall gap into evidence. The work starts with clear population hypotheses and ends with a conclusion in context. Contributions and percentages then help explain the result, while sparse categories and parameters estimated from the data require changes to the setup.
2.1 Build a claimed distribution
A goodness-of-fit test asks whether one categorical variable follows a particular distribution in a population. You take one random sample and compare its category counts with the counts the claim predicts. The comparison begins with population proportions, before any test statistic is calculated.
State the population claim
Suppose city records give commuting proportions of 60% car, 25% public transit, 10% bike, and 5% walk. The null hypothesis says these are the current population proportions:
The alternative says at least one population proportion differs. It does not require every category to differ. There is no single direction such as “greater”: increasing one share forces another share to decrease because all shares add to 1.
Hypotheses concern the population. A sample will rarely reproduce every claimed percentage exactly, even when the population claim is right. The test assesses whether the sample’s overall disagreement is too large to explain comfortably through sampling variation.
Claims may come from equal shares, a scientific theory, past records, or a probability model. Equal weekday shares give five proportions of 0.20. A genetic ratio of 9 : 3 : 3 : 1 gives four proportions after conversion. A binomial model can predict the proportions of families with 0, 1, 2, or 3 girls.
Convert the claim into expected counts
First check that the proportions add to 1. For a ratio, divide each part by the sum of the parts. The ratio 9 : 3 : 3 : 1 has 16 parts, giving proportions , or 0.5625, 0.1875, 0.1875, and 0.0625.
Then calculate each expectation:
In a sample of 400 commuters, the city claim gives expectations of 240 car, 100 public transit, 40 bike, and 20 walk. Their sum is 400. For 556 seeds and the genetic ratio, expectations are 312.75, 104.25, 104.25, and 34.75. Their decimal parts are meaningful; rounding them to whole seeds changes the calculation.
Check the sum before continuing. A mismatch can reveal an omitted category, a percentage entered as 25 instead of 0.25, or a set of claimed shares that was never a complete distribution. Do not estimate these claimed shares from the sample’s observed percentages when testing an outside claim. That would make every expectation equal its observed count and force the statistic to 0.
Find the degrees of freedom
With categories whose proportions are fully specified in advance,
The subtraction accounts for the fixed sample total: after counts are known, the remaining count is determined by subtraction. Both the four-category commuter test and the four-category seed test have 3 df. Increasing the sample from 400 to 800 changes expected counts but leaves those 3 df unchanged.
The formula uses the number of categories, not the sample size. The expression belongs to the single-variance test, where the data are measurements. When a model parameter is estimated from the count data, the goodness-of-fit df also need an adjustment.
Key Takeaways
- Goodness of fit compares one categorical variable with specified population proportions.
- The alternative says that at least one proportion differs.
- Convert ratios to proportions and check that the proportions sum to 1.
- Expected counts equal sample size times claimed proportion and sum to the sample size.
- With fully specified proportions, df equals the number of categories minus 1.
2.2 Complete a goodness-of-fit test
A goodness-of-fit calculation is useful only when its reference curve fits the data collection and expected counts. Set the hypotheses and significance level first, then check the conditions before interpreting the p-value.
Check the data
The data should come from a random sample or a process that behaves like one. Observations must be independent: each individual is counted once, and one outcome does not determine another. When sampling without replacement, keep the sample below about 10% of the population. Use a count for each category.
The standard expected-count rule is every expected count at least 5. Check expectations, not observations. Some textbooks use the looser guideline that all expectations are at least 1 and no more than 20% are below 5. The rule used in the calculations here is the all-at-least-5 rule.
Work through the commuter test
A random sample of 400 commuters gives 210 car, 122 public transit, 48 bike, and 20 walk. Test the recorded 60%, 25%, 10%, and 5% distribution at . The null states those population proportions; the alternative says at least one differs. Assume the sample is less than 10% of the city’s commuters and each person reports one main method.
The expected counts are 240, 100, 40, and 20. All are at least 5. Compute the contributions:
| Method | Calculation | Contribution |
|---|---|---|
| Car | 3.75 | |
| Public transit | 4.84 | |
| Bike | 1.60 | |
| Walk | 0 |
Their sum is . Four categories give . The right-tail probability is about 0.017. Since , reject the null hypothesis. There is convincing evidence that the city’s current commuting distribution differs from its recorded proportions. This result identifies an overall difference; it does not establish a difference in every category.
The critical-value approach agrees: at 3 df the 5% right-tail cutoff is 7.815, below 10.19. Use either the p-value comparison or the critical value comparison, with the same significance level.
A result that does not reject
A gym records 150 sampled weekday check-ins: 36, 30, 27, 24, and 33 from Monday through Friday. Under equal shares, every expected count is 30. The squared gaps are 36, 0, 9, 36, and 9. Dividing their sum by 30 gives with 4 df and p about 0.558. At 0.05, do not reject equal shares. The data give no convincing evidence of unequal weekday shares; they do not establish exact equality. Repeated check-ins by the same member would need attention to independence before using this calculation for inference.
Get the result from software
On a TI-84 Plus, enter observed counts in L1 and expected counts in L2, then run χ²GOF-Test with the df. Excel or Google Sheets uses CHISQ.TEST(observed_range, expected_range) for a single row or column. In R, use chisq.test(c(210,122,48,20), p=c(0.60,0.25,0.10,0.05)).
Keep full precision until the final statistic. Read the right tail and compare p with the chosen level. Finish with a population conclusion that names the distribution being tested.
Key Takeaways
- Check randomness, independent observations, and every expected count before testing.
- Calculate all contributions, add them, and use the correct category-based df.
- Reject when the right-tail p-value is at most the chosen significance level.
- State the result about the population distribution in the context of the question.
- Not rejecting leaves the claim consistent with the data; it does not establish exact equality.
- An overall rejection does not identify every category as different.
2.3 Find the pattern behind the result
An overall rejection tells you that the claimed distribution misses some aspect of the population. To describe that gap, examine the category contributions, the direction of each gap, and the observed percentages. These answer different questions from the p-value.
Contributions and residuals
In the commuter test, public transit contributes 4.84 and car contributes 3.75 to the total statistic of 10.19. Bike contributes 1.60 and walk contributes 0. The biggest contributions show which categories drive the overall disagreement. Their signs were lost during squaring, so also inspect : transit is above expectation, 122 against 100, and car is below expectation, 210 against 240.
A Pearson residual measures the signed gap on a standardized scale:
Its square is the category’s chi-square contribution. For the commuters the residuals are approximately −1.94, +2.20, +1.26, and 0. A residual beyond about ±2 draws attention to a category. Use this as a descriptive clue, not a separate significance test for that category. Statistical software may use “standardized residual” for a further adjusted quantity, so check the formula in its output.
Percentages put the pattern in familiar units: 30.5% took transit against the claimed 25%, while 52.5% drove against 60%. These differences help judge practical importance. A huge sample can produce a small p-value for a difference that has little practical effect.
Recognize close agreement
For 556 pea seeds, observed counts of 315, 108, 101, and 32 are close to the 9 : 3 : 3 : 1 expectations of 312.75, 104.25, 104.25, and 34.75. The statistic is about 0.47 with 3 df and p about 0.93. The ratio fits these data well, but nearby ratios could fit too.
Very close agreement can sometimes deserve scrutiny. A statistic far into the left tail means the counts fit unusually closely under the null model. The seed example’s left area, about 0.075, is not remarkable by itself. Fisher’s 1936 criticism concerned the combined agreement across many of Mendel’s experiments.
Handle sparse categories before testing
Suppose revised commuter claims are 59% car, 25% transit, 10% bike, 5% walk, and 1% other. For 400 people, expected counts are 236, 100, 40, 20, and 4. The last expectation fails the rule. Combining walk and other produces an expected count of 24, leaving four categories and 3 df. Combine the corresponding observed counts too.
Choose a grouping that makes sense from the category meanings and expectations. Do not search through groupings for a desired p-value. Larger samples or exact or simulation-based methods are alternatives; discarding a rare category loses data and changes the question.
Allow for fitted parameters
If the planned model estimates parameters from the same category counts, use with an appropriate fitting method. For numbers of girls in three-child families, four categories give 3 df when the binomial probability 0.5 is fixed in advance. Estimating that probability from the sample uses one more df, leaving 2. Plan the model, categories, and fitting procedure before examining the pattern. Choosing a claim just because it fits the observed counts invalidates the usual reference calculation.
Key Takeaways
- Contributions locate large gaps; the sign of gives their direction.
- A Pearson residual is ; its square is the cell contribution.
- Residuals near or beyond ±2 are descriptive flags, not individual category tests.
- Compare observed percentages with claimed percentages to judge the size of a difference.
- Combine related sparse categories on a defensible plan and recalculate df.
- For a suitably fitted model, subtract one additional df per estimated parameter.
- Choose the procedure before inspecting the data for a preferred result.
3Analyze categorical groups
Two-way tables show how categorical variables occur together. Reading them well means choosing a denominator that matches the question and comparing percentages within groups. The same count calculation can test association in one population or compare distributions across populations. Expected tables describe what no difference would look like; the study design determines which hypotheses and conclusions belong with the calculation.
3.1 Read percentages within groups
A contingency table, or two-way table, counts combinations of two categorical variables. Each individual belongs in one cell. The margins hold row totals, column totals, and the grand total. These totals give several possible denominators, each answering a different question.
Read the counts and margins
A random sample of 300 adults reports exercise frequency and good or poor sleep:
| Sleep quality | No exercise | 1–2 days | 3 or more days | Total |
|---|---|---|---|---|
| Good | 40 | 70 | 90 | 200 |
| Poor | 40 | 35 | 25 | 100 |
| Total | 80 | 105 | 115 | 300 |
This is a table: two sleep categories and three exercise categories. Totals summarize categories; they are not additional categories. Adding all six inner cells gives 300, just as adding the row totals or the column totals does.
Choose the denominator from the question
A joint percentage describes a combination out of everyone. The 40 adults with no exercise and good sleep are of the whole sample.
A marginal percentage describes one variable without separating the other. Good sleep occurs for of all adults. The marginal exercise distribution uses the column totals 80, 105, and 115 divided by 300.
A conditional percentage describes one variable within a specified group. Among the 80 adults with no exercise, sleep well. The phrase “among those with no exercise” identifies the denominator. Among the 200 good sleepers, exercise 3 or more days. That is a different question from the percentage of frequent exercisers who sleep well, .
A useful habit is to finish the sentence “Out of all the …” before dividing. “Out of all good sleepers” uses 200; “out of all frequent exercisers” uses 115. A single cell can support both percentages, but their meanings are different.
Describe association in the sample
Treat exercise group as the explanatory grouping and compare the sleep distribution within each exercise group. Good sleep is reported by 50%, about 66.7%, and about 78.3% across the three groups. Since these conditional distributions differ, exercise and sleep are associated in this sample.
The raw good-sleep counts, 40, 70, and 90, are insufficient for that comparison because the groups contain different numbers of people. Conditional percentages remove the difference in group size. Under no association, each group would have the same good-sleep percentage, even if the group counts were very different.
A segmented bar chart makes this visible: draw one equal-height bar per exercise group, split into good and poor sleep percentages. Similar splits suggest no association; different splits suggest a pattern. A side-by-side chart of conditional percentages can show the same comparison.
Sample percentages vary even when population variables are independent. The test of independence asks whether a discrepancy as large as the observed one would be unusual under population independence. A descriptive pattern is the starting point for that test; the survey design also matters when deciding which population the result can describe.
Key Takeaways
- A two-way table counts combinations; its totals are margins, not extra categories.
- Joint percentages use the grand total, and marginal percentages use one variable’s totals.
- A conditional percentage uses the total of the group named in the question.
- Compare conditional distributions across groups to describe sample association.
3.2 Calculate expectations in a two-way table
Under independence, the distribution of one variable is the same within every category of the other. Expected counts apply the table’s overall proportions to each group. They keep the observed group sizes while removing the association.
Build an expected count from the margins
For a cell with row total , column total , and grand total ,
To see why, estimate the row probability by and the column probability by . Independence multiplies these probabilities for their joint occurrence. Multiplying by converts that joint probability back into a count: .
In the exercise-and-sleep table, 200 of 300 adults sleep well, or two thirds. If sleep and exercise are independent, two thirds of each exercise group should sleep well on average. The no-exercise group has 80 people, so its expected good-sleep count is .
Complete and check the expected table
| Sleep quality | No exercise | 1–2 days | 3 or more days | Total |
|---|---|---|---|---|
| Good | 53.33 | 70.00 | 76.67 | 200 |
| Poor | 26.67 | 35.00 | 38.33 | 100 |
| Total | 80 | 105 | 115 | 300 |
The displayed values use two decimals; keep unrounded values in calculations. For poor sleep and 3 or more exercise days, . The observed count of 25 in that cell is not an input to this formula. Its row and column totals are the inputs.
The expected table has the same margins as the observed table. Check a row and a column before using it: the good-sleep row sums to 200, and the no-exercise column sums to 80. Small rounding differences in displayed totals can occur; substantial differences signal an arithmetic or copying error.
Every expected exercise column also has the same good-to-poor ratio, 2 : 1. That is the practical meaning of independence in this table. Unequal expected counts across columns come from unequal group sizes, not from an expected association.
Count the freely varying cells
For rows and columns of categories,
The margins restrict the cell counts. In the example, choose two entries in the first row; its row total determines the third. Each column total then determines the entry beneath it. There are only two freely chosen entries, so .
The same reasoning gives 1 df for a table, 4 for a table, and 12 for a table. Swapping rows and columns leaves the product unchanged. Counting a totals row would incorrectly increase df, while using the number of inner cells minus 1 would ignore the separate row and column constraints.
Use counts to construct this table. Percentages can help explain independence, but applying the expected-count formula to a percentage table removes the original sample size. After calculating the full expected table, check its smallest entry against 5 before computing the test statistic.
Key Takeaways
- Under independence, .
- Expected counts keep the observed margins and remove differences in conditional distributions.
- Calculate from the margins, keeping decimal precision.
- Use df, excluding the totals row and column.
3.3 Test whether two variables are associated
Use a test of independence for one random sample whose members are classified on two categorical variables. The question is whether the variables are associated in the population. The null model removes that association while keeping the table’s observed margins.
State hypotheses and check conditions
For the exercise-and-sleep survey, the null hypothesis says exercise frequency and sleep quality are independent among adults in the population. The alternative says they are associated. These statements describe population relationships, not whether two sample percentages happen to match.
Check that the survey is a random sample, adults are counted once, and the sample is less than about 10% of the population when sampling without replacement. Every expected count must be at least 5. Here the smallest expectation is about 26.67, so the expected-count condition holds. A survey allowing multiple exercise selections for the same person would not produce the required one-cell-per-person count table.
Calculate the statistic and p-value
The observed good-sleep counts are 40, 70, and 90. Their expectations are approximately 53.33, 70, and 76.67. Poor-sleep counts are 40, 35, and 25, with expectations 26.67, 35, and 38.33. Using full precision gives contributions of approximately:
| Sleep quality | No exercise | 1–2 days | 3 or more days |
|---|---|---|---|
| Good | 3.33 | 0 | 2.32 |
| Poor | 6.67 | 0 | 4.64 |
Add all six contributions to obtain . With , the right-tail p-value is about 0.0002. This is below 0.05, so reject independence. There is convincing evidence that exercise frequency and sleep quality are associated in the population. The statistic also exceeds the 2-df critical value of 5.991.
The largest contributions identify more poor sleepers than expected among non-exercisers and fewer among frequent exercisers. The middle exercise group matches its expected counts. Explain the pattern using within-group percentages: about 50%, 67%, and 78% report good sleep across the exercise groups.
Keep the conclusion tied to the design
This is an observational survey. Age, health, or work schedules could help explain the relationship; the test establishes evidence of association, not that exercise causes better sleep. The calculation is symmetric: exchanging rows and columns gives the same statistic and p-value. It supplies no causal direction.
The p-value also does not measure association strength. It reflects both the pattern and the sample size. Describe the pattern and its size with conditional percentages alongside the test result.
Use software with matching settings
A TI-84 χ²-Test uses the observed matrix [A] and can store expectations in [B]. A spreadsheet’s CHISQ.TEST takes corresponding observed and expected cell ranges, with margins excluded. In R, chisq.test(tab) computes the test from a count matrix named tab.
For a table, R applies Yates’s continuity correction by default. Python’s scipy.stats.chi2_contingency also defaults to a correction when df is 1. To match the uncorrected hand formula, use correct = FALSE in R or correction=False in Python. For 60 successes in 100 versus 45 in 100, the uncorrected statistic is about 4.51; the corrected value is about 3.93.
Key Takeaways
- One sample classified on two variables calls for an independence test.
- The null hypothesis states population independence; the alternative states association.
- Add contributions over every inner cell and use df.
- Report the overall result together with conditional percentages.
- An observational association does not establish a cause.
- Check continuity-correction settings when matching a 2 × 2 software test to hand calculations.
3.4 Compare distributions across populations
A test of homogeneity compares the distribution of one categorical variable across populations or treatment groups. You may take separate independent random samples from several populations, or randomly assign participants to groups in an experiment. The design determines the hypotheses, even though the arithmetic matches an independence test.
Ask whether the distributions are the same
Suppose separate random samples of 100 customers from each of three stores report their main payment method. The null hypothesis says that the population proportions using card, mobile payment, and cash are the same at all three stores. It does not say that these three methods are equally popular. The alternative says that at least one store’s distribution differs.
| Store | Card | Mobile | Cash | Total |
|---|---|---|---|---|
| A | 50 | 30 | 20 | 100 |
| B | 45 | 40 | 15 | 100 |
| C | 40 | 25 | 35 | 100 |
| Total | 135 | 95 | 70 | 300 |
The pooled proportions are 135/300, 95/300, and 70/300. Under the null, each store shares that common distribution. Because each sample contains 100 customers, each expected row is 45, 31.666…, and 23.333…. If the store samples had different sizes, their expected counts would differ while their expected proportions stayed the same.
Perform the comparison
Check independent random samples, one payment classification per customer, the sampling fraction within each population, and all expected counts at least 5. Then calculate and add over all nine cells.
The contributions are about 0.556, 0.088, and 0.476 for A; 0, 2.193, and 2.976 for B; and 0.556, 1.404, and 5.833 for C. With unrounded intermediate values, . The df are and the right-tail p-value is about 0.007. At 0.05, reject the null: there is convincing evidence that payment-method distributions are not the same across the stores.
Cash use gives a useful description: 20% at A, 15% at B, and 35% at C. Store C’s cash cell has the largest contribution, 5.833, because 35 customers used cash against an expectation of about 23.33. The rejection does not say that every pair of stores differs or that every payment method differs.
Separate the design from the calculation
| Design | Test | Population question |
|---|---|---|
| One sample, two variables measured on each member | Independence | Are the variables associated? |
| Separate samples, one outcome compared across populations | Homogeneity | Are the outcome distributions the same? |
A table’s shape alone cannot choose between these tests. Both use the same expectations, statistic, df, and right tail. Read how the sample or groups were created before naming the test.
A randomized treatment study supports a different interpretation from the store survey. For example, random assignment of 210 patients to two drugs and a placebo can support a causal conclusion about treatment effects if the outcome distributions differ. Separate samples of existing store customers establish differences between those populations without identifying their cause.
With two groups and a binary outcome, the uncorrected homogeneity test matches the two-sided two-proportion z test using the pooled proportion. The chi-square approach also extends directly to more groups or more outcome categories.
Key Takeaways
- Homogeneity compares one categorical distribution across independent samples or treatment groups.
- The null states equal distributions across populations, not equal shares across categories.
- Its expectations, statistic, df, and right-tail calculation match the independence test.
- The sampling design determines the test’s name and the conclusion.
- Use within-population percentages to explain an overall difference.
- Random assignment supports causal conclusions about treatments; existing-group comparisons do not.
4Choose, check, and report a test
A test’s name is only part of a sound analysis. The data collection, expected counts, and kind of variable determine whether its p-value answers the question. Learn to spot conditions that fail, choose a defensible remedy, and report evidence alongside the size of the pattern. A final use of the chi-square curve tests the spread of measurements, with a different statistic and a tail chosen from the alternative hypothesis.
4.1 Check whether the count test applies
A precise calculation can still give an unreliable answer when the data do not fit the test. Chi-square tests on counts rely on random data collection, independent observations, actual frequencies, and sufficiently large expected counts. Each condition protects a different part of the reasoning.
Randomness and independence
Random sampling supports inference to the population sampled. Separate random samples support comparisons of their populations. Random assignment supports treatment comparisons. A voluntary online poll can overrepresent people with strong opinions; a small p-value does not remove that selection problem or justify extending the result to a wider population.
Each individual must appear in exactly one cell. Independent observations also mean that one person’s response does not determine another’s. A multiple-answer survey can count one person several times, and a before-and-after survey records two responses from the same person. Ordinary independence or homogeneity tests do not account for those dependencies. Paired binary responses call for a paired method such as McNemar’s test.
For sampling without replacement, a sample less than about 10% of its population keeps dependence from depletion small. Check this within each sampled population. The rule does not repair repeated measurements or clustered responses from the same household.
Use actual frequencies
Cells must contain counts of individuals, not means, rates, or measurements. Percentages need their underlying sample sizes: 30.5% of 400 corresponds to 122 individuals. A rounded percentage may not recover an exact count; use the original counts when available. Replacing every cell by a percentage changes the sample size used by the statistic.
Keep observed zeros. They can be informative disagreements with the null model. The denominator is the expected count, so a zero observed count does not make that denominator zero.
Inspect the expected counts
The usual rule is that every expected count is at least 5. These are predictions under the null, not the counts seen in the sample. Some texts allow all expectations at least 1 with at most 20% below 5. State which guideline is being applied and do not switch rules after seeing whether the test rejects.
A large grand total is insufficient. In 1,000 observations, a category with claimed proportion 0.003 has expectation 3. In a two-way table of 120 people, a cell with row total 30 and column total 12 has expectation . Both fail the all-at-least-5 rule.
The chi-square reference distribution is an approximation for count tests. Small expectations make the distribution of possible contributions too irregular for that approximation to work well. Checking observed counts instead can approve a test whose reference p-value is unreliable.
Choose a remedy that fits the problem
Combine related categories when their meanings support a common group, updating observed counts, expected counts, and df. For a table, merge complete rows or columns, not an isolated cell. A larger random sample can increase expected counts. An exact or simulation-based test can address sparse counts without forcing a poor approximation; Fisher’s exact test is a common choice for a sparse table.
Dropping a rare category changes both the distribution and the sample. Trying many mergers until one gives a desired p-value also changes the procedure being tested. Remedies for small counts do not correct a biased sample or dependence between observations; those problems require a suitable design or a method that accounts for them.
Key Takeaways
- Random data collection, independent observations, actual counts, and adequate expectations serve distinct purposes.
- Each individual must appear in exactly one cell; paired responses need a paired method.
- Check the sampling fraction when sampling without replacement.
- Apply the expected-count rule to expectations, even when observed counts are zero.
- A large total sample does not guarantee adequate counts in rare categories.
- Use meaningful pooling, more data, or an exact or simulation-based method for sparse counts.
- In two-way tables, pooling merges whole rows or columns.
4.2 Choose a test and explain its result
Choose a test by the question, the kind of variable, and the way the data were collected. A table may look identical under two different designs, while two tests with different names may produce the same arithmetic.
Match the procedure to the question
| Question and design | Procedure |
|---|---|
| One categorical variable in one sample, compared with stated proportions | Goodness of fit |
| Two categorical variables measured on one sample | Independence |
| One categorical outcome compared across separate samples or treatment groups | Homogeneity |
| Spread of one quantitative variable from a normal population | Single variance |
Comparing donor blood types with national proportions is goodness of fit. Measuring party affiliation and policy opinion in one random sample of 500 voters calls for independence. Comparing travel methods in separate samples of 200 students at each of four colleges calls for homogeneity. Asking whether fill weights have standard deviation above 2 grams calls for a variance test.
Questions about means require a different family of tests, such as t tests. Paired yes/no observations require a paired method. Prediction of a binary outcome using several explanatory variables leads to logistic regression; joint modeling of several categorical variables can lead to loglinear models.
Connect chi-square and z tests
For two categories, the uncorrected goodness-of-fit statistic is the square of the one-proportion z statistic. For a table, the uncorrected statistic is the square of the pooled two-proportion z statistic. The p-value matches the two-sided z test because squaring loses the sign.
With 60 successes out of 100 in one group and 45 out of 100 in another, the pooled proportion is . The pooled standard error is , giving . Thus and p is about 0.034. A one-sided z test answers a directional question and has a different p-value.
Report evidence and its size
Include the test name, statistic, df, sample size, and p-value. For example, the exercise survey can be reported as “A chi-square test of independence gave , p < 0.001. Good sleep was reported by about 50%, 67%, and 78% of adults across increasing exercise groups.” Follow with the conclusion about association in the sampled population.
Percentages show the size and pattern that a p-value leaves out. Keeping the same 60% versus 45% success rates while changing group sizes gives very different evidence: 20 per group gives a statistic about 0.90 and p about 0.34; 100 per group gives 4.51 and p about 0.034; 1,000 per group gives about 45.1 and p far below 0.001. The percentage-point gap stays 15 throughout.
Statistical significance means the observed discrepancy is unusual under the null model at the chosen level. Practical importance depends on the size and consequences of the difference. A nonsignificant result can reflect limited power to detect a real difference. Say “no convincing evidence” after not rejecting, and reserve causal language for a design with random assignment. A survey can support a population association without establishing why it occurs.
Key Takeaways
- Identify the variable types and sampling design before naming a test.
- Two-category chi-square tests match two-sided z tests when the correction settings agree.
- Report the test name, statistic, df, sample size, p-value, and relevant percentages.
- A p-value measures evidence against the null model, not the size of the relationship.
- Statistical significance and practical importance are different judgments.
- Keep population and causal conclusions within what the study design supports.
4.3 Test a population’s spread
A single-variance test asks whether the spread of a quantitative measurement matches a claim. Examples include consistency of fill volumes or precision of repeated measurements. This procedure uses the chi-square distribution but does not compare category counts.
Set up the variance claim
Write hypotheses about the population variance . The null is . Choose the alternative to match the question: greater than, less than, or different from the claimed variance. A standard-deviation claim must be squared: mm becomes mm².
For a random, independent sample from a normal population, use
Here is the sample variance. Both the numerator’s sample spread and the denominator’s claimed spread are variances. A large statistic indicates more spread than claimed; a small statistic indicates less. The normal-population condition is essential: skewness, heavy tails, and outliers can badly distort this test’s p-value. A large sample does not remove that sensitivity. Inspect a histogram or normal probability plot before using the test.
Match the tail to the alternative
| Alternative | p-value |
|---|---|
| Right-tail area | |
| Left-tail area | |
| Twice the smaller tail area |
For a two-sided 5% test, put 2.5% in each tail. The cutoffs are not equally far from the center because the curve is asymmetric. With 24 df they are 12.401 and 39.364.
Work through three directions
Too much spread: a random sample of 20 bolts has mm against a claimed standard deviation of 0.5 mm. For a normal length population, test the greater-than alternative. The statistic is with 19 df. The right-tail p-value is about 0.030. At 0.05, reject: there is convincing evidence that the population standard deviation exceeds 0.5 mm.
Less spread: a new filler gives mL in 15 independent fills against an old standard deviation of 2.0 mL. Under normality, the statistic is with 14 df. The left-tail area is about 0.060. At 0.05, there is no convincing evidence of reduced spread. The same result would reject at a level of 0.10 if that level had been chosen beforehand.
Changed spread: 25 independent weighings have g against a claimed 1.2 g. The statistic is with 24 df. The left area is about 0.043; double it for the two-sided p-value, about 0.086. Do not reject at 0.05.
Use CHISQ.DIST.RT(x, df) for a right area and CHISQ.DIST(x, df, TRUE) for a left area. In R, pchisq(x, df) gives the left area; add lower.tail = FALSE for the right. On a TI-84 use χ²cdf with bounds 0 to the statistic for a left tail, or the statistic to 1E99 for a right tail. A conclusion about spread says nothing about the population mean.
Key Takeaways
- The single-variance test uses quantitative measurements from a normal population.
- Square standard deviations before using .
- Use df for this test.
- The alternative determines the tail; a two-sided test doubles the smaller tail area.
- Large samples do not remove the test’s sensitivity to nonnormal data.
- The conclusion concerns population spread, not the population mean.
Chi-Square Test examples
1Build a count statistic and read its curve
10 steps
- 1IntroductionFrom count gaps to evidence
A model predicts how counts should be distributed, but a random sample will usually miss those predictions by some amount. The test needs to measure that gap and judge it on the right probability curve.
Follow a three-sector spinner through these two jobs: build an overall discrepancy from its counts, then interpret the result using a chi-square curve with the appropriate degrees of freedom.
- 2ExplanationChoose a curve by its df
The chi-square family contains a different curve for each degrees of freedom, or df. All values are nonnegative. Small df gives a strongly right-skewed curve; larger df moves it right, spreads it out, and makes it more symmetric.
At 4 df the mean is 4 and standard deviation is about 2.83. At 10 df the mean is 10. The same statistic therefore occupies a different place on the two curves.
- 3ConnectionSee why squares appear
If independent standard normal values are squared and added, their sum follows a chi-square distribution. The number of values is the df.
For one value, . The two normal tails beyond −1.96 and +1.96 become one chi-square right tail beyond about 3.84. This connects a familiar two-sided normal cutoff with the nonnegative chi-square scale.
- 4ChallengeCan a statistic be large by itself?
Two tests both produce a statistic of 8. One has 2 df and the other has 10 df. Must they have the same p-value? Explain without calculating either area.
---reveal---
No. Their reference curves differ because df sets the shape and location. Eight is well above the mean of the 2-df curve but below the mean of the 10-df curve. Its right-tail areas differ, so the statistic alone does not give the evidence.
- 5ExampleWrite observed and expected counts
An equally likely three-sector spinner is spun independently 120 times. Sectors red, blue, and green occur 48, 32, and 40 times. Under equal shares, each expected count is .
The observed and expected lists both sum to 120. Red is 8 above expectation, blue is 8 below, and green matches. Adding signed gaps would hide the discrepancy because .
- 6ExampleCompute one contribution at a time
Use the squared gap divided by expected for each sector.
- Red: .
- Blue: .
- Green: .
Add the three contributions: . Red and blue both contribute positively even though their gaps have opposite signs. The green cell still belongs in the calculation; its contribution happens to be zero.
- 7Key InsightA gap needs a scale
Why divide by expected? A gap of 8 is a different discrepancy when 40 are expected than when 400 are expected. Its contribution is in the first case and in the second.
The count statistic measures the mismatch relative to the null prediction’s size. A large raw gap is not necessarily the cell that contributes most to the overall test.
- 8ExampleRead the spinner’s right tail
Three fully specified sectors give 2 df. For , the right-tail area is about 0.202. In a spreadsheet,
CHISQ.DIST.RT(3.2, 2)calculates that area.It is the probability of a statistic at least 3.2 under equal shares. Because 0.202 exceeds 0.05, the spins give no convincing evidence against equal shares at that level. Do not double this area.
- 9ChallengeKeep the percentages, change the evidence
A second spinner record has 240 independent spins with counts 96, 64, and 80. Its category percentages match the first record. How do its statistic and df compare?
---reveal---
Expectations double to 80 each. Every squared gap grows fourfold while each denominator doubles, so the total doubles from 3.2 to 6.4. The three categories still give 2 df. Keeping the same percentages does not keep the same evidence.
- 10RecapKeep calculation and interpretation connected
Expected counts express the null prediction; the sum of squared, scaled gaps measures disagreement. Use the df to choose the reference curve before finding its tail area.
For categorical-count tests, the entire p-value is the right-tail area. The spinner example also shows why actual sample size matters: the same percentage gaps create a larger statistic when supported by more independent observations.
2Test and interpret a distribution claim
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionTest a complete distribution claim
- 2ExplanationState the claim and its alternative
- 3ExampleTurn shares into count predictions
- 4ChallengeStart from a ratio
- 5TipCheck the conditions before the area
- 6ExampleCompute the four gaps
- 7ExampleMake the population decision
- 8ChallengeRead a result at its chosen level
- 9ExplanationLocate and describe the mismatch
- 10ConnectionShow the size with percentages
- 11ExamplePool a sparse category meaningfully
- 12ChallengeCombine a merger with a fitted model
- 13RecapFrom a claim to a defensible conclusion
3Analyze a table and identify its design
16 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionRead a table before testing it
- 2ExampleKeep one student in one cell
- 3ExplanationCondition on the named group
- 4ChallengeReverse the conditioning
- 5ExplanationBuild no association from the margins
- 6Key InsightUnderstand the one free count
- 7ChallengeUse unequal margins
- 8ExplanationName the survey hypotheses
- 9ExampleCombine all four contributions
- 10TipMatch the software formula
- 11ChallengeInterpret an association responsibly
- 12ConnectionChange the design, keep the numbers
- 13Key InsightEqual distributions mean equal shares
- 14ChallengeRecognize a different source of causal evidence
- 15ChallengeChoose the name before calculating
- 16RecapJoin design, counts, and percentages
4Check an analysis and test a variance
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionDecide whether the calculation answers the question
- 2ExampleA large total can hide a sparse category
- 3TipMatch the remedy to the problem
- 4ChallengeCheck the design before the counts
- 5ExplanationSelect the question’s procedure
- 6ChallengeKeep evidence separate from size
- 7ConnectionReport enough to understand the result
- 8ExplanationChange from counts to measurement spread
- 9ExampleCompute the bolt statistic
- 10ExampleChoose the area that answers the question
- 11ChallengeChange the alternative
- 12TipKeep the population-shape check
- 13ChallengeGive an analysis a final review
- 14RecapCarry the question through the entire test
Chi-Square Test practice questions
Set 1: Work with tables and sampling variation10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Build and interpret the basic tests10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Diagnose choices and combine testing steps10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Evaluate complete analyses and difficult cases10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Alternative hypothesis
Association
C
Cell contribution
Chi-square distribution
Chi-square statistic
Claimed proportion
Common distribution
Conditional distribution
Confounding variable
Contingency table
Continuity correction
Critical value
D
Data-dependent selection
Degrees of freedom
E
Estimated parameter
Exact test
Expected count
Expected table
Expected-count condition
G
Goodness-of-fit test
I
Independent observations
Independent samples
J
Joint distribution
M
Marginal constraint
Marginal distribution
N
Normality
Null hypothesis
O
Observed count
P
P-value
Paired data
Pearson residual
Pooled proportion
Pooling categories
Population independence
Population variance
Power
Practical importance
R
Random assignment
Random sample
Rejection region
Right skew
Right-tail area
S
Sample variance
Sampling variation
Segmented bar chart
Significance level
Single-variance test
Statistical significance
T
Test of homogeneity
Test of independence
Two-sided variance test
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.