Why Grouped Binomial Responses Need Care
A binary response is often recorded one trial at a time: each policy either has a claim or does not, each applicant either renews or does not, and each test either detects a condition or does not. In a data set with many trials sharing the same predictor values, it can be more convenient to record the number of successes and failures in each group. The response is then a grouped binomial response.
Grouping changes how a response must be entered in a generalized linear model. A row containing 4 successes from 10 trials is not one binary outcome equal to 4. It represents ten trials, of which four had outcome 1. In R, the two standard encodings are a two-column response containing successes and failures, or a success proportion accompanied by a weight equal to the number of trials.
The common-probability condition matters: a group should combine trials with the same modeled probability, usually because they have the same values of the predictors in the GLM. If the trials have different probabilities that are not represented by the model, their total count is generally not binomial with one common \(p_j\). The usual grouped-binomial GLM also assumes conditional independence of trials; dependence or extra variation requires further modeling, not merely a different response encoding.
Why a Group Contributes a Binomial Probability
Suppose a particular ordered sequence of \(n_j\) independent trials has exactly \(x_j\) successes. Its probability is \(p_j^{x_j}(1-p_j)^{n_j-x_j}\), because each success contributes a factor \(p_j\) and each failure contributes a factor \(1-p_j\). The observed group count does not specify the order of those outcomes. There are \(\binom{n_j}{x_j}\) different sequences with \(x_j\) successes, and these sequences are mutually exclusive. Adding their equal probabilities gives the probability of the observed count:
This probability is the group’s likelihood contribution when viewed as a function of the model probability \(p_j\), with the observed counts held fixed. If groups are conditionally independent, the likelihood for all groups is the product of their contributions; the log-likelihood is the sum of their log contributions. The binomial coefficient is part of the probability of the observed count. It does not depend on the model coefficients, but it should not be confused with a factor that can be omitted when reporting the full likelihood contribution.
Worked Example: Calculating Contributions at Fixed Probabilities
Worked Example: Calculating Contributions at Fixed Probabilities
Two independent hypothetical groups have observed counts and specified success probabilities: group A has 1 success from 4 trials with \(p_A=0.3\), and group B has 2 successes from 3 trials with \(p_B=0.6\). Calculate each likelihood contribution and the total log-likelihood. Use the full binomial probability, including the binomial coefficient.
Method. Apply the grouped-binomial probability separately to each group. Independence means the joint likelihood is the product; equivalently, its log is the sum of the two log contributions.
Group A. Here \(n_A=4\), \(x_A=1\), and \(n_A-x_A=3\). Therefore, \(\binom{4}{1}=4\), \(0.3^1=0.3\), and \(0.7^3=0.343\). The contribution is \(4(0.3)(0.343)=4(0.1029)=0.4116\).
Group B. Here \(n_B=3\), \(x_B=2\), and \(n_B-x_B=1\). Therefore, \(\binom{3}{2}=3\), \(0.6^2=0.36\), and \(0.4^1=0.4\). The contribution is \(3(0.36)(0.4)=3(0.144)=0.432\).
Combine and check. The likelihood is \(0.4116(0.432)=0.1778112\). The total log-likelihood, rounded to four decimal places, is \(\log(0.4116)+\log(0.432)\approx -1.7270\). This agrees with \(\log(0.1778112)\approx -1.7270\).
Common mistake avoided. Using only \(p^x(1-p)^{n-x}\) omits the number of arrangements of successes and failures. That would give \(0.1029\) for group A instead of \(0.4116\), and \(0.144\) for group B instead of \(0.432\).
Two Standard Encodings in R
For each row, the success/failure form supplies the two observed counts directly. The alternative proportion form supplies \(x_j/n_j\) as the response and \(n_j\) as the prior weight. In both cases, the model probability is commonly linked to predictors with the logit link, \(\log(p_j/(1-p_j))=\eta_j\), where \(\eta_j\) is the linear predictor.
Record the successes, failures, and predictors for each group. Set the trial count to successes plus failures.
Use a two-column response such as cbind(success, failure), or use success divided by trials as the response.
When the response is the success proportion, set the binomial prior weights to the number of trials in that row.
Use family=binomial(link="logit") and the same predictor formula for either encoding.
For example, if the data frame has columns named success, failure, trials, and age, the two forms are `glm(cbind(success, failure) ~ age, family=binomial(link="logit"), data=d)` and `glm(success/trials ~ age, weights=trials, family=binomial(link="logit"), data=d)`. The first form makes the two counts explicit. The second uses a proportion for the response and uses the trial count as the binomial prior weight.
The proportion must be \(x_j/n_j\), not the raw success count \(x_j\). The weight must be the number of trials represented by that proportion. A row with 4 successes and 6 failures therefore has response \(4/10=0.4\) and weight 10 in the proportion form, or response columns 4 and 6 in the count form.
Worked Example: Checking Equivalent R Representations
Worked Example: Checking Equivalent R Representations
A hypothetical underwriting study groups applicants by a risk category. Group A has 2 accepted applicants among 4 trials; group B has 3 among 6. Consider an intercept-only binomial model, so both groups have the same modeled probability. Show how to encode the data in R, calculate the fitted probability, and evaluate the likelihood at that fit.
Encode the counts. The count data have rows \((success,failure)=(2,2)\) and \((3,3)\). In R, fit `glm(cbind(success, failure) ~ 1, family=binomial, data=d)`.
Encode the proportions. The corresponding proportions are \(2/4=0.5\) and \(3/6=0.5\), with weights 4 and 6. The equivalent fit is `glm(success/trials ~ 1, weights=trials, family=binomial, data=d)`. Both representations describe the same ten Bernoulli trials.
Find the fitted probability. There are \(2+3=5\) successes among \(4+6=10\) trials, so the fitted common probability is \(5/10=0.5\). This is also the observed success proportion in each group.
Calculate the group contributions. For group A, \(\binom{4}{2}=6\), and \(0.5^2(1-0.5)^2=0.5^4=0.0625\). Thus its contribution is \(6(0.0625)=0.375\). For group B, \(\binom{6}{3}=20\), and \(0.5^3(1-0.5)^3=0.5^6=0.015625\). Thus its contribution is \(20(0.015625)=0.3125\).
Combine and check. The total likelihood is \(0.375(0.3125)=0.1171875\). The exact product is \((3/8)(5/16)=15/128=0.1171875\), so the arithmetic checks. The log-likelihood is \(\log(0.375)+\log(0.3125)\), approximately \(-2.1440\) to four decimal places.
Common mistake avoided. Treating each grouped row as one ordinary binary observation would give only two observations, rather than the ten trials represented by the rows. The proportion form needs weights 4 and 6 precisely because the groups contain different numbers of trials.
Interpreting the Likelihood Contribution
A group with more trials generally supplies more information about its success probability than a group with fewer trials. The count form reflects this through both the powers \(p_j^{x_j}\) and \((1-p_j)^{n_j-x_j}\), and the proportion form reflects it by using \(n_j\) as the weight. The weight is not an additional predictor and is not an exposure offset: it says how many Bernoulli trials are summarized by that row.
This is related to, but distinct from, frequency weighting for replicated observations. A frequency weight says that an observation or row is repeated a specified number of times. A grouped-binomial trial weight has a specific interpretation: the row records a success proportion across that number of Bernoulli trials. For binomial responses, the two encodings are equivalent when they describe the same trial counts and predictor values. They are not interchangeable with arbitrary weights that lack a trial-count interpretation.
| Representation | Response in each row | Weight | Meaning |
|---|---|---|---|
| Success/failure counts | Two columns: \(x_j\) and \(n_j-x_j\) | No separate trial-count weight is needed | Directly records both outcome counts |
| Proportion with trial weights | \(x_j/n_j\) | \(n_j\) | Records the observed success fraction and the number of trials behind it |
| Raw success count entered as a proportion | \(x_j\) | Often incorrectly set to \(n_j\) | Not the grouped-binomial proportion form |
Aggregation is appropriate only when a single row’s trials share the modeled predictor values and the binomial assumptions are reasonable. If a predictor varies within a proposed group, splitting the group by that predictor may be necessary. Likewise, a zero-trial row has no observed success proportion and contributes no binomial information; it should not be treated as an ordinary proportion observation.
Worked Example: Evaluating Two Grouped Contributions
Worked Example: Evaluating Two Grouped Contributions
A hypothetical service team models whether a customer renews. Its candidate model predicts probability 0.4 for a segment with 2 renewals among 5 customers, and probability 0.7 for a second segment with 3 renewals among 4 customers. Calculate each group’s likelihood contribution and the joint likelihood. State how the data could be entered in R.
First segment. There are \(n_1=5\) trials, \(x_1=2\) successes, and 3 failures. The coefficient is \(\binom{5}{2}=10\). The probability factors are \(0.4^2=0.16\) and \(0.6^3=0.216\). Therefore the contribution is \(10(0.16)(0.216)=10(0.03456)=0.3456\).
Second segment. There are \(n_2=4\) trials, \(x_2=3\) successes, and 1 failure. The coefficient is \(\binom{4}{3}=4\). The probability factors are \(0.7^3=0.343\) and \(0.3^1=0.3\). Therefore the contribution is \(4(0.343)(0.3)=4(0.1029)=0.4116\).
Joint contribution. The groups are independent, so the joint likelihood at these probabilities is \(0.3456(0.4116)=0.14224896\). Its log-likelihood is \(\log(0.3456)+\log(0.4116)\), approximately \(-1.9502\) to four decimal places.
R representation and check. The count response rows are \((2,3)\) and \((3,1)\), entered using `cbind(success, failure)`. The proportion rows are \(2/5=0.4\) and \(3/4=0.75\), with weights 5 and 4. The probabilities 0.4 and 0.7 in the question are the model’s predictions; they need not equal the observed proportions. The two encodings preserve the same counts, while the fitted model supplies \(p_1\) and \(p_2\) for the likelihood calculation.
Common mistake avoided. Do not replace the model prediction for the second segment by its observed proportion \(3/4\). The likelihood contribution uses the probability specified by the candidate model, \(p_2=0.7\), not an outcome-derived value substituted after the fact.
Common Mistakes and Practical Checks
- Entering a count as a proportion. For 4 successes from 10 trials, enter \(0.4\) with weight 10, or enter success and failure counts 4 and 6. Do not enter response 4 as if it were a proportion.
- Using the number of groups as the weight. The proportion weight is the trial count in that row, not the total number of rows and not the number of successes.
- Dropping failures. If only successes and total trials are stored, compute failures as trials minus successes. The failure count determines the exponent on \(1-p_j\).
- Combining unlike trials. Do not aggregate observations with different modeled probabilities into one binomial row merely to shorten the data set.
- Forgetting the binomial coefficient in a probability calculation. It is essential to the probability of the observed count, even though it does not change the coefficient estimates when the counts are fixed.
Check Your Understanding
For each problem, identify the grouped-binomial quantities and check the final likelihood calculation where requested.
- A group has 4 successes from 6 trials and a specified probability \(p=0.5\). Find its likelihood contribution. (Answer: \(\binom{6}{4}(0.5)^4(0.5)^2=0.234375\).)
- A group has no successes in 3 trials, with specified probability \(p=0.2\). Find its likelihood contribution. (Answer: \((0.8)^3=0.512\).)
- Two independent groups have 1 success from 4 trials with \(p=0.3\), and 2 successes from 3 trials with \(p=0.6\). Find their separate contributions and total log-likelihood, rounded to four decimals. (Answer: \(0.4116\) and \(0.432\); total log-likelihood \(\log(0.4116)+\log(0.432)\approx -1.7270\).)
- A row records 7 successes and 5 failures, and a predictor value of 2 for every trial. Give both valid binomial response encodings in R’s model terms. (Answer: use cbind(success, failure) with counts 7 and 5, or response \(7/12\) with prior weight 12; use predictor value 2 in either encoding.)
- At fixed probabilities, group A has 3 successes from 5 trials with \(p_A=0.6\), and group B has 1 success from 2 trials with \(p_B=0.4\). Find the two contributions and their product. (Answer: group A \(=10(0.6^3)(0.4^2)=0.3456\); group B \(=2(0.4)(0.6)=0.48\); product \(=0.165888\).)