Sub topic 5
Measuring spread: mean and standard deviation
This chapter assumes you can do basic arithmetic and percentages, know what a mean is, and have a rough picture of a distribution as a histogram. It also assumes you know a process turns inputs into outputs. Earlier chapters showed that no two outputs are identical. Here we put a number on how different they are.
Why two numbers are needed
A single measurement tells you little about a process. Ten shafts cut on one lathe will not all have the same diameter. To describe the process, you need two things:
- Location: where the outputs are centered. The mean describes this.
- Spread: how far individual outputs stray from that center. The standard deviation describes this.
Two processes can have the same mean and very different spread. The first might cut shafts that are all within 0.03 mm of 10 mm. The second might also average 10 mm but produce shafts anywhere from 9.85 to 10.15 mm. A customer who needs 10 mm will be far happier with the first. Six Sigma depends on this idea, because defects come from spread, not only from a wrong average.
The mean
The mean is the sum of the values divided by their count:
x̄ = (x₁ + x₂ + … + xₙ) / n
It locates the center of the process. If the mean is off target, you have a centering problem, and you can often fix it with a single adjustment such as an offset on a machine.
The mean says nothing about consistency. A process that alternates between 9.0 and 11.0 has the same mean as one that always produces 10.0.
The standard deviation
The standard deviation answers a plain question: how far is a typical output from the mean? The calculation has four steps.
- Compute the mean.
- Subtract the mean from each value to get its deviation.
- Square each deviation and add them up.
- Divide by n − 1, then take the square root.
Squaring serves two purposes. Deviations above and below the mean would otherwise cancel to zero, and squaring also makes large deviations count for more than small ones. Taking the square root at the end returns the result to the original units, so a standard deviation of shaft diameters is in millimeters.
A worked example
Ten shafts from one production run measured these diameters in mm:
10.02, 9.98, 10.05, 9.97, 10.01, 10.03, 9.99, 10.00, 10.04, 9.96
The values add up to 100.05, so the mean is 10.005 mm. The deviations from the mean are 0.015, −0.025, 0.045, −0.035, 0.005, 0.025, −0.015, −0.005, 0.035 and −0.045. Their squares sum to 0.00825 mm². Dividing by n − 1 = 9 gives a variance of about 0.000917 mm². The square root is about 0.0303 mm.
The same calculation in Python:
from statistics import mean, stdev
# Shaft diameters in mm from one production run
measurements = [10.02, 9.98, 10.05, 9.97, 10.01, 10.03, 9.99, 10.00, 10.04, 9.96]
print("mean:", mean(measurements))
print("sample standard deviation:", stdev(measurements))The output is a mean of 10.005 and a standard deviation of about 0.0303, matching the hand calculation.
Sample versus population: why n − 1
Python offers both stdev and pstdev. They differ only in the divisor.
| Function | Divisor | Use when |
|---|---|---|
| `stdev` | n − 1 | The data is a sample drawn from a larger process |
| `pstdev` | n | The data is every item that exists, such as a whole closed batch |
In process work you almost always have a sample. The ten shafts stand in for all the shafts the process could make. A sample's values sit closer to the sample's own mean than to the true process mean, because the sample mean is computed from those same values. Dividing by n would therefore underestimate the spread. Dividing by n − 1 corrects most of that bias. This is called Bessel's correction.
For the shaft data, pstdev gives about 0.0287 mm and stdev gives about 0.0303 mm. With ten points the difference is about 5%. With a few hundred points it becomes negligible. With three or four points it matters a great deal.
You can check the formula with a function that follows the four steps:
from math import sqrt
from statistics import mean, stdev, pstdev
def sample_sd(data):
n = len(data)
if n < 2:
raise ValueError("need at least two values for a sample standard deviation")
m = mean(data)
squared_deviations = [(x - m) ** 2 for x in data]
return sqrt(sum(squared_deviations) / (n - 1))
measurements = [10.02, 9.98, 10.05, 9.97, 10.01, 10.03, 9.99, 10.00, 10.04, 9.96]
print(sample_sd(measurements))
print(stdev(measurements))
print(pstdev(measurements))The first two lines agree. The third is smaller.
Reading a standard deviation
A standard deviation has no meaning without the units and the mean beside it. A value of 0.03 mm is tiny for a shaft near 10 mm and huge for a semiconductor feature measured in nanometers. The standard deviation is also not the average distance from the mean. It weights large deviations more heavily, so it is always at least as large as the average absolute deviation.
Two processes make the point. Process A is the shaft data above. Process B has the same pattern of deviations stretched to three times the size:
from statistics import mean, stdev
process_a = [10.02, 9.98, 10.05, 9.97, 10.01, 10.03, 9.99, 10.00, 10.04, 9.96]
process_b = [10.06, 9.94, 10.15, 9.91, 10.03, 10.09, 9.97, 10.00, 10.12, 9.88]
for name, data in (("A", process_a), ("B", process_b)):
print(name, "mean", round(mean(data), 4), "sd", round(stdev(data), 4))The means are close, 10.005 and 10.015, and the standard deviations are about 0.0303 and 0.0908. Process B is three times as spread out. Anyone comparing only the means would call these processes equivalent.
If the data looks roughly bell-shaped, the standard deviation has a handy interpretation. About two thirds of the outputs fall within one standard deviation of the mean. Nearly all fall within three. The next chapter develops this, and the sigma level and control limits later in the tutorial depend on it.
Common errors
Using the wrong divisor. Calling pstdev on a sample understates spread. Because the understated spread makes the process look better than it is, the error is easy to miss.
Treating a standard deviation from too few points as precise. A sample standard deviation is itself an estimate and varies from sample to sample. With ten points it is only a rough guide. With thirty or more it becomes steadier.
Mixing sources of variation in one sample. If you pool shafts from two machines, two shifts or two material lots, the standard deviation includes the differences between them. The result may describe neither machine. It is often useful to compute the standard deviation within each group first and compare.
Ignoring time order. The mean and standard deviation discard the order of the data. A process that drifts steadily upward can produce the same numbers as a stable process with the same values shuffled. Plotting the data in time order, as a control chart does, catches what the summary hides.
Letting an outlier dominate. Because deviations are squared, one extreme value inflates the standard deviation. Adding a single 10.40 mm shaft to the ten above raises the sample standard deviation from about 0.0303 to about 0.1225 mm. First find out whether the extreme value is a measurement mistake or a real special cause. Do not delete it just to get a better number.
Where this leads
The mean and standard deviation are the inputs to the rest of the tutorial. Control limits are placed three estimated standard deviations from the center line. Cp and Cpk compare six standard deviations to the width of the customer's tolerance. The sigma level counts how many standard deviations fit between the mean and the nearest specification limit. Each of these is built from the two numbers in this chapter.
Exercise
Exercise
A sample of five fill volumes in milliliters is 4, 8, 6, 5, 7. Compute the mean, the sample standard deviation, and the population standard deviation. Then say which one you would report for the filling process and why.
Show answer
The mean is (4 + 8 + 6 + 5 + 7) / 5 = 6. The deviations are -2, 2, 0, -1, 1, and their squares sum to 4 + 4 + 0 + 1 + 1 = 10. The sample standard deviation is sqrt(10 / 4) = sqrt(2.5), about 1.58 mL. The population standard deviation is sqrt(10 / 5) = sqrt(2), about 1.41 mL. Report the sample standard deviation, because the five fills are a sample of everything the process could produce, and dividing by n - 1 corrects the tendency of a sample to understate the spread.
Exercise
Two machines both average 25.0 mm. Machine 1 has a sample standard deviation of 0.04 mm and machine 2 has 0.12 mm. A coworker says the machines perform the same because the means match. What is wrong with that claim, and what would you check before comparing them further?
Show answer
The mean only locates the center, so matching means say nothing about consistency. Machine 2's spread is three times that of machine 1, so it will produce many more parts far from 25.0 mm and more parts outside any given tolerance. Before comparing, check that each sample came from a stable process, for example by plotting the values in time order, and confirm that the sample sizes are large enough for the standard deviations to be reliable.