Statistics formulas for SPC, capability and graphs
This page collects the formulas StatLab uses, one section per group of tools, so you can check a result by hand or see exactly what a number means. N is the number of values, x̄ their mean and s their sample standard deviation; x₍ᵢ₎ is the i-th smallest value; Φ is the standard normal cumulative distribution and Φ⁻¹ its inverse. Show code under any result gives the same calculation as runnable Python, with your data written in.
Descriptive statistics
x̄ = Σx / N
s = √( Σ(x − x̄)² / (N − 1) )
SE Mean = s / √N- Quartiles: Q1, the median and Q3 sit at rank (N + 1)p of the sorted data for p = 0.25, 0.5 and 0.75, interpolating between the two nearest values. With N = 10, Q1 sits at rank 2.75: three quarters of the way from the 2nd value to the 3rd.
- Skewness and kurtosis, adjusted for sample size, with zᵢ = (xᵢ − x̄)/s:
G₁ = N / ((N − 1)(N − 2)) × Σzᵢ³
G₂ = N(N + 1) / ((N − 1)(N − 2)(N − 3)) × Σzᵢ⁴ − 3(N − 1)² / ((N − 2)(N − 3))- Confidence intervals: for the mean, x̄ ± t × s/√N, with t from Student's t distribution on N − 1 degrees of freedom. For the standard deviation, from s√((N − 1)/χ²) with the chi-square quantiles for each end. For the median, from the sorted values, interpolated between the two nearest (Hettmansperger and Sheather).
The descriptive statistics article works an example through.
Normality tests
The data are standardized with their own mean and standard deviation, zᵢ = (x₍ᵢ₎ − x̄)/s.
- Anderson-Darling gives extra weight to the tails. The p-value comes from the adjusted A*² by D'Agostino and Stephens' formula:
A² = −N − (1/N) Σ (2i − 1) [ ln Φ(zᵢ) + ln(1 − Φ(z₍N+1−i₎)) ]
A*² = A² × (1 + 0.75/N + 2.25/N²)- Ryan-Joiner is the correlation between the sorted data and their normal scores bᵢ = Φ⁻¹((i − 0.375)/(N + 0.25)); values close to 1 fit a normal distribution.
- Kolmogorov-Smirnov is the largest gap between the data's cumulative proportion and Φ(z), in Lilliefors' version, since the mean and standard deviation come from the data.
The normal probability plot puts the i-th smallest value at (i − 0.3)/(N + 0.4), Benard's approximation of the median rank. See the normality test.
Control charts
Each chart has a center line and limits 3 standard deviations away. The constants d₂, d₃ and c₄ depend on the subgroup size n; StatLab computes them exactly, and the control chart constants page tabulates them.
Charts for subgroups
μ is the mean of all the observations and σ the standard deviation within subgroups. For a subgroup of n values:
| Chart | Center line | Limits |
|---|---|---|
| Xbar | μ | μ ± 3σ/√n |
| R | d₂σ | d₂σ ± 3d₃σ, not below 0 |
| S | c₄σ | c₄σ ± 3σ√(1 − c₄²), not below 0 |
With subgroups of equal size these are the familiar x̄̄ ± A₂R̄, D₃R̄ to D₄R̄, and so on. σ within comes from one of three estimates; each subgroup i has nᵢ values, range Rᵢ and standard deviation sᵢ, and only subgroups of 2 or more values count:
Rbar: σ̂ = Σ fᵢRᵢ/d₂(nᵢ) / Σ fᵢ
fᵢ = d₂(nᵢ)² / d₃(nᵢ)²
Sbar: σ̂ = Σ hᵢsᵢ/c₄(nᵢ) / Σ hᵢ
hᵢ = c₄(nᵢ)² / (1 − c₄(nᵢ)²)
Pooled: σ̂ = sₚ / c₄(d + 1)
sₚ = √(Σ(nᵢ − 1)sᵢ² / d)
d = Σ(nᵢ − 1)When every subgroup has the same size, the weights cancel: Rbar gives σ̂ = R̄/d₂ and Sbar gives σ̂ = s̄/c₄.
Charts for individuals
The moving range is the absolute difference between each value and the one before, MRᵢ = |xᵢ − xᵢ₋₁|. With μ the mean of the values:
σ̂ = MR̄ / 1.128
I chart: μ ± 3σ̂
MR chart: center MR̄, upper limit 3.267MR̄Attributes charts
For a subgroup of size n:
| Chart | Plots | Center line | Limits |
|---|---|---|---|
| P | proportion defective | p̄ = total defective / total inspected | p̄ ± 3√(p̄(1 − p̄)/n), within 0 and 1 |
| NP | number defective | np̄ | np̄ ± 3√(np̄(1 − p̄)), within 0 and n |
| C | number of defects | c̄, the mean count | c̄ ± 3√c̄, not below 0 |
| U | defects per unit | ū = total defects / total units | ū ± 3√(ū/n), not below 0 |
The patterns that signal a special cause are in tests for special causes.
Process capability
LSL and USL are the specification limits, T the target and μ the process mean. Capability indices (Cp, Cpk) use σ within; performance indices (Pp, Ppk) use the overall standard deviation s. With K = 6, the usual process spread:
Cp = (USL − LSL) / (K σ)
CPL = (μ − LSL) / (K/2 σ)
CPU = (USL − μ) / (K/2 σ)
Cpk = min(CPL, CPU)
Cpm = min(T − LSL, USL − T) / (K/2 τ)
τ = √(Σ(x − T)² / N)Pp, PPL, PPU and Ppk are the same formulas with s in place of σ. With a single specification limit, only that side's index is computed.
- Expected PPM out of specification, from the normal tails: 10⁶ × Φ((LSL − μ)/σ) below and 10⁶ × (1 − Φ((USL − μ)/σ)) above. Observed PPM counts the values beyond each limit, per million.
- Z.Bench = Φ⁻¹(1 − P), where P is the expected total proportion out of specification (no 1.5 shift).
- σ within for single values: the average moving range divided by 1.128 (the default), the median moving range divided by 0.954, or the square root of the mean squared successive difference, √(½ Σdᵢ²/m) over the m differences, divided by its own unbiasing constant.
- Confidence intervals, with ν the degrees of freedom of the σ used (N − 1 for s) and α split between the two ends. Cp and Pp use the chi-square distribution, Cpk and Ppk Bissell's normal approximation with z from the standard normal, and Cpm the chi-square with its own ν:
Cp lower = Cp √(χ²(α/2, ν) / ν)
Cp upper = Cp √(χ²(1 − α/2, ν) / ν)
Cpk ± z √(1/(9N) + Cpk²/(2ν))
Cpm: ν = N(1 + a²)² / (1 + 2a²)
a = (x̄ − T) / sCp, Cpk, Pp and Ppk explains what the indices mean and when they differ.
Run chart
The center line is the median of the points. With m points above the median and n on or below it, N in all, the expected number of runs E and its variance V are, about the median:
E = 1 + 2mn/N
V = 2mn(2mn − N) / (N²(N − 1))and up or down:
E = (2N − 1) / 3
V = (16N − 29) / 90Each test turns its count of runs into z = (runs − E)/√V and gives two one-sided p-values: few runs about the median point to clustering, many to mixtures; few runs up or down point to trends, many to oscillation. The normal approximation needs about 10 points or more. See the run chart.
Chunky-data check
A recorded value is a whole number of measurement increments δ, so a range can only be 0, δ, 2δ, 3δ… The check counts how many of these possible values fall within the range chart's limits, from 0 (or from the lower limit, for subgroups of 7 or more) up to the upper limit, D₄R̄ for subgroups of equal size or 3.267MR̄ for moving ranges. Following Wheeler, the data are chunky when the count is 3 or fewer for moving ranges and subgroups of 2, or 4 or fewer for subgroups of 3 or more. See the chunky-data check.
Probability plots
Each value is plotted at its median rank (i − 0.3)/(N + 0.4), on axes stretched so that a sample from the chosen distribution falls on a straight line. The fitted line is:
- Normal: μ = x̄ and σ = s; the p-th percentile is μ + σΦ⁻¹(p).
- Lognormal: the mean and standard deviation of ln x.
- Exponential: the maximum likelihood mean, θ̂ = x̄; the p-th percentile is −θ̂ ln(1 − p).
- Weibull: shape β and scale η by maximum likelihood; the p-th percentile is η(−ln(1 − p))^(1/β).
The percentiles' confidence intervals use the normal approximation of each estimate, on the log scale for the Weibull. See the probability plot.
Graphs
- Interval plot: x̄ ± t × s/√n, or the mean ± 1 standard error, s/√n. The groups' pooled standard deviation is √(Σ(nᵢ − 1)sᵢ² / Σ(nᵢ − 1)), on Σ(nᵢ − 1) degrees of freedom.
- Scatterplot: the least-squares line ŷ = b₀ + b₁x, with
b₁ = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²
b₀ = ȳ − b₁x̄
r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²)
S = √(SSE / (n − 2))
R-sq = 1 − SSE / Σ(y − ȳ)² = r²- Bar chart: a percent of all bars is a bar's value divided by the total of every bar; a percent within a category divides by that category's total, so each category's bars add up to 100%.
- Pie chart: each slice's angle is 360° × its value / the pie's total.
- Histogram: about √N bars of equal width, from 5 to 25, centred on round numbers and never narrower than the data's resolution.
Frequently asked questions
Why can StatLab's limits differ from a hand calculation in the last digit?
Printed tables round d₂, d₃ and c₄ to three or four decimals. StatLab uses the exact values, so its limits and indices can differ from a hand calculation in the fourth or fifth significant digit.
Which σ does StatLab use by default?
For Xbar-R and R charts, Rbar; for Xbar-S and S charts, Sbar; for the Xbar chart alone and for capability with subgroups, the pooled standard deviation; for individuals, the average moving range. Every dialog lets you choose another.
Where are these formulas checked?
Each analysis is tested against published reference answers: NIST's Statistical Reference Datasets, the NIST/SEMATECH e-Handbook's examples, textbook examples cited by page, and values computed independently with high-precision arithmetic.