Tutorials › Generalized Linear Mixed Models (GLMM) › Analyzing Grouped Manufacturing Defects

Software and Case Studies · Tutorial 681 of 698

Analyzing Grouped Manufacturing Defects

You will learn to fit a grouped-binomial GLMM for manufacturing defects and interpret its process coefficient as a conditional odds ratio against the reference process.

Intermediate 13 min read

What You'll Learn

  • Express defective and nondefective counts as a grouped-binomial response.
  • Specify a logit GLMM with a production-line random intercept.
  • Interpret the process coefficient and exponentiated coefficient relative to the reference process.
  • Convert conditional defect odds to probabilities at a specified random-effect value.
  • Check assumptions, convergence, and patterns that can undermine the model.
  • Distinguish a conditional treatment contrast from a population-averaged comparison.

Why Grouped Defect Data Need a Mixed Model

Manufacturing records often report counts for each batch: how many items were defective and how many were inspected. The batch proportion is useful descriptively, but it does not by itself account for differences among production lines. Batches from the same line may share equipment, operators, or operating conditions, so their outcomes can be more alike than outcomes from different lines. A grouped-binomial generalized linear mixed model (GLMM) represents both the defective-item counts and this line-to-line variation.

The treatment comparison in this model is on the conditional odds scale: it compares processes at the same value of the production-line random effect. The reference process determines the baseline against which the process coefficient is interpreted. This is not automatically a comparison of marginal, population-averaged defect probabilities.

Model and Assumptions

Definition: For batch \(j\) on production line \(l\), let \(Y_{lj}\) be the number of defective items among \(m_{lj}\) inspected items. A grouped-binomial random-intercept GLMM is $$ Y_{lj}\mid b_l \sim \operatorname{Binomial}(m_{lj},p_{lj}), \qquad \operatorname{logit}(p_{lj})=\beta_0+\beta_1 x_{lj}+b_l, \qquad b_l\sim N(0,\sigma_b^2). $$ Here \(x_{lj}=0\) for the reference process and \(x_{lj}=1\) for the modified process. The random intercept \(b_l\) is shared by batches from line \(l\), \(\beta_0\) is the reference-process log odds when \(b_l=0\), and \(\beta_1\) is the conditional log odds ratio for the modified process versus the reference process.

This specification assumes that, conditional on the line effect and the included predictors, items within a batch have a common defect probability and follow a binomial distribution. It also assumes that batches are conditionally independent given their line effects, and that line effects follow a normal distribution with mean zero and variance \(\sigma_b^2\). The random intercept represents a multiplicative shift in the odds shared by batches on a line; it does not allow the process contrast to vary by line.

The model also needs a design that separates process from line. For example, if every line uses only one process, a process difference may be confounded with line differences. The data must contain enough independent lines to estimate line-to-line variation with useful precision. The binomial assumption can be inadequate if batch outcomes remain more variable than the model allows after accounting for the line effect and predictors.

From Counts to a Model Fit

For each batch, the response supplied to software is the pair of counts: defective items and nondefective items. If \(Y_{lj}\) items are defective out of \(m_{lj}\) inspected, the second count is \(m_{lj}-Y_{lj}\). The binomial model uses both the count and the number inspected; a batch with 2 defects among 20 items does not provide the same information as a batch with 20 defects among 200 items, even though both observed proportions are 0.10.

Worked Example: Encoding Hypothetical Batch Records

Suppose a hypothetical plant records batches from two processes on several production lines. A small extract is shown below. These rows illustrate the data structure; they are not sufficient by themselves to support a reliable estimate of between-line variation.

LineProcessDefectiveInspectedNondefective
L1Reference12200188
L1Modified9200191
L2Reference18200182
L2Modified13200187

For the first batch, the grouped response is \(12\) defective and \(200-12=188\) nondefective. Its observed defect proportion is \(12/200=0.0600\). Under the model, its conditional likelihood contribution, for a specified line effect \(b_1\), is $$ P(Y_{11}=12\mid b_1) =\binom{200}{12}p_{11}^{12}(1-p_{11})^{188}, \qquad \operatorname{logit}(p_{11})=\beta_0+b_1. $$ The line effect is shared with the second L1 batch, rather than being independently redrawn for that batch.

In R, a grouped response can be specified as cbind(defective, inspected - defective). For a dataset with columns named line, process, defective, and inspected, a model with the reference process as the factor reference level is written:

$$ \texttt{glmmTMB(cbind(defective, inspected - defective) \textasciitilde{} process + (1 | line),} $$

family = binomial(link = "logit"), data = batches). In practice the formula and arguments are supplied together in the software call. The random-intercept term \((1 \mid line)\) assigns one shared intercept deviation to each line. A trustworthy analysis also checks the fitted model’s convergence and whether its assumptions are plausible; merely obtaining coefficient estimates is not enough.

Why the Process Coefficient Is an Odds Ratio

For a fixed line effect \(b_l\), the reference-process odds are \(\exp(\beta_0+b_l)\). The modified-process odds are \(\exp(\beta_0+\beta_1+b_l)\). Their ratio cancels both the intercept and the line effect:

$$ \frac{\exp(\beta_0+\beta_1+b_l)}{\exp(\beta_0+b_l)} =\exp(\beta_1). $$

Thus \(\exp(\beta_1)\) is the conditional odds ratio for the modified process relative to the reference process, comparing batches at the same line effect. If it is below 1, the modified process has lower conditional defect odds; if it is above 1, it has higher conditional defect odds. The odds ratio is not a ratio of probabilities, and it does not directly give the change in defect probability.

A useful consequence is that the same conditional odds ratio applies at each value of \(b_l\) in this random-intercept model. The probabilities still differ across lines because the shared line effect changes the baseline odds. Also, because the logit link is nonlinear, the conditional odds ratio should not be presented as a population-averaged odds ratio.

Worked Example: Interpreting a Fitted Process Contrast

Suppose a hypothetical fit gives \(\hat{\beta}_0=-2.442\) and \(\hat{\beta}_1=-0.5108\), with standard error \(SE(\hat{\beta}_1)=0.180\). The reference process is the factor’s baseline category. The conditional odds ratio is $$ \exp(\hat{\beta}_1)=\exp(-0.5108)\approx 0.6000. $$

At a fixed production-line effect, the estimated defect odds under the modified process are 0.600 times the odds under the reference process. Equivalently, they are estimated to be \(1-0.600=0.400\), or 40.0%, lower. This is a comparison of odds, not a claim that defect probability falls by 40.0%.

For an approximate Wald interval, first calculate the interval on the log-odds-ratio scale: $$ -0.5108\pm1.96(0.180)=[-0.8636,-0.1580]. $$ Exponentiating the endpoints gives an approximate 95% confidence interval for the conditional odds ratio: $$ [\exp(-0.8636),\exp(-0.1580)]\approx[0.421,0.854]. $$ Under the model and the Wald approximation, this interval is compatible with conditional defect odds from 0.421 to 0.854 times those under the reference process. Because the interval is below 1, it indicates lower conditional odds for the modified process at the 5% two-sided level. The corresponding Wald statistic is \(z=-0.5108/0.180=-2.838\), giving an approximate two-sided \(p\)-value of 0.0045. This p-value is the probability, under the null and the test assumptions, of a statistic at least this extreme; it is not the probability that the null is true.

From Conditional Odds to Defect Probabilities

To give a probability for a particular process, specify the line effect as well as the fitted coefficients. If the log odds are \(\eta\), the corresponding probability is \(\exp(\eta)/(1+\exp(\eta))\). The intercept \(\beta_0\) describes the reference process at \(b_l=0\), not an average probability over the distribution of production lines.

Worked Example: Comparing Processes at a Specified Line Effect

Use the same hypothetical coefficient estimates, and consider a line with random effect \(b_l=0.400\). For the reference process, the log odds are \(-2.442+0.400=-2.042\). Therefore its odds and defect probability are $$ \exp(-2.442+0.400)\approx 0.1298, \qquad \frac{0.1298}{1+0.1298}\approx 0.1149. $$

For the modified process, add its coefficient to the same line effect. The log odds are \(-2.442-0.5108+0.400=-2.5528\), so the odds and probability are $$ \exp(-2.442-0.5108+0.400)\approx 0.0779, \qquad \frac{0.0779}{1+0.0779}\approx 0.0722. $$

At this specified line effect, the fitted defect probabilities are about 11.49% for the reference process and 7.22% for the modified process. For a batch of 500 items, these probabilities correspond to expected defective counts of \(500(0.1149)=57.45\) and \(500(0.0722)=36.10\), respectively. They are model-based expected counts, not guaranteed counts for individual batches. The odds ratio remains about \(0.0779/0.1298=0.600\), subject to rounding.

Diagnostics, Alternatives, and Limitations

Diagnostics should assess both the numerical fit and the data-generating assumptions. Check that the optimizer reports convergence, that estimates are finite, and that the random-effect variance is not being estimated at an implausible boundary. A singular or near-zero variance estimate can indicate little detectable line variation, though it can also reflect limited information. Examine observed and fitted defect proportions across lines and processes, paying attention to systematic discrepancies and batches with unusually large residuals. Patterns of extra variation beyond what the binomial and line effect accommodate may signal overdispersion, omitted predictors, or an inadequate random-effects structure.

A grouped-binomial GLM without a line random effect is a simpler alternative, but it treats observations as independent conditional only on fixed predictors. If batches on the same line are correlated, that can understate uncertainty. A model with line fixed effects is another option when inference is specifically about the observed lines, but it uses a different representation of line differences and may not target variation across a population of lines. A population-averaged approach such as generalized estimating equations targets a different type of comparison. These alternatives are not interchangeable merely because they use the same response counts.

The random-intercept GLMM also has limits. It assumes a normal distribution for line effects and a common process log odds ratio across lines. It cannot correct confounding caused by a design in which process and line are inseparable, nor can it account automatically for unrecorded batch-level conditions or dependence beyond the specified line effect. With few lines, estimation of \(\sigma_b^2\) and uncertainty for the process contrast can be imprecise. Conclusions should therefore be phrased as model-based conditional associations unless the design and assumptions justify a causal interpretation.

Common pitfall: It is incorrect to call \(\exp(\hat{\beta}_1)\) a defect-probability ratio or to interpret \(\hat{\beta}_0\) as the average defect probability. The exponentiated process coefficient is a conditional odds ratio at a fixed line effect, while the intercept is the reference-process log odds at \(b_l=0\). Convert a specified linear predictor to probability with the inverse-logit, and state the random-effect value used.
1
Check the response and design.
Confirm that each row has a valid defective count between zero and the inspected count, and that the process contrast is not confounded with production line.
2
Fit the stated grouped-binomial model.
Use defective and nondefective counts, the process indicator, and the line random intercept; verify convergence and inspect the estimated random-effect variation.
3
Translate the contrast and check fit.
Exponentiate the process coefficient for the conditional odds ratio, then assess fitted probabilities and residual patterns across processes and lines.

Check Your Understanding

Answer each question using the model and interpretation developed above. Brief solutions follow the questions.

  1. A batch has 7 defective items among 160 inspected. What grouped response should be entered, and what is its observed defect proportion?
  2. A fitted process coefficient is \(0.2231\). What is the conditional odds ratio, and how should it be interpreted?
  3. For the reference process, suppose the log odds at a specified line are \(-2.0\). Calculate the defect probability.
  4. Why is a process coefficient difficult to estimate if each production line uses only one process?

Solutions. (1) Enter 7 defective and \(160-7=153\) nondefective; the observed proportion is \(7/160=0.04375\), or 4.375%. (2) The conditional odds ratio is \(\exp(0.2231)\approx1.250\). At the same line effect, the modified process has about 1.25 times the defect odds of the reference process, or 25.0% higher odds; this does not mean 25.0% higher probability. (3) The probability is \(\exp(-2.0)/(1+\exp(-2.0))\approx0.1192\), or 11.92%. (4) If process is perfectly determined by line, process differences cannot be separated from line differences; the data do not provide a within-line process comparison to distinguish the fixed process effect from the line effects.

Clinical Biostats