Sub topic 13
Discrete Data: Proportion Tests and Chi-Square
Prerequisites and the Analyze question
This chapter assumes that you can calculate a mean, median, and standard deviation, read a histogram or box plot, and distinguish a sample from a population. It also assumes that you understand that the Analyze phase looks for evidence about possible causes of process variation.
Discrete data are counts or categories. Examples include defective versus non-defective, pass versus fail, and the number of complaints in a week. For these data, the main questions are:
- Does one observed proportion differ from a target?
- Do two groups have different proportions?
- Are two categorical variables associated?
The output, or Y, is often a defect status. An input, or X, might be shift, machine, supplier, or operator.
Choose the test from the question
| Process question | Typical test | Example |
|---|---|---|
| Does one proportion differ from a target? | One-sample proportion test | Is the defect rate different from 5%? |
| Do two groups have different proportions? | Two-proportion test | Does Shift 1 differ from Shift 2? |
| Are two categorical variables associated? | Chi-square test of independence | Is defect status associated with shift? |
A one-sample proportion test compares an observed proportion with a stated benchmark. A two-proportion test compares the proportions from two independent groups. A chi-square test of independence uses a contingency table, which contains counts for combinations of categories.
Chi-square testing with a contingency table
Suppose a team records defects by shift:
| Shift | Defective | Non-defective |
|---|---|---|
| 1 | 18 | 182 |
| 2 | 34 | 166 |
The null hypothesis says that defect status and shift are independent. The alternative hypothesis says that they are associated. The chi-square test compares the observed counts with expected counts. Expected counts are the counts we would anticipate if the variables were independent.
import numpy as np
from scipy import stats
# Rows: shift 1, shift 2. Columns: defective, non-defective.
table = np.array([[18, 182],
[34, 166]])
chi2, p_value, degrees_of_freedom, expected = stats.chi2_contingency(table)
print("chi2 =", chi2)
print("p =", p_value)
print("degrees of freedom =", degrees_of_freedom)
print("Expected counts:\n", expected)If the p-value is below the chosen significance level, often α = 0.05, reject the null hypothesis. This provides evidence that defect status is related to shift. It does not prove that shift causes the defects. Other variables, such as product mix or equipment condition, may explain the association.
Check expected counts before relying on a chi-square approximation. Very small expected counts can make the result unreliable. For a small 2-by-2 table, consider Fisher’s exact test instead.
Report the process meaning
Report the group proportions, not only the test statistic. In the example, Shift 1 has an observed defect rate of 18/200 = 9%, while Shift 2 has 34/200 = 17%. State the difference, confidence interval when available, p-value, and practical consequence. A statistically significant difference may still be too small to justify a process change.
Exercise
A team compares defect status with three machine settings. Which test should it use, and what should it inspect before interpreting the p-value?
Show answer
Use a chi-square test of independence. Inspect the observed and expected counts, especially for very small expected counts, and report the defect proportion for each setting.