Why Grouped Binomial Data Need Their Trial Totals
A data set may record one row for each policy segment, clinic, location or risk class, rather than one row for every individual trial. For each row, the analyst knows how many trials occurred and how many produced the event of interest. For example, a hypothetical portfolio summary might show 12 events among 40 exposures in one category. The observed proportion, \(12/40\), is useful, but it does not contain all the information needed to represent the data: 12 events among 40 trials is not as precise as 12 among 400.
A grouped-binomial generalized linear model (GLM) preserves that distinction by modelling the event count out of a known number of trials. It is closely related to a Bernoulli GLM: a Bernoulli response records an individual trial as 0 or 1, while a grouped-binomial response summarizes several trials that share the same modelled event probability.
The standard grouped-binomial likelihood assumes that, conditional on the modelled probability, the trials within a group are independent and have the same event probability. It also assumes the groups are independent and that each \(n_i\) is known. If trials within a group have materially different probabilities or are dependent, the standard binomial model may not describe the data adequately.
Deriving the Grouped-Binomial Likelihood
For one group, the probability of a particular sequence of \(n_i\) independent trial outcomes with exactly \(y_i\) events is \(p_i^{y_i}(1-p_i)^{n_i-y_i}\). There are \(\binom{n_i}{y_i}\) possible sequences with that event count. Adding their probabilities gives the binomial probability mass function. Multiplying across independent groups gives the likelihood.
With the logit link, \(p_i=\exp(\eta_i)/\{1+\exp(\eta_i)\}\), so \(\log(p_i)=\eta_i-\log\{1+\exp(\eta_i)\}\) and \(\log(1-p_i)=-\log\{1+\exp(\eta_i)\}\). Substituting these expressions yields the log-likelihood below. The binomial coefficient depends on the observed counts and trial totals, but not on the model coefficients.
This form explains why the trial total matters: the term involving the model probability is multiplied by \(n_i\), not merely by one. Differentiating with respect to the linear predictor gives \(y_i-n_ip_i\), because the derivative of \(\log\{1+\exp(\eta_i)\}\) is \(p_i\). Since \(\eta_i=\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}\), the score for the coefficient vector is the sum of predictor vectors multiplied by observed-minus-expected event counts.
At a maximum-likelihood estimate, the score is zero, provided a finite maximum exists. In an intercept-only model, all groups share one probability \(p\). The score equation is then \(\sum_i(y_i-n_ip)=0\), so the estimated probability is total events divided by total trials. This is a trial-weighted estimate, not an unweighted average of the group proportions.
Worked Example: A Common Probability Across Two Groups
A hypothetical study records 5 events among 25 trials in group A and 18 events among 45 trials in group B. Assume that all trials share one event probability \(p\). Find the maximum-likelihood estimate, compare it with the unweighted average of the two observed proportions, and state the corresponding R response.
Method. Use the intercept-only grouped-binomial likelihood. The two group proportions are \(5/25=0.20\) and \(18/45=0.40\). The total number of events is \(5+18=23\), and the total number of trials is \(25+45=70\). Thus the estimate is \(23/70=0.328571\ldots\), or 0.3286 to four decimal places.
The unweighted average is \((0.20+0.40)/2=0.30\), or 0.3000 to four decimal places. It differs because it assigns the same influence to groups with 25 and 45 trials. The likelihood score gives \(23-70p=0\), confirming the trial-weighted estimate.
For an intercept-only logit model, the estimated odds are \((23/70)/(47/70)=23/47\). The fitted intercept is therefore \(\log(23/47)\), approximately \(-0.714\) to three decimal places. In R, after defining columns `events` and `total` with the two rows, the grouped response is `glm(cbind(events, total - events) ~ 1, family = binomial, data = dat)`. The two columns represent event and non-event counts.
Check. The fitted event count across 70 trials is \(70(23/70)=23\), equal to the observed total. The common mistake is to report 0.3000 as the pooled estimate; that is the unweighted mean of proportions, not the grouped-binomial maximum-likelihood estimate.
Fitting Group-Specific Probabilities in R
A predictor can allow probabilities to differ between groups. Consider a categorical predictor with reference level A and comparison level B. With a logit link and an indicator \(x_i=1\) for B (and \(x_i=0\) for A), the model is \(\operatorname{logit}(p_i)=\beta_0+\beta_1x_i\). The intercept is the log-odds for A, and the coefficient \(\beta_1\) is the log-odds difference between B and A. Exponentiating that difference gives the odds ratio for B versus A.
Worked Example: Estimating a Group Odds Ratio
In a hypothetical comparison, group A has 10 events among 40 trials and group B has 30 events among 50 trials. Fit the two-group logit model conceptually, calculate its fitted probabilities and odds ratio, and specify the R call.
Method. The model has one indicator coefficient and is saturated for the two group probabilities: each group’s fitted probability equals its observed proportion. Group A has 30 non-events, so its odds are \(10/30=1/3\), and its fitted probability is \(10/40=0.25\). Group B has 20 non-events, so its odds are \(30/20=1.5\), and its fitted probability is \(30/50=0.60\).
With A as the reference, \(\widehat{\beta}_0=\log(1/3)\approx-1.099\) and \(\widehat{\beta}_1=\log(1.5)-\log(1/3)=\log(4.5)\approx1.504\), with coefficients rounded to three decimals. The estimated odds ratio is \(\exp\{\log(4.5)\}=4.5\): the estimated event odds in B are 4.5 times those in A.
In R, enter one row per group, with `group` containing A and B, and fit `glm(cbind(events, total - events) ~ group, family = binomial, data = dat)`. If A is the reference level, the coefficient for B is the log-odds difference just calculated.
Check. The fitted probabilities reproduce the observed counts: \(40(0.25)=10\) and \(50(0.60)=30\). The common mistake is to compare the probabilities and call \(0.60/0.25=2.4\) an odds ratio. The odds ratio uses odds, not probabilities, and here is 4.5.
The two-column response, `cbind(events, total - events)`, directly represents successes and failures. The second column must be the non-event count, not the total number of trials. For example, if a row has 12 events out of 40 trials, the response columns are 12 and 28. A useful data check is to confirm for every row that the event count is between 0 and the total and that the two response columns sum to the stated total.
Counts, Proportions and Individual Records
Grouped counts and grouped proportions can encode the same binomial information when the trial totals are retained. If \(r_i=y_i/n_i\) is the observed proportion, R can fit that proportion with prior weight \(n_i\), as in `glm(rate ~ predictor, weights = total, family = binomial, data = dat)`. The weight tells the binomial fit that the row represents \(n_i\) trials. A proportion without its denominator does not tell the model how much information the row contains.
Individual binary records are another valid representation. If every individual trial is included as a separate 0 or 1 response and the predictors are recorded for each trial, a Bernoulli GLM can be fitted to those records. When grouped trials have the same predictors and event probability, multiplying their individual Bernoulli contributions produces the same parameter-dependent likelihood as the grouped-binomial model. The grouped likelihood additionally includes \(\binom{n_i}{y_i}\), which counts the possible arrangements of events and non-events. That factor does not depend on the coefficients, so it does not change the coefficient estimates.
Worked Example: Proportions Must Carry Their Denominators
A hypothetical data set contains three groups with event counts and totals of 2 out of 10, 18 out of 30, and 20 out of 40. Estimate one common event probability. Then compare the grouped-count fit, the properly weighted proportion fit, and the unweighted average of the three proportions.
Method. The proportions are \(2/10=0.20\), \(18/30=0.60\), and \(20/40=0.50\). Total events are \(2+18+20=40\); total trials are \(10+30+40=80\). The intercept-only grouped-binomial estimate is \(40/80=0.50\).
The same estimate follows from a proportion response weighted by the trial totals: \(\{10(0.20)+30(0.60)+40(0.50)\}/(10+30+40)=(2+18+20)/80=0.50\). The unweighted average is \((0.20+0.60+0.50)/3=1.30/3=0.433333\ldots\), or 0.4333 to four decimal places. It does not give the maximum-likelihood estimate for these grouped trials.
For the count representation, R uses `glm(cbind(events, total - events) ~ 1, family = binomial, data = dat)`. For the proportion representation, define `rate = events / total` and use `glm(rate ~ 1, weights = total, family = binomial, data = dat)`. In both cases the fitted probability is 0.50.
Check. Under the common-probability fit, the expected event count is \(80(0.50)=40\), matching the observed total. The mistake to avoid is fitting the proportions without trial weights: that treats the three rows as equally informative and targets their unweighted average.
When each row is an individual 0-or-1 outcome, the response should be that binary outcome, and each record normally represents one trial. Do not substitute a group-level proportion on every individual row or repeat a group count as though it were an individual outcome. Choose the response form that matches the actual observational unit, and verify that the number of trials is represented exactly once.
Common Traps and a Practical Workflow
A grouped-binomial fit is appropriate when each row gives a number of events and a known number of eligible trials, and the model assigns a common probability to trials with the same predictors. It is not enough that a response happens to be expressed as a percentage. A percentage may be based on 8 trials or 8,000; the denominator is essential to its binomial contribution.
Define what one trial represents and what counts as an event. Check that the response is a count of events, not a rate or a continuous amount.
For every group, record the known total \(n_i\) and verify \(0\leq y_i\leq n_i\). Compute non-events as \(n_i-y_i\).
Use event and non-event counts together, proportions with trial-total weights, or one binary response per individual trial. Do not drop the trial totals.
With the logit link, coefficients describe changes in log-odds. Exponentiated coefficients describe odds ratios; they are not probability differences or probability ratios.
A frequent exam trap is to pool group proportions by taking their simple average even when group sizes differ. The correct intercept-only estimate is \(\sum_i y_i/\sum_i n_i\), which equals the average of proportions only in special cases, such as equal trial totals. Another trap is to use a proportion response with no weights: the model then treats each group row as one trial, rather than allowing the known number of trials to determine its contribution.
Check Your Understanding
For each problem, identify the grouped-binomial calculation or encoding that matches the stated data.
- Two categories have 6 events among 24 trials and 14 among 28 trials. Find the common-probability maximum-likelihood estimate and the unweighted average of the two observed proportions. (Answer: pooled estimate \(20/52=0.3846\); unweighted average \((0.25+0.50)/2=0.3750\).)
- A reference group has 9 events among 30 trials, and a comparison group has 21 among 35. For a two-group logit model with the reference group as baseline, give the fitted intercept, comparison coefficient and odds ratio. (Answer: intercept \(\log(3/7)\approx-0.8473\); coefficient \(\log(3.5)\approx1.2528\); odds ratio \(3.5\).)
- Two groups have proportions 0.30 and 0.80, based on 10 and 20 trials respectively. Find the trial-weighted common estimate and the unweighted average. (Answer: weighted estimate \((3+16)/30=0.6333\); unweighted average \(0.5500\).)
- A group has 7 events among 12 trials. State its event and non-event counts for a two-column R binomial response, and its observed proportion. (Answer: counts \(7\) and \(5\); proportion \(7/12=0.5833\).)
- Three groups have counts of 4 out of 8, 9 out of 15, and 21 out of 35. Under an intercept-only grouped-binomial model, calculate the fitted probability and the expected event count in the 58 trials. (Answer: fitted probability \(34/58=0.5862\); expected event count \(58(34/58)=34\).)