Tutorials › AP Statistics › Chi-Square Test of Independence Full Worked Example

Expected counts and chi-square conclusions · Tutorial 578 of 1000

Chi-Square Test of Independence Full Worked Example

Learn how to complete and interpret a chi-square test of independence using survey data, from stating hypotheses to concluding in context.

Intermediate 9 min read

What You'll Learn

  • Distinguish a survey test of independence from a test comparing separate groups.
  • State null and alternative hypotheses about two population variables.
  • Check random sampling, independence, the 10% condition, and expected counts.
  • Calculate the chi-square statistic, degrees of freedom, and upper-tail p-value.
  • Write a contextual conclusion that describes association without implying causation.
  • Explain what a nonsignificant test does—and does not—show.

From a Survey Table to a Test of Independence

In “Chi-Square Test With a Random Experiment,” the design involved randomly assigned treatment groups and a categorical outcome. This tutorial turns to a different design: one random sample in which each person is classified by two categorical variables. A chi-square test of independence uses the resulting two-way table to assess whether those variables are associated in the population.

A survey can reveal evidence of an association, but it does not generally show that one variable caused the other. For instance, if age group and preferred source of local news are associated in a sample, that does not establish that age causes a particular news preference. The test answers a question about evidence of association; the observational survey design limits what we can claim beyond that.

Definition: A chi-square test of independence evaluates whether two categorical variables are independent in a population, using one sample in which each individual is classified by both variables. The null hypothesis says the variables are independent; the alternative says they are associated.

The Four Steps for a Survey Test

The study design determines the procedure. Here, researchers take one sample and record two categorical variables for every individual, so a chi-square test of independence is appropriate. In contrast, a test of homogeneity compares the distribution of one categorical response across separate samples or groups.

As in “Stating Hypotheses for a Test of Independence,” write the hypotheses about the population and define both variables. The null hypothesis is that the variables are independent. The alternative is that they are associated. Neither hypothesis says that the observed sample table must have identical percentages in every row; random variation can create differences even when the population variables are independent.

Under the null model of independence, expected counts are calculated from the table margins. For each cell, multiply its row total by its column total and divide by the grand total. The chi-square statistic adds the cell contributions \((O-E)^2/E\), where \(O\) is the observed count and \(E\) is the expected count.

$$ E=\frac{(\text{row total})(\text{column total})}{\text{grand total}} \qquad\text{and}\qquad X^2=\sum\frac{(O-E)^2}{E} $$

The test’s degrees of freedom are \((r-1)(c-1)\), where \(r\) and \(c\) are the numbers of row and column categories. Its p-value is the upper-tail probability for the observed chi-square statistic and those degrees of freedom, assuming the null hypothesis is true. The expected-count condition requires every expected count to be at least 5.

1
State.
Identify the population and the two categorical variables. State independence as \(H_0\) and association as \(H_a\), in context.
2
Plan.
Name a chi-square test of independence. Check random sampling, independence of observations, the 10% condition when sampling without replacement, and the expected-count condition.
3
Do.
Calculate expected counts, \(X^2\), degrees of freedom, and the upper-tail p-value.
4
Conclude.
Compare the p-value with the significance level and describe the evidence about association between the variables in the population.

Worked Examples: Survey Data and Association

Worked Example: Age Group and Local News Source

Suppose a municipality randomly selects 240 adult residents for a survey. Each person reports an age group and their primary source for local news. The municipality has 18,000 adult residents. The following invented counts summarize the responses:

Age groupAppRadioPrintTotal
18–39553530120
40 and older254550120
Total808080240

State. The population is the adult residents of this municipality. The two variables are age group and primary source of local news. \(H_0\): age group and primary news source are independent among the municipality’s adult residents. \(H_a\): age group and primary news source are associated among those residents.

Plan. Use a chi-square test of independence because one sample of residents is classified by two categorical variables. The residents were randomly selected, satisfying the random condition. Each resident contributes once to one cell, and the sample is only \(240/18{,}000=0.0133\), or about 1.33%, of the adult population. Thus \(240\leq0.10(18{,}000)=1{,}800\), so the 10% condition is met. Expected counts will be checked below.

Do. The row totals are 120, each column total is 80, and the grand total is 240. For example, the expected count in the 18–39 and app cell is \(120(80)/240=40\). The same calculation applies to every cell, so all six expected counts are 40, meeting the Large Counts condition.

$$ \begin{array}{c|ccc} &\text{App}&\text{Radio}&\text{Print}\\ 18\text{–}39&40&40&40\\ 40\text{ and older}&40&40&40 \end{array} $$

The observed counts differ from their expected counts by \(15,-5,-10\) in the first row and \(-15,5,10\) in the second. Therefore:

$$ X^2 =2\left(\frac{15^2}{40}+\frac{5^2}{40}+\frac{10^2}{40}\right) =2(5.625+0.625+2.5) =17.5 $$

There are \(r=2\) rows and \(c=3\) columns, so \(df=(2-1)(3-1)=2\). The upper-tail p-value is approximately \(0.0002\), rounded to four decimal places.

Conclude. At \(\alpha=0.05\), \(0.0002<0.05\), so reject \(H_0\). The survey provides convincing evidence that age group and primary source of local news are associated among the municipality’s adult residents. Because this is a survey rather than a randomized experiment, the results do not show that age group causes people to choose a particular news source. The sample also does not identify which specific differences are independently significant; the test assesses the overall table.

Worked Example: Travel Mode and Preferred Commute Time

Suppose a random sample of 180 residents is asked about their usual travel mode to work and whether they prefer an earlier, middle, or later commute time. The adult population from which the sample is selected is 9,000. These invented counts are recorded:

Usual travel modeEarlierMiddleLaterTotal
Public transit35282790
Car25323390
Total606060180

State. The population is the adult residents represented by the sample. \(H_0\): usual travel mode and preferred commute time are independent in this population. \(H_a\): usual travel mode and preferred commute time are associated.

Plan. A chi-square test of independence fits because one sample is classified by two categorical variables. The sample was randomly selected. Each resident gives one response to each variable and appears in one table cell. The 10% check is \(180\leq0.10(9{,}000)=900\), so it is met. Every expected count is \(90(60)/180=30\), which is at least 5.

Do. The expected count is 30 in each of the six cells. The differences between observed and expected counts are \(5,-2,-3\) in the first row and \(-5,2,3\) in the second. Thus:

$$ X^2 =2\left(\frac{5^2}{30}+\frac{2^2}{30}+\frac{3^2}{30}\right) =\frac{76}{30} \approx2.5333 $$

The degrees of freedom are \((2-1)(3-1)=2\), and the upper-tail p-value is approximately \(0.2817\), rounded to four decimal places.

Conclude. At \(\alpha=0.05\), \(0.2817>0.05\), so fail to reject \(H_0\). The sample does not provide convincing evidence of an association between usual travel mode and preferred commute time in the population. This does not prove that the variables are independent; it means the observed differences do not provide strong evidence against independence.

Worked Example: Recycling Access and Familiarity

Suppose a random sample of 200 residents is asked whether their home has convenient recycling access and whether they are familiar with the local recycling guidelines. Each variable has two categories. The adult population is 12,000. The following invented counts are obtained:

Recycling accessFamiliarNot familiarTotal
Convenient5842100
Not convenient4258100
Total100100200

State. The population is the adult residents represented by the sample. \(H_0\): recycling access and familiarity with the guidelines are independent in this population. \(H_a\): recycling access and familiarity are associated.

Plan. Use a chi-square test of independence because one sample is classified by two categorical variables. The sample is random, and each person is counted once. The 10% condition is satisfied because \(200\leq0.10(12{,}000)=1{,}200\). Each expected count is \(100(100)/200=50\), so the expected-count condition is met.

Do. Each observed count differs from its expected count of 50 by 8 in absolute value. Therefore:

$$ X^2=4\left(\frac{8^2}{50}\right) =4\left(\frac{64}{50}\right) =5.12 $$

The degrees of freedom are \((2-1)(2-1)=1\). The upper-tail p-value is approximately \(0.0236\), rounded to four decimal places.

Conclude. At \(\alpha=0.05\), \(0.0236<0.05\), so reject \(H_0\). The survey provides convincing evidence that convenient recycling access and familiarity with the guidelines are associated among the adult residents represented by the sample. The data do not establish that access causes familiarity: other factors could be related to both.

Common Mistakes and AP Exam Tip

  • Choosing the test from the table’s appearance alone: A two-way table can be used for different chi-square procedures. One sample classified by two variables calls for a test of independence; separate groups compared on one response call for homogeneity.
  • Writing hypotheses about the sample: The hypotheses are claims about the population variables, not about whether the sample percentages look exactly equal. Define both variables and the population, then state independence versus association.
  • Forgetting a condition: Explicitly address random sampling, independent observations, the 10% condition when sampling without replacement, and every expected count. Do not check the expected-count condition using observed counts.
  • Interpreting a large p-value as proof of independence: “Fail to reject” means the data do not provide convincing evidence of an association. It does not prove that there is no association.
  • Claiming causation from a survey: A random sample can support generalizing results to its population, but it does not create random assignment. An observed association does not establish a cause-and-effect relationship.
  • Claiming a particular cell difference is significant from the overall test: A significant chi-square result indicates an overall departure from independence. It does not, by itself, identify which cells or category comparisons account for that result.

For full-credit communication, name the test, give the decision, and state what the evidence says about the two variables in the population. For a survey, distinguish generalization supported by random sampling from causal conclusions, which the survey design does not establish.

Key takeaway: A chi-square test of independence uses one sample classified by two categorical variables to assess evidence of population association. Check the sampling and expected-count conditions, then interpret the conclusion in context without turning an observational association into a causal claim.

Check Your Understanding

Use the study design, hypotheses, conditions, and conclusion wording in your answers.

  1. A random sample of residents is classified by neighborhood and preferred park activity. Which chi-square procedure fits, and what does its null hypothesis say?
  2. A sample of 300 is taken without replacement from a population of 2,500. Is the 10% condition met? Show the comparison.
  3. A test of independence has \(r=3\) row categories and \(c=4\) column categories. Find its degrees of freedom.
  4. A test has \(p=0.18\) and \(\alpha=0.05\). State the decision and explain what it means in context, without claiming the variables are proven independent.
  5. Why can a random survey support generalization to a population but still not establish that one categorical variable causes the other?