Sub topic 10
Comparing Two Groups: Two-Sample and Paired t-Tests
Prerequisites and the Analyze question
This chapter assumes that you can calculate a mean and standard deviation, read a box plot, distinguish a sample from a population, and explain the Analyze phase of DMAIC.
A two-group comparison asks whether the average output, or Y, differs between two conditions. For example:
- Does supplier A have a different delivery time from supplier B?
- Does a machine produce fewer defects after a maintenance change?
- Does the average cycle time change after a new work instruction?
The correct test depends first on how the observations were collected.
Independent two-sample t-test
Use an independent two-sample t-test when the observations in one group do not correspond to specific observations in the other group. The groups might contain different parts, employees, orders, or production runs.
Let the two population means be \( \mu1 \) and \( \mu2 \).
- Null hypothesis: \(H0: \mu1 - \mu_2 = 0\)
- Alternative hypothesis: \(HA: \mu1 - \mu_2 \ne 0\)
A two-sided alternative detects a difference in either direction. Use a one-sided alternative only when the direction was chosen before examining the data and the project question supports it.
Welch's t-test is usually a safe default because it does not require the two groups to have equal variances. Variance is the spread of observations around their mean.
Paired t-test
Use a paired t-test when each observation in one condition has a meaningful partner in the other condition. Common pairs include:
- The same part measured before and after a change
- The same employee measured under two methods
- Matched products made under similar conditions
For each pair, calculate a difference:
\[ di = \text{after}i - \text{before}_i \]
The paired t-test tests whether the mean difference is zero:
- Null hypothesis: \(H0: \mud = 0\)
- Alternative hypothesis: \(HA: \mud \ne 0\)
The test does not require the before values and after values to be independent. It requires the differences to be approximately normal and the pairs to be independent of other pairs.
import numpy as np
from scipy import stats
before = np.array([50, 52, 49, 51, 48, 53, 50, 49])
after = np.array([48, 50, 48, 50, 47, 51, 49, 48])
# Independent groups: use when observations are unrelated.
independent_result = stats.ttest_ind(
before, after, equal_var=False
)
# Paired observations: use when each position forms a before-after pair.
paired_result = stats.ttest_rel(before, after)
print("Welch independent test:", independent_result)
print("Paired test:", paired_result)
print("Mean paired change:", np.mean(after - before))Assumptions and selection
Check the process and the data collection plan before checking test output. A small p-value cannot repair dependent observations, severe outliers, or a biased sample.
| Question | Independent two-sample test | Paired t-test |
|---|---|---|
| Are observations naturally matched? | No | Yes |
| Main data analyzed | Values in each group | Within-pair differences |
| Normality concern | Each group | Differences |
| Equal variance required? | No for Welch's test | Not applicable |
| Typical example | Two production lines | Same parts before and after |
Use a histogram or a normal probability plot to inspect the relevant values. A Shapiro-Wilk test can provide additional evidence, but do not use it as the only decision rule. With small samples, it may miss non-normality. With large samples, it may flag harmless departures.
Interpreting the result
Choose a significance level, often \(\alpha = 0.05\), before testing. If the p-value is less than alpha, reject the null hypothesis. Otherwise, fail to reject it.
A p-value is the probability of obtaining results at least this extreme if the null hypothesis and the test assumptions are true. It is not the probability that the null hypothesis is true.
Report the estimated mean difference and a confidence interval along with the p-value. Then compare the size of the change with the project target. A statistically significant change of 0.02 minutes may not matter if the process target allows a one-minute improvement threshold.
Exercise
A team measures the cycle time of 20 randomly selected orders before a process change and 20 different randomly selected orders after the change. Which two-group test should it start with, and what should the null hypothesis state?
Show answer
It should start with Welch's independent two-sample t-test because the orders are different and not naturally matched. The null hypothesis is that the mean cycle time before and after the change is equal, or \(H0: \mu{\text{before}} - \mu_{\text{after}} = 0\).