Tutorials › Generalized Linear Mixed Models (GLMM) › Why Within-Group Covariate Variation Blocks Simple Aggregation

Responses: Binary, Count, Ordinal, Overdispersed · Tutorial 71 of 698

Why Within-Group Covariate Variation Blocks Simple Aggregation

See how covariate variation changes the distribution and information in a grouped binary count, and when careful stratification can preserve what simple pooling discards.

Intermediate 10 min read

What You'll Learn

  • State the conditional Bernoulli model for binary trials within a cluster.
  • Derive why a sum with unequal success probabilities is generally Poisson-binomial, not binomial.
  • Compare individual-record and grouped-count likelihoods for the same hypothetical data.
  • Explain how shared random effects create dependence after they are integrated out.
  • Identify when aggregation within identical covariate strata can preserve model information.
  • Diagnose when pooling trials into one count obscures covariate-response patterns.

Why a Group Total Can Be Misleading

A grouped success count is convenient: it replaces a list of binary outcomes with one number. That replacement is straightforward when all trials in the group share the same success probability, as in the earlier material on aggregation under shared covariates. But if covariate values differ across trials, their success probabilities generally differ too. The total number of successes then does not follow an ordinary binomial distribution with one common probability, and it can conceal which covariate values were associated with the observed successes.

The distinction matters in a generalized linear mixed model because the response model is specified for each trial, conditional on the relevant covariates and random effects. Grouping is safe only when the grouped representation still matches that model and retains the information needed for the intended analysis.

Conditional Model and the Shared-Covariate Case

Definition: Let \(Y_{ij}\) be the binary response for trial \(i\) in cluster \(j\), where 1 denotes success and 0 denotes failure. A logistic mixed model can be written $$ Y_{ij}\mid b_j \sim \operatorname{Bernoulli}(p_{ij}), \qquad \operatorname{logit}(p_{ij}) = x_{ij}^{T}\beta + z_{ij}^{T}b_j. $$ Here \(x_{ij}\) is the fixed-effect covariate vector, \(\beta\) is its coefficient vector, \(z_{ij}\) is the random-effect design vector, and \(b_j\) is the cluster-specific random-effect vector. Conditional on \(b_j\) and the covariates, the trial outcomes are assumed independent. In the usual GLMM formulation, random effects have a specified distribution, commonly a mean-zero multivariate normal distribution, and are independent across clusters.

The conditional independence assumption does not say that outcomes are independent after the random effects are integrated out. It says that, for a fixed value of the shared cluster effect, the model gives a product of Bernoulli probabilities. This is the appropriate level at which to compare individual and grouped likelihoods.

If all trials within a group have the same conditional success probability \(p\), then their sum \(S_j=\sum_iY_{ij}\) is conditionally binomial: \(S_j\mid b_j\sim\operatorname{Binomial}(n_j,p)\). When covariates vary, however, \(p_{ij}\) will generally vary with \(i\), even within the same cluster and at the same value of \(b_j\).

What Distribution Does the Total Have?

For fixed conditional probabilities \(p_1,\ldots,p_n\), the sum \(S=\sum_{i=1}^nY_i\) of independent Bernoulli variables has a Poisson-binomial distribution. Its probability-generating polynomial follows directly by multiplying the contribution of each trial: failure contributes \(1-p_i\), while success contributes \(p_i t\). The coefficient of \(t^s\) is the probability of exactly \(s\) successes.

$$ P(S=s\mid b) = [t^s]\prod_{i=1}^{n}\bigl((1-p_i)+p_i t\bigr) $$

Here \([t^s]\) means “the coefficient of \(t^s\).” If every \(p_i=p\), the product becomes \(((1-p)+pt)^n\), and the binomial theorem gives the ordinary binomial probabilities. With unequal probabilities, it generally does not reduce to that form. A grouped total can still be modelled using its Poisson-binomial likelihood when the trial-level covariate values are known; the problem is treating that total as an ordinary binomial count with a single probability, or assuming the total retains all the individual-record information.

Key result: Conditional on the random effects, independent binary trials with unequal success probabilities sum to a Poisson-binomial response, not generally a binomial response. In a GLMM, the distribution of the total after integrating out \(b_j\) is a mixture of these conditional distributions.

Worked Example: Checking Whether a Pooled Count Is Binomial

Suppose a hypothetical cluster contains four conditionally independent trials at a specified random-effect value. Two trials have success probability 0.20 and two have probability 0.60. Compute the probability of exactly one success and compare it with a binomial calculation that incorrectly uses the average probability.

For exactly one success, one of the four trials succeeds and the other three fail. Each of the two lower-probability trials contributes \(0.20(0.80)(0.40)(0.40)=0.0256\). Each of the two higher-probability trials contributes \(0.60(0.80)(0.80)(0.40)=0.1536\). Therefore, $$ P(S=1\mid b) =2(0.0256)+2(0.1536) =0.3584. $$

The average trial probability is \((0.20+0.20+0.60+0.60)/4=0.40\). Incorrectly treating all trials as having that common probability gives \(P(S=1)=\binom{4}{1}(0.40)(0.60)^3=0.3456\). The difference, 0.0128, shows that matching the average probability does not make the pooled total binomial. The correct calculation uses the four trial-specific probabilities.

How Pooling Loses Allocation Information

The individual-record likelihood conditional on the random effects is $$ L(\beta,b_j;y_j) = \prod_i p_{ij}^{y_{ij}}(1-p_{ij})^{1-y_{ij}}. $$ It records which trial succeeded. A likelihood for the total instead sums the individual-record likelihoods over every response pattern that has the observed total: $$ P(S_j=s\mid b_j,x_j) = \sum_{\{y_j:\,\sum_i y_{ij}=s\}} L(\beta,b_j;y_j). $$ This sum is a valid probability for the total, but it combines patterns that can have different likelihoods when the trials have different covariates. Once only the total is retained, the observed allocation among covariate values cannot be recovered.

A short score calculation makes the lost detail concrete. For a logistic model with a single covariate \(x_i\) and a slope \(\beta_1\), the conditional log-likelihood score for that slope is $$ \frac{\partial\ell}{\partial\beta_1} = \sum_i x_i(y_i-p_i). $$ If two response patterns have the same number of successes but different successes at different \(x_i\) values, their slope scores can differ. The pooled total alone does not reveal which score corresponds to the observed pattern.

Worked Example: The Same Total, Different Slope Evidence

Use the four hypothetical trials above: two have \(x=0\) and success probability 0.20, and two have \(x=1\) and probability 0.60. These probabilities are consistent with a logistic linear predictor whose intercept is \(\operatorname{logit}(0.20)\) and whose slope is \(\operatorname{logit}(0.60)-\operatorname{logit}(0.20)\). Compare two possible records, each with one success.

In the first record, one \(x=0\) trial succeeds and all others fail. Its conditional likelihood is \(0.20(0.80)(0.40)(0.40)=0.0256\). The slope score is \(0(1-0.20)+0(0-0.20)+1(0-0.60)+1(0-0.60)=-1.20\).

In the second record, one \(x=1\) trial succeeds and all others fail. Its conditional likelihood is \(0.80(0.80)(0.60)(0.40)=0.1536\). The slope score is \(0(0-0.20)+0(0-0.20)+1(1-0.60)+1(0-0.60)=-0.20\).

Both records have the same pooled total, \(S=1\), but their individual likelihoods differ by a factor of six and their slope scores differ. The grouped probability of one success is 0.3584 for either observed record because it sums over all four possible one-success patterns. That grouped probability is not the likelihood contribution of the particular allocation that was observed.

Random Effects and Marginal Dependence

In a GLMM, a random effect shared by trials in a cluster is another reason not to interpret a pooled total as a simple binomial count. Conditional independence gives \(E(S_j\mid b_j)=\sum_i p_{ij}\) and \(\operatorname{Var}(S_j\mid b_j)=\sum_i p_{ij}(1-p_{ij})\). After averaging over the random effect, the law of total variance gives $$ \operatorname{Var}(S_j) = E\!\left[\sum_i p_{ij}(1-p_{ij})\right] + \operatorname{Var}\!\left(\sum_i p_{ij}\right). $$ The second term reflects variation in the cluster’s conditional expected total as its random effects vary. Equivalently, marginally, two outcomes sharing a random effect can be dependent. A binomial distribution with one fixed probability does not generally represent this mixture.

This identity assumes the conditional Bernoulli model and a well-defined random-effect distribution. It does not require equal covariates; indeed, unequal covariates are one reason the conditional probabilities in the sum differ. The random-effects integration must use the same cluster-level effect for all trials it governs, rather than giving each trial an unrelated draw.

Worked Example: Separating Conditional and Marginal Variation

For illustration, consider a hypothetical random-intercept model with a two-point random-effect distribution: \(b\) equals \(\log(3)\) or \(-\log(3)\), each with probability one half. This finite distribution is used only to make the mixture arithmetic exact. Take two trials with fixed linear predictors 0 and \(\log(3)\), before adding \(b\).

When \(b=\log(3)\), their probabilities are \(\operatorname{logit}^{-1}(\log(3))=0.75\) and \(\operatorname{logit}^{-1}(\log(9))=0.90\). The conditional mean of the total is 1.65 and its conditional variance is \(0.75(0.25)+0.90(0.10)=0.2775\). When \(b=-\log(3)\), the probabilities are 0.25 and 0.50, so the conditional mean is 0.75 and the conditional variance is \(0.25(0.75)+0.50(0.50)=0.4375\).

The marginal mean is \((1.65+0.75)/2=1.20\). The expected conditional variance is \((0.2775+0.4375)/2=0.3575\), and the variance of the conditional means is \(\{(1.65-1.20)^2+(0.75-1.20)^2\}/2=0.2025\). Thus the marginal variance is \(0.3575+0.2025=0.5600\). A binomial distribution with two trials and marginal probability 0.60 would have variance \(2(0.60)(0.40)=0.48\), which does not match. The shared random effect adds marginal variation, while the different trial predictors make the conditional probabilities unequal.

When Aggregation Can Still Be Useful

Pooling every trial in a cluster into one count is not the only option. If trials have identical covariate vectors and share the same random-effect design, they have the same conditional probability. Their successes can be counted within that covariate stratum, giving a binomial likelihood contribution. With several distinct covariate patterns, retaining a separate count for each pattern can preserve the allocation information between patterns.

Worked Example: Retaining Counts Within Covariate Strata

Suppose a hypothetical group has three trials at \(x=0\), with one success, and two trials at \(x=1\), with two successes. Let their conditional probabilities be 0.20 and 0.60, respectively. The individual-record likelihood is $$ (0.20)^1(0.80)^2(0.60)^2 =0.04608. $$

The likelihood from the two stratum counts is \(\binom{3}{1}(0.20)^1(0.80)^2\binom{2}{2}(0.60)^2 =3(0.04608)=0.13824\). The factor of 3 counts the possible locations of the success within the \(x=0\) stratum. It does not depend on the model coefficients, so it does not change the relative likelihood for those coefficients. The two stratum counts retain which covariate pattern had the success; pooling them into one total of three successes would not.

This conclusion requires that trials within each stratum truly share the same model-relevant covariates and random-effect design, and that the conditional independence assumptions hold. When covariates are continuous or vary within strata, grouping them into approximate categories changes the model and may discard information; it is not exact aggregation.

Diagnostics, Alternatives, and Limitations

Before fitting a grouped response model, check the data structure rather than relying on a table’s row labels. For each proposed group, inspect whether all trials have the same model-relevant covariate values and random-effect design. If they do not, verify that the chosen likelihood uses their distinct probabilities, or retain individual records or separate counts by identical covariate patterns.

Warning signs include a binomial model with one probability assigned to a group despite within-group covariate variation, totals whose likelihood cannot be reconstructed from the stored covariate summaries, or fitted probabilities that fail to reflect known trial-level differences. A useful diagnostic is to compare the proposed grouped likelihood with the individual Bernoulli likelihood for several possible response allocations having the same total. If those allocations yield different parameter-dependent likelihoods, the total alone cannot reproduce the individual likelihood.

RepresentationWhat it preservesKey condition or limitation
Individual Bernoulli recordsEach outcome’s covariates and response allocationRequires trial-level records and the specified conditional model
One binomial count per groupSuccess total under a common conditional probabilityNot generally valid when trial probabilities differ
One Poisson-binomial totalThe probability of the total given all trial probabilitiesDoes not retain which covariate-specific trials succeeded
Counts within identical covariate strataSuccess allocation across distinct covariate patternsExact only when trials within each stratum share model-relevant predictors

A Poisson-binomial total can be useful when the total is genuinely the recorded response and the relevant covariates are available to calculate its likelihood. But individual records are usually preferable for estimating covariate effects because they retain the response-covariate pairing. Aggregation also cannot repair incorrect denominators, omitted predictors, or a misspecified random-effects structure. In all cases, distinguish the conditional model given random effects from its marginal implications.

Common Mistake

Common mistake: “There are \(n\) binary trials and \(s\) successes, so the group response is binomial; I can use the average covariate value to get one probability.” This reasoning assumes every trial has the same conditional success probability. An average covariate does not generally produce a probability whose binomial likelihood equals the trial-specific likelihood. Check the individual predictors and probabilities first; use individual Bernoulli records, a correctly specified Poisson-binomial likelihood, or counts separated by identical covariate patterns.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. Three conditionally independent trials have probabilities 0.10, 0.10, and 0.70. Is their total generally binomial? State its appropriate conditional distribution.
  2. Two records each contain one success among trials with different covariate values. Why can their individual likelihoods differ even though their totals match?
  3. When can two covariate-specific success counts be used instead of all individual records without changing likelihood comparisons for model coefficients?
  4. Why can shared random effects make outcomes dependent marginally even when the model assumes conditional independence?

Solutions. (1) It is generally not binomial because the probabilities differ; conditional on the specified probabilities, the sum has a Poisson-binomial distribution. (2) The Bernoulli likelihood multiplies the probability associated with each observed trial, so assigning the success to a trial with a different predictor changes the parameter-dependent factors. The total does not encode that assignment. (3) This is exact when trials within each stratum share all model-relevant covariates and random-effect design, with the stated conditional independence model. The binomial combinatorial factors within strata do not depend on model coefficients. (4) Conditional on a random effect, trial probabilities are fixed and outcomes can be independent; after integrating over the shared effect, outcomes co-vary because they respond to the same varying cluster-level quantity.

Clinical Biostats