10.7 Lab 1: Chi-Square Goodness-of-Fit
SLO 4
Demonstrate an understanding of, and ability to use, basic ideas of statistical processes, including hypothesis tests and confidence interval estimation.
SLO 5
Identify appropriate statistical techniques and use technology-based statistical analysis to describe, interpret, and communicate results.
Learning Objectives
By the end of this lab, you will be able to:
- collect a small real-world data set and organize it into categories suitable for a chi-square test;
- build expected counts for a uniform distribution and for an exponential distribution from your own data;
- run a goodness-of-fit test against each distribution and state a conclusion in a complete sentence;
- explain what it means when a data set appears to fit more than one distribution, or neither.
Everything in this chapter so far arrived as a finished table. This lab is where you make the table yourself, and that changes the difficulty in a way worth naming up front: real receipts do not sort themselves into tidy categories with expected counts above five. You will have to choose the intervals, check the condition, and combine categories when it fails — all before any of the arithmetic from Section 10.2 becomes usable.
10.7.1 Student Learning Outcome
The student will evaluate data collected to determine if they fit either the uniform or exponential distributions.
Every cell needs an expected value of at least five. With only 30 receipts spread across five or six intervals you are working close to that floor from the start, so expect to merge at least once — and remember from Section 10.2 that each merge costs you a category and therefore one degree of freedom.
Before collecting anything, work out how thin your data can get. If you collect 30 receipts and divide them into five equal-probability intervals, what is the expected count in each interval? What if you used six intervals instead, and what does that tell you about the largest number of intervals this sample size can support?
Solution — sizing the categories before collecting
Step 1 — Find the expected count for five intervals. Equal-probability fifths each hold one fifth of the sample:
$$ E = \frac{30}{5} = 6 $$Step 2 — Check that against the condition. Six is at least five, so five intervals is legal — but only barely.
Step 3 — Find the expected count for six intervals.
$$ E = \frac{30}{6} = 5 $$Step 4 — Check that against the condition. Exactly five, which satisfies "at least five" with nothing to spare.
Step 5 — Find the limit. Seven intervals would give \(\frac{30}{7} \approx 4.3\), below the floor. So 30 observations support at most six equal-probability intervals.
Answer: Five intervals give \(E = 6\) and six give \(E = 5\). Six is the maximum this sample size supports, which is why the lab asks for five to six.
10.7.2 Collect the Data
Go to your local supermarket. Ask 30 people as they leave for the total amount on their grocery receipts. (Or, ask three cashiers for the last ten amounts. Be sure to include the express lane, if it is open.)
- Record the values in Table 10.7.1.
- Construct a histogram of the data. Make five to six intervals. Sketch the graph using a ruler and pencil, and scale the axes, with relative frequency on the vertical axis and amount of receipt on the horizontal axis.
- Calculate the following:
a. \(\overline{x} =\) ____
b. \(s =\) ____
c. \(s^{2} =\) ____
A student collects 30 receipts and finds the smallest is $4.12 and the largest is $147.80. Explain why asking three cashiers for their last ten amounts might produce a different-looking sample than asking 30 departing customers, and why the lab specifically says to include the express lane if it is open.
Solution — how the collection method shapes the data
Step 1 — Consider what a cashier's last ten amounts represent. They are ten consecutive transactions at one register, so they share a time of day and a register type. Consecutive transactions at one till are not independent draws from all shoppers.
Step 2 — Consider what 30 departing customers represent. They come from every open register across the time you are standing there, so the sample spreads over register types and shopper types.
Step 3 — Explain the express lane instruction. Express lanes cap the number of items, which caps the receipt total. Omitting them removes most of the small receipts and truncates the low end of the distribution.
Step 4 — Connect this to the test. Both distributions being tested depend on the whole spread of values. Cutting off the small totals would shift the interval boundaries and the expected counts, so the test would be answering a question about express-lane-free shopping rather than about shopping.
Answer: Consecutive transactions at one register are not independent and share a time and register type, while the express lane holds the small receipts. Excluding either one biases the shape of the distribution the test is about.
A student's 30 receipts give \(\overline{x} = 42.60\) and \(s = 31.85\). Compute \(s^{2}\), and explain what role each of these three numbers plays later in the lab. Which of them is NOT used by the uniform test?
Solution — what each summary statistic is for
Step 1 — Compute the sample variance. The variance is the square of the standard deviation:
$$ s^{2} = (31.85)^{2} \approx 1014.42 $$Step 2 — Say what \(\overline{x}\) is for. The sample mean supplies the decay parameter for the exponential test, \(m = \frac{1}{\overline{x}} = \frac{1}{42.60} \approx 0.0235\). Without it that half of the lab cannot start.
Step 3 — Say what \(s\) and \(s^{2}\) are for. They describe the spread of the receipts and let you compare the two fitted distributions against the data's actual variability. Neither enters the chi-square statistic itself.
Step 4 — Identify what the uniform test uses. The uniform test needs only the lowest and highest values, which set \(X \sim U(a, b)\), and then counts within fifths. It never uses \(\overline{x}\), \(s\) or \(s^{2}\).
Answer: \(s^{2} \approx 1014.42\). The mean supplies the exponential decay parameter; \(s\) and \(s^{2}\) describe spread but enter neither test statistic. The uniform test uses none of the three — only the minimum and maximum.
10.7.3 Testing the Uniform Distribution
Test to see if grocery receipts follow the uniform distribution.
- Using your lowest and highest values, \(X \sim U(\_\_\_\_, \_\_\_\_)\)
- Divide the distribution into fifths.
- Calculate the following:
a. lowest value = ____
b. \(20^{th}\) percentile = ____
c. \(40^{th}\) percentile = ____
d. \(60^{th}\) percentile = ____
e. \(80^{th}\) percentile = ____
f. highest value = ____
- For each fifth, count the observed number of receipts and record it. Then determine the expected number of receipts and record that.
| Fifth | Observed | Expected |
|---|---|---|
| \(1^{st}\) | ||
| \(2^{nd}\) | ||
| \(3^{rd}\) | ||
| \(4^{th}\) | ||
| \(5^{th}\) |
- \(H_{0}\): ____
- \(H_{a}\): ____
- What distribution should you use for a hypothesis test?
- Why did you choose this distribution?
- Calculate the test statistic.
- Find the \(p\)-value.
- Sketch a graph of the situation. Label and scale the x-axis, and shade the area corresponding to the p-value.
- State your decision.
- State your conclusion in a complete sentence.
For the uniform test above, state the hypotheses in words, the distribution you should use, and the degrees of freedom. Then explain why dividing into fifths makes every expected count identical.
Solution — setting up the uniform goodness-of-fit test
Step 1 — Write the hypotheses.
\(H_{0}\): The grocery receipt amounts fit the uniform distribution.
\(H_{a}\): The grocery receipt amounts do not fit the uniform distribution.
Step 2 — Name the distribution for the test. A goodness-of-fit test uses the chi-square distribution, and it is right-tailed.
Step 3 — Find the degrees of freedom. There are five categories, one per fifth:
$$ df = \text{number of categories} - 1 = 5 - 1 = 4 $$so the distribution for the test is \(\chi_{4}^{2}\).
Step 4 — Explain the identical expected counts. A fifth of a distribution holds 20% of its probability by construction, whatever the shape of the interval widths. With 30 receipts, each fifth is therefore expected to hold \((0.20)(30) = 6\).
Answer: \(H_{0}\): the receipts fit the uniform distribution; \(H_{a}\): they do not; use \(\chi_{4}^{2}\) with \(df = 4\). Every expected count is 6 because each fifth carries 20% of the probability by definition.
A student's receipts run from a low of $4.00 to a high of $144.00. Treating the data as \(X \sim U(4, 144)\), find the four interior cut points that divide the distribution into fifths.
Solution — percentiles of a uniform distribution
Step 1 — Find the width of the interval. The range runs from 4 to 144, so its width is \(144 - 4 = 140\).
Step 2 — Use the uniform percentile rule. For \(X \sim U(a,b)\), the \(k\)th percentile sits a fraction \(k\) of the way along the interval:
$$ P_{k} = a + k(b - a) $$Step 3 — Compute each cut point.
$$ P_{20} = 4 + 0.20(140) = 32 \qquad P_{40} = 4 + 0.40(140) = 60 $$ $$ P_{60} = 4 + 0.60(140) = 88 \qquad P_{80} = 4 + 0.80(140) = 116 $$Step 4 — State the five intervals. They are $4–$32, $32–$60, $60–$88, $88–$116 and $116–$144, each 28 dollars wide.
Answer: The cut points are 32, 60, 88 and 116. Under a uniform distribution the fifths are equal in WIDTH as well as in probability, which is what makes this the easy case.
A student runs the uniform test and finds the observed counts in the five fifths are 12, 9, 5, 3 and 1. State whether the expected-count condition is satisfied, then explain what must be done and what happens to the degrees of freedom.
Solution — a lopsided table that is still legal
Step 1 — Find the expected counts. Under the uniform hypothesis each fifth is expected to hold \(\frac{30}{5} = 6\) receipts.
Step 2 — Check the condition. The condition constrains the EXPECTED counts, and every one of them is 6, which is at least five. The condition is satisfied.
Step 3 — Address the small observed counts. Observed counts of 3 and 1 are not a violation. They are the evidence — they are exactly the mismatch the test exists to measure.
Step 4 — State the consequence. Nothing needs to be merged, and the degrees of freedom stays at \(df = 5 - 1 = 4\).
Step 5 — Anticipate the result. With counts sliding from 12 down to 1 against a flat expectation of 6, the terms \(\frac{(O-E)^{2}}{E}\) will be large and the test will very likely reject the uniform hypothesis.
Answer: The condition IS satisfied, because every expected count is 6. No merging is needed and \(df\) remains 4. The small observed counts are the signal, not a problem with the setup.
10.7.4 Testing the Exponential Distribution
Test to see if grocery receipts follow the exponential distribution with decay parameter \(\frac{1}{\overline{x}}\).
- Using \(\frac{1}{\overline{x}}\) as the decay parameter, \(X \sim Exp(\_\_\_\_)\).
- Calculate the following:
a. lowest value = ____
b. first quartile = ____
c. \(37^{th}\) percentile = ____
d. median = ____
e. \(63^{rd}\) percentile = ____
f. \(3^{rd}\) quartile = ____
g. highest value = ____
- For each cell, count the observed number of receipts and record it. Then determine the expected number of receipts and record that.
| Cell | Observed | Expected |
|---|---|---|
| \(1^{st}\) | ||
| \(2^{nd}\) | ||
| \(3^{rd}\) | ||
| \(4^{th}\) | ||
| \(5^{th}\) | ||
| \(6^{th}\) |
- \(H_{0}\): ____
- \(H_{a}\): ____
- What distribution should you use for a hypothesis test?
- Why did you choose this distribution?
- Calculate the test statistic.
- Find the p-value.
- Sketch a graph of the situation. Label and scale the x-axis, and shade the area corresponding to the p-value.
- State your decision.
- State your conclusion in a complete sentence.
A student's receipts give \(\overline{x} = 42.60\). State the decay parameter and write the exponential distribution. Then explain why this test uses a parameter estimated from the data while the uniform test did not.
Solution — a parameter borrowed from the sample
Step 1 — Compute the decay parameter. The lab specifies \(m = \frac{1}{\overline{x}}\):
$$ m = \frac{1}{42.60} \approx 0.0235 $$Step 2 — Write the distribution. \(X \sim Exp(0.0235)\).
Step 3 — Compare with the uniform setup. The uniform test also took its endpoints from the data, using the lowest and highest observed values as \(a\) and \(b\). Both tests therefore borrow from the sample.
Step 4 — Note what that costs. A distribution whose parameters were estimated from the same data being tested will fit that data better than one specified in advance, which makes the test more reluctant to reject. This lab keeps the degrees of freedom at cells minus one for simplicity, but it is the reason a strict treatment subtracts one further degree of freedom per estimated parameter.
Answer: \(m \approx 0.0235\), so \(X \sim Exp(0.0235)\). Both tests estimate their parameters from the sample, which biases each toward fitting.
The exponential test uses six cells cut at the quartiles, the median, and the 37th and 63rd percentiles. With 30 receipts, find the expected count per cell and the degrees of freedom, then explain why these cut points are chosen rather than six equal-width intervals.
Solution — percentile cuts versus equal widths
Step 1 — Find the expected count. Six equal-probability cells over 30 receipts give
$$ E = \frac{30}{6} = 5 $$which meets the at-least-five condition exactly.
Step 2 — Find the degrees of freedom. \(df = 6 - 1 = 5\), so the distribution for the test is \(\chi_{5}^{2}\).
Step 3 — Consider what equal-width intervals would do. An exponential distribution is heavily right-skewed. Cutting the range into six equal widths would pile most of the data into the first interval and leave the last ones nearly empty, producing expected counts far below five at the top end.
Step 4 — Explain the percentile cuts. Cutting at percentiles makes every cell carry the same probability under the claimed distribution, so every expected count is equal and the condition is satisfied everywhere at once.
Answer: \(E = 5\) per cell with \(df = 5\). Percentile cut points give equal expected counts, while equal-width intervals on a skewed distribution would starve the upper cells.
10.7.5 Discussion Questions
- Did your data fit either distribution? If so, which?
- In general, do you think it's likely that data could fit more than one distribution? In complete sentences, explain why or why not.
Suppose your uniform test gives a p-value of 0.31 and your exponential test gives a p-value of 0.42, both at a 5% significance level. State the decision for each, and explain carefully what you may and may not conclude about which distribution the receipts follow.
Solution — failing to reject twice is not fitting twice
Step 1 — Decide the uniform test. \(\alpha = 0.05\) and the p-value is 0.31, so \(\alpha <\) p-value. Do not reject \(H_{0}\).
Step 2 — Decide the exponential test. \(\alpha = 0.05\) and the p-value is 0.42, so \(\alpha <\) p-value. Do not reject \(H_{0}\).
Step 3 — State what that does establish. Neither test found sufficient evidence that the receipts fail to fit its distribution.
Step 4 — State what it does not establish. Failing to reject is not proof that a distribution fits. With only 30 observations the test has little power, so it will fail to reject many distributions — including ones the data genuinely do not follow.
Step 5 — Answer the discussion question directly. Two non-rejections do not mean the data follow both distributions. They mean the sample is too small to rule either out.
Answer: Do not reject in both cases. The correct conclusion is that this sample provides insufficient evidence against either distribution, not that the receipts follow both.
Key Terms
goodness-of-fit test — the chi-square test used here, comparing observed category counts against those a claimed distribution predicts.
uniform distribution — a distribution in which all outcomes over an interval are equally likely; written \(X \sim U(a, b)\) using the lowest and highest observed values.
exponential distribution — a right-skewed distribution written \(X \sim Exp(m)\), where the decay parameter used in this lab is \(m = \frac{1}{\overline{x}}\).
decay parameter — the rate \(\frac{1}{\overline{x}}\) that fixes an exponential distribution's shape.
expected count condition — the requirement that every cell's expected value be at least five; with 30 observations this caps the number of equal-probability cells at six.
percentile cut points — interval boundaries chosen so each cell carries equal probability under the claimed distribution, which keeps every expected count equal.