Sub topic 8
X-bar and R Charts: Means and Ranges of Subgroups
This chapter assumes you can read an individuals chart, know what a center line and 3-sigma limits are, and understand rational subgroups. It also assumes you are comfortable with mean, range, and standard deviation, and with basic NumPy. By the end you will be able to build an X-bar and R chart from raw subgroup data, explain where the constants come from, and avoid the usual mistakes.
Why chart subgroups instead of single values
An I-MR chart plots every measurement on its own. That works when you can only measure one item per period. When you can collect several measurements close together in time, you can do better. You can take a small sample, called a subgroup, at each sampling point and plot two statistics:
- The subgroup mean (X-bar) shows where the process is centered.
- The subgroup range (R) shows how spread out the process is within that moment.
This has two advantages. First, means of several values vary less than individual values, so the X-bar chart is more sensitive to small shifts in the average. Second, the two charts separate location from spread, so you can tell which one moved.
A subgroup is only useful if it is rational. The values in one subgroup should be made under the same conditions, such as one machine, one operator, and one short stretch of time. Then the variation inside a subgroup contains only common-cause variation. Differences between subgroups are where special causes show up.
The structure of the two charts
The two charts are read together.
| Chart | Plots | Detects | Center line |
|---|---|---|---|
| R chart | Range of each subgroup | Changes in within-subgroup spread | R-bar, the average range |
| X-bar chart | Mean of each subgroup | Shifts in the process average | X-double-bar, the grand mean |
The X-bar limits are built from R-bar. If the R chart is out of control, R-bar is not a reliable estimate of the common-cause spread, and the X-bar limits are not trustworthy either. This is why you check the R chart first.
The calculations
For k subgroups, each of size n:
- Compute each subgroup's mean and range (maximum minus minimum).
- Compute the grand mean, X-double-bar, as the average of the subgroup means.
- Compute R-bar as the average of the subgroup ranges.
- Compute the limits:
- X-bar chart: center X-double-bar, limits X-double-bar ± A2 × R-bar.
- R chart: center R-bar, UCL = D4 × R-bar, LCL = D3 × R-bar.
A2, D3, and D4 are constants that depend only on n.
| n | A2 | D3 | D4 | d2 |
|---|---|---|---|---|
| 2 | 1.880 | 0 | 3.267 | 1.128 |
| 3 | 1.023 | 0 | 2.574 | 1.693 |
| 4 | 0.729 | 0 | 2.282 | 2.059 |
| 5 | 0.577 | 0 | 2.114 | 2.326 |
| 6 | 0.483 | 0 | 2.004 | 2.534 |
| 7 | 0.419 | 0.076 | 1.924 | 2.704 |
| 8 | 0.373 | 0.136 | 1.864 | 2.847 |
| 9 | 0.337 | 0.184 | 1.816 | 2.970 |
| 10 | 0.308 | 0.223 | 1.777 | 3.078 |
Where the constants come from
The average range of subgroups of size n is d2 times the process standard deviation. So you can estimate the within-subgroup standard deviation as sigma-hat = R-bar / d2.
The mean of n values has standard deviation sigma / sqrt(n). The 3-sigma limits for the X-bar chart are therefore X-double-bar ± 3 × sigma-hat / sqrt(n). Substitute sigma-hat and you get
A2 = 3 / (d2 × sqrt(n)).
For n = 5 this is 3 / (2.326 × 2.236) = 0.577. D3 and D4 are built the same way, from the spread of the range itself. D3 is zero for n ≤ 6 because the computed lower limit would be negative, and a range cannot be negative.
The constant is a shortcut for "3 sigma", not a different kind of limit. Knowing this helps you spot a wrong constant, such as using the I-MR value 2.66 here.
A worked example in Python
The code below uses five subgroups of five measurements, such as shaft diameters in millimeters.
import numpy as np
# Constants for subgroup size n = 5
A2, D3, D4 = 0.577, 0.0, 2.114
# Each row is one subgroup of 5 measurements
data = np.array([
[5.02, 4.98, 5.01, 5.00, 4.99],
[5.03, 5.00, 4.97, 5.01, 5.02],
[4.99, 5.01, 5.00, 5.04, 4.98],
[5.00, 5.02, 4.96, 5.01, 5.00],
[5.01, 4.99, 5.03, 5.00, 4.97],
])
xbars = data.mean(axis=1)
ranges = data.max(axis=1) - data.min(axis=1)
xbarbar = xbars.mean()
rbar = ranges.mean()
xbar_ucl = xbarbar + A2 * rbar
xbar_lcl = xbarbar - A2 * rbar
r_ucl = D4 * rbar
r_lcl = D3 * rbar
print(xbar_lcl, xbarbar, xbar_ucl)
print(r_lcl, rbar, r_ucl)The subgroup means are 5.000, 5.006, 5.004, 4.998, and 5.000, so X-double-bar is 5.0016. The ranges are 0.04, 0.06, 0.06, 0.06, and 0.06, so R-bar is 0.056. The limits are:
- X-bar chart: LCL ≈ 4.969, center 5.0016, UCL ≈ 5.034.
- R chart: LCL 0, center 0.056, UCL ≈ 0.118.
All subgroup means lie well inside the X-bar limits, and all ranges lie below the R UCL. Five subgroups are too few for real limits, though. Use at least 20 to 25 subgroups for a baseline, because R-bar from a handful of ranges is itself very noisy.
Making it reusable
In practice you want a function that looks up the constants from n. This version handles any n from 2 to 10 and also returns the within-subgroup sigma estimate.
import numpy as np
# n: (A2, D3, D4, d2)
CONSTANTS = {
2: (1.880, 0.0, 3.267, 1.128),
3: (1.023, 0.0, 2.574, 1.693),
4: (0.729, 0.0, 2.282, 2.059),
5: (0.577, 0.0, 2.114, 2.326),
6: (0.483, 0.0, 2.004, 2.534),
7: (0.419, 0.076, 1.924, 2.704),
8: (0.373, 0.136, 1.864, 2.847),
9: (0.337, 0.184, 1.816, 2.970),
10: (0.308, 0.223, 1.777, 3.078),
}
def xbar_r_limits(data):
"""data: 2D array, one row per subgroup, equal subgroup size."""
data = np.asarray(data, dtype=float)
n = data.shape[1]
if n not in CONSTANTS:
raise ValueError("Subgroup size must be between 2 and 10 for an R chart")
A2, D3, D4, d2 = CONSTANTS[n]
xbarbar = data.mean(axis=1).mean()
rbar = (data.max(axis=1) - data.min(axis=1)).mean()
return {
"xbar": (xbarbar - A2 * rbar, xbarbar, xbarbar + A2 * rbar),
"r": (D3 * rbar, rbar, D4 * rbar),
"sigma_within": rbar / d2,
}
rng = np.random.default_rng(7)
sample = rng.normal(loc=50.0, scale=0.4, size=(25, 4))
print(xbar_r_limits(sample))The sigma_within value is what a capability analysis would later use. It describes short-term variation only.
Reading the pair of charts
Start with the R chart, then read the X-bar chart.
- R chart out of control, point above the UCL. One subgroup had unusual spread. Look for a mixed material lot, a loose fixture, or a measurement error in that subgroup.
- R chart trending upward. Spread is growing, perhaps from tool wear or a degrading gauge.
- R chart points consistently low. This can be an improvement worth keeping, but it can also mean the gauge resolution is too coarse. Rounded values give many equal readings and small ranges.
- X-bar chart out of control. The average shifted. Check settings, material changes, and operator or shift differences.
- Both charts move together. Suspect a cause that changes both level and spread, or a data entry problem.
The signal rules from the earlier chapter apply to both charts. Points beyond the limits and runs of eight on one side of the center line are the common ones. Apply them to the R chart as well. Its distribution is skewed, so run rules on the R chart are approximate.
Edge cases and design choices
Choosing n. Subgroups of 4 or 5 are common. Larger n makes the X-bar chart more sensitive to small shifts. It also risks including variation from different conditions in the same subgroup, which defeats the rational-subgroup idea. Spend effort on how often you sample before spending it on larger subgroups.
Large subgroups. For n above about 10, the range uses only the two extreme values and becomes an inefficient estimate of spread. Use an X-bar and S chart, which uses the subgroup standard deviation, instead.
Unequal subgroup sizes. The constants assume a fixed n. If a subgroup is occasionally short, you can compute separate limits for that point with its own n. If sizes vary a lot, the X-bar and S chart with per-point limits is easier to manage.
Subgroup size 1. There is no range within a subgroup. Use an I-MR chart.
The R chart's lower limit. For n ≤ 6 the LCL is zero, so the R chart cannot signal a drop in spread through a point below the limit. You can only detect it with run rules, which is another reason to use them.
Stratification. If the X-bar points cluster unnaturally close to the center line, with far less variation than the limits imply, the subgroups probably mix several streams. For example, a subgroup might contain one part from each of five spindles. Then the range is inflated by the spindle differences, R-bar is too large, and the limits become too wide to detect anything. Re-form the subgroups by stream, or chart each stream separately.
Between-subgroup variation. The limits assume that most variation sits within subgroups. If there is real drift between subgroups that is part of normal operation, the X-bar chart will show many false alarms. This is a signal that the subgroup design or the chart type does not fit the process. A charting variant for this case exists, but moving to it is a modeling decision, not a limit adjustment.
Do not widen limits to quiet the chart. If points alarm too often, find out why. Moving the limits to fit does not make the process more stable.
Common errors
- Using 2.66 or 3.267 (the I-MR constants) on X-bar and R data.
- Computing limits from the standard deviation of all the individual values pooled together. That standard deviation includes between-subgroup variation, so the limits come out too wide and hide real signals.
- Reading the X-bar chart without first checking the R chart.
- Recalculating limits after every new subgroup. Limits come from a stable baseline and stay fixed during monitoring.
- Leaving special-cause subgroups in the baseline. Investigate them, remove them when you have an assignable cause, and recompute.
Exercise
A process makes subgroups of n = 4 measurements. From 25 stable baseline subgroups you get X-double-bar = 20.0 and R-bar = 1.5. Using A2 = 0.729, D3 = 0, and D4 = 2.282, compute the control limits for both charts. Then say what a new subgroup with a range of 3.8 tells you.
Show answer
X-bar chart: 20.0 ± 0.729 × 1.5 = 20.0 ± 1.0935, so LCL = 18.9065 and UCL = 21.0935. R chart: center 1.5, LCL = 0 × 1.5 = 0, UCL = 2.282 × 1.5 = 3.423. A range of 3.8 is above the R UCL of 3.423, so it is a special-cause signal for spread. Investigate that subgroup for a cause such as mixed material or a measurement problem. Treat the mean of that subgroup with caution until the cause is understood, because the X-bar limits assume the spread is stable.
Exercise
A team computes X-bar limits by taking the standard deviation s of all 100 individual measurements from 25 subgroups and using X-double-bar ± 3s / sqrt(5). Explain why this can hide a real signal.
Show answer
The standard deviation of all pooled values includes variation between subgroups as well as within them. If a special cause shifted the mean in some subgroups, that shift inflates s, which widens the limits. The wider limits can then contain the shifted subgroup means, so the chart fails to signal. Estimating sigma from R-bar / d2 uses only within-subgroup variation, which is the right basis for judging whether the subgroup means differ more than chance allows.