Why the Denominator Is Part of the Response
A grouped-binomial record summarizes several binary trials that share the same modeled conditions. For example, a row might report 8 successes among 20 participants in one clinic and treatment group. The observed proportion, \(8/20\), does not by itself say how much information the row contains: 8 successes among 20 trials and 80 among 200 have the same proportion but different denominators. In R, glmmTMB can represent the two counts directly, making the intended number of trials explicit.
The observational unit in the data frame is a group of trials, not an individual trial. Grouping is appropriate only when the trials in a row share the predictors and random-effect membership required by the model. The earlier material on binary outcomes and binomial denominators establishes the distinction between a binary response and its number of trials; here the key task is carrying that distinction correctly into a mixed-model fit.
The model assumes that, conditional on the predictors and random effect, each trial in a group has the same success probability \(p_{ij}\), and that trials are conditionally independent. The group count then has a binomial distribution with denominator \(m_{ij}\). The random effect accounts for modeled dependence between observations in the same cluster by allowing their probabilities to vary together. It does not make different probabilities within one grouped row possible: if the people summarized in a row have different predictor values or different cluster memberships, they generally should not be combined in that row.
Fitting with Two Count Columns
In glmmTMB, put successes and failures in a two-column response using cbind(success, failure). The total number of trials for each row is the sum of those columns. A typical logistic random-intercept model is:
Here, treatment is a fixed effect and clinic identifies the clusters with a random intercept. The two response columns are counts, not a success proportion and a denominator. Do not supply a separate trial weight in addition to the two counts: that would redundantly encode the denominator. Before fitting, check that both counts are present, finite, nonnegative integers and that their sum matches the trial total intended for each row.
Worked Example: Fit a Clinic-Level Grouped-Binomial Model
Suppose hypothetical data summarize treatment outcomes in four clinics. Within each clinic and treatment group, all participants have the same modeled treatment value and share the clinic random intercept. The columns success and failure are the observed counts.
| Clinic | Treatment | Successes | Failures | Trials |
|---|---|---|---|---|
| A | Control | 3 | 15 | 18 |
| A | Active | 8 | 12 | 20 |
| B | Control | 4 | 13 | 17 |
| B | Active | 6 | 10 | 16 |
| C | Control | 5 | 15 | 20 |
| C | Active | 10 | 12 | 22 |
| D | Control | 2 | 13 | 15 |
| D | Active | 7 | 12 | 19 |
For clinic A under active treatment, the total is \(8+12=20\); for clinic D under control, it is \(2+13=15\). Across all eight rows, the trial total is \(18+20+17+16+20+22+15+19=147\), and the success total is \(3+8+4+6+5+10+2+7=45\). The failure total is \(102\), so \(45+102=147\), as required.
One way to enter and audit the data is:
Then fit the specified conditional logistic mixed model:
This code specifies 147 trials across eight grouped observations, not 147 rows. It also specifies four clinic random-intercept levels. The table is a syntax illustration, not a basis for reliable estimation of clinic-level variation: four clusters are very few for estimating a random-effect variance. A real analysis needs a design and number of clusters adequate for its inferential aims.
Why Grouping Can Preserve the Binomial Model
The grouped response is not merely a convenient way to store proportions. When trials share the same probability, the binomial distribution follows directly from the individual-trial model. If each of \(m\) conditionally independent trials has success probability \(p\), the probability of observing exactly \(y\) successes is the number of possible arrangements of those successes multiplied by the probability of any one arrangement:
This is the binomial probability mass function. In a mixed model, the same statement holds conditionally on the random effect, with \(p=p_{ij}\) and \(m=m_{ij}\). Consequently, a row with 8 successes and 12 failures contributes a binomial response with \(m=20\), not a single binary observation with response 8, nor a response of \(0.4\) with one trial.
Worked Example: Check Whether Two Records Can Be Combined
Imagine a hypothetical clinic dataset with two batch records for the same treatment, clinic, and modeled covariate values. The first batch has 2 successes and 3 failures; the second has 3 successes and 4 failures. The shared probability is \(p\), conditional on the clinic random effect.
The first record contributes a probability proportional to \(p^2(1-p)^3\), and the second contributes a probability proportional to \(p^3(1-p)^4\). Their product is:
The combined record has \(2+3=5\) successes and \(3+4=7\) failures, or \(5+7=12\) trials. Its \(p\)-dependent likelihood is also \(p^5(1-p)^7\). Thus the records can be combined for this model. This conclusion would not apply if the batches belonged to different clinics, had different predictors, or otherwise had different modeled probabilities: in those cases, combining them would discard information needed to specify the model.
Audit the Intended Trial Count
A syntactically valid count pair does not guarantee that the data represent the design. If a row was intended to summarize 12 participants but its success and failure counts sum to 10, the model uses 10 trials for that row. It cannot infer the missing denominator from the intended study plan. Keep an independently recorded expected total when available, then compare it with the count sum before fitting.
Worked Example: Find a Mismatched Denominator
Suppose a hypothetical two-row dataset has a recorded intended total, planned_n. The first row has 4 successes and 6 failures, with 10 planned trials. The second has 3 successes and 7 failures, with 12 planned trials.
For row one, \(4+6=10\), which agrees with the planned total. For row two, \(3+7=10\), but the planned total is 12. The grouped response therefore represents 10 trials, not 12. The two unaccounted-for trials must be investigated in the source data; changing the failure count to 9 would be justified only if those two participants were confirmed failures.
A direct check in R is:
The comparison returns TRUE for the first row and FALSE for the second. Resolve discrepancies before fitting rather than treating the discrepancy as a software issue. Also inspect missing values, noninteger entries, negative counts, duplicated records, and whether each row’s cluster identifier and predictors match the people it summarizes.
Alternative Inputs, Diagnostics, and Limits
An alternative is to store one row per trial with a binary outcome coded 0 or 1 and fit the same predictors and random-effect structure. If the expanded records have exactly the same covariates and cluster memberships as the grouped records, the parameter-dependent likelihood is equivalent; the expanded format simply retains each binary result separately. Grouping is more compact, while individual records are essential when trial-level predictors vary or when the model needs to distinguish trial-level information. A success proportion with the number of trials supplied as binomial weights is another possible representation, but the two-column response makes successes and failures explicit and is often easier to audit. Do not enter a proportion as though it were a count, or combine that proportion with the two count columns.
After fitting, check that the model used the expected number of grouped rows and that the response columns supplied to the fit are the audited counts. The sum of the row denominators should equal the intended total number of trials in the analysis dataset. Remember that the model’s observation count refers to grouped records, not the total number of individuals. Review convergence messages, estimated random-effect variation, and observed versus fitted patterns across clusters. If the model consistently misses the variability in grouped counts, consider whether the assumed binomial variation and random-effects structure are adequate; a count mismatch or an aggregation error should be fixed in the data rather than addressed by a more elaborate model.
The grouped-binomial representation also has a substantive limit: the binomial model assumes a common conditional success probability for all trials summarized in a row. Aggregating people with different covariate values can conceal meaningful heterogeneity and can invalidate that assumption. Likewise, grouping across clusters prevents the model from assigning the correct random effect to each person. Use a row definition that respects both the design and the intended conditional model.
Common Mistake
A frequent error is to treat the success proportion as the response and forget the denominator, reasoning that two groups with the same percentage provide the same information. They do not: \(4/10\) and \(40/100\) have the same observed proportion but different trial counts. In a grouped-binomial model, use the successes and failures (or a proportion with its correct binomial trial weights), and verify that the implied total is the intended number of trials. A second error is to assume any records with matching treatment labels can be combined. Matching treatment alone is insufficient; predictors and random-effect membership must also agree.
glmmTMB, represent each row as cbind(success, failure), confirm that the two nonnegative integer counts sum to the intended trial total, and aggregate only trials that share the modeled conditions and cluster membership.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A row contains 9 successes and 11 failures. What denominator does the model use?
- Two records in the same clinic have identical predictors and report 2/5 and 4/8 successes/trials. How many successes and trials are in their combined record, and when is combining valid?
- A row has 5 successes and 4 failures, but the intended total is 10. What should you do before fitting?
- Why is entering a success proportion alone insufficient to describe a grouped-binomial response?
Solutions. (1) The denominator is \(9+11=20\) trials. (2) The combined record has \(2+4=6\) successes and \(5+8=13\) trials. Combining is valid when both records share the predictors, cluster membership, and other modeled conditions. (3) Investigate the source data and resolve the discrepancy; the supplied counts currently represent only \(5+4=9\) trials, and the missing trial’s outcome must not be guessed. (4) A proportion does not identify how many trials produced it: the model needs the denominator, supplied here by the failures plus successes or by a correctly specified binomial weight.