From Trial Design to Analysis
In a cluster-randomized trial, groups such as clinics—not individual patients—are assigned to treatment. Outcomes may still be recorded for each patient. The analysis therefore needs to respect two features of the design: treatment is assigned at the clinic level, while responses are observed at the patient level. Treating every patient as if independently randomized can make the analysis look more precise than the design warrants.
This tutorial follows a hypothetical trial in which clinics are assigned to a new care program or usual care, and each enrolled patient has a binary response recorded at follow-up. The objective is to show a practical workflow: check the patient-level data, specify a logistic mixed model, inspect the fit, and summarize what it estimates. The examples are illustrative rather than results from a real study.
Let \(Y_{ij}\) equal 1 if patient \(i\) in clinic \(j\) responds and 0 otherwise. Let \(T_j=1\) for a clinic assigned to the new program and \(T_j=0\) for a clinic assigned to usual care. A basic model is
The model assumes that, conditional on the clinic random intercept \(b_j\) and the included predictors, patients’ outcomes are independent Bernoulli variables with the stated probabilities. Clinic random intercepts are modeled as independent draws from a normal distribution with mean zero and variance \(\sigma_b^2\). The model also assumes the logit link and a common treatment coefficient across clinics. For a causal interpretation of the treatment contrast, the trial’s randomization and conduct must support it; the model does not repair allocation errors, selective enrollment, or informative missing outcomes.
In this specification, \(\beta_1\) is the treatment contrast in conditional log odds: it compares treatment and control patients at the same value of \(b_j\). The corresponding conditional odds ratio is \(\exp(\beta_1)\). It is not automatically the population-averaged odds ratio obtained after averaging over the clinic distribution.
Prepare and Check the Patient-Level Data
The fitting data should have one row per patient, including a binary response, the clinic identifier, and the clinic’s assigned treatment. The treatment value must be constant within each clinic: if a clinic is assigned to the program, every patient row for that clinic must show program assignment. Do not create a separate “randomization” row for each patient or duplicate a clinic’s assignment as if it were independently randomized.
Worked Example: Audit a Hypothetical Trial Dataset
Suppose 12 clinics are randomized, six per arm, with 20 patients enrolled in each clinic. Thus there are 240 patient records. The table gives the response counts that would be obtained by grouping those records by clinic.
| Arm | Responders by clinic | Patients per clinic | Total responders / patients |
|---|---|---|---|
| Usual care | 8, 9, 7, 10, 8, 9 | 20 | 51 / 120 |
| New program | 12, 13, 10, 14, 11, 12 | 20 | 72 / 120 |
For each patient row, response is coded 1 for a response and 0 otherwise. A clinic with 8 responders has eight rows coded 1 and twelve coded 0. The usual-care response proportion is \(51/120=0.425\); the program response proportion is \(72/120=0.600\). These are descriptive proportions, not a substitute for the clustered model.
Before fitting, check that there are 240 distinct patient records, 12 clinic identifiers, and exactly six clinics in each arm. Within each clinic, check that treatment has only one value, patient identifiers are not duplicated, and the number of records agrees with the enrollment count. Check that response contains only the intended values 0 and 1, and report the number and handling of missing outcomes. These checks follow directly from the design: an incorrect clinic label or treatment assignment can change the model being fit.
A patient-level data frame can be passed to R’s lme4 function glmer. In code, a basic specification is written as glmer(response ~ treatment + (1 | clinic), family = binomial(link = "logit"), data = patient_data). The term (1 | clinic) specifies a clinic-specific random intercept. If treatment is stored as a factor, choose and document its reference level so the coefficient has the intended contrast. Record the software and package versions used for the analysis.
Fit and Summarize the Logistic GLMM
The model should reflect the randomization and measurement structure before an output table is interpreted. With only a treatment indicator and a clinic random intercept, the treatment contrast is estimated using the patient outcomes while accounting for modeled variation among clinics. Additional patient-level covariates can be included when justified and prespecified, but they do not change the fact that treatment was assigned to clinics.
Worked Example: Read a Hypothetical glmer Fit
For illustration, suppose the fitted model returns an intercept estimate of \(-0.30\) with standard error 0.25, a treatment estimate of \(0.76\) with standard error 0.36, and an estimated clinic random-intercept standard deviation of 0.30. These numbers illustrate how to work with output; they should not be treated as exact results implied by the response-count table.
The treatment coefficient is on the log-odds scale. Exponentiating it gives the conditional odds ratio:
Under the fitted model, at a fixed clinic random intercept, the estimated odds of response for a program patient are about 2.14 times the estimated odds for a usual-care patient. This describes a conditional odds contrast, not a ratio of the two raw response proportions.
A Wald statistic for testing \(H_0:\beta_1=0\) against a two-sided alternative is \(z=\hat{\beta}_1/SE=0.76/0.36=2.11\). The corresponding large-sample two-sided normal-approximation p-value is about 0.035. This calculation describes the approximation used for this illustrative output; with only 12 randomized clinics, it should not be presented as definitive evidence without considering the adequacy of the inferential method for a small number of clusters.
Justifying the Odds-Ratio and Probability Summaries
The odds-ratio calculation follows directly from the model. At a fixed random intercept \(b_j\), the usual-care linear predictor is \(\beta_0+b_j\) and the program linear predictor is \(\beta_0+\beta_1+b_j\). Subtracting gives \(\beta_1\). Since odds equal the exponential of the log odds, the ratio of program to usual-care odds is \(\exp(\beta_1)\). The shared \(b_j\) cancels in this conditional comparison.
A probability can also be calculated for a specified clinic effect. For the illustrative estimates, at \(b_j=0\), the estimated usual-care probability is
For the program at the same \(b_j=0\), it is
These are fitted probabilities for a clinic whose random intercept is zero. They are not probabilities averaged over all clinics. Because the inverse-logit function is nonlinear, applying it to the fixed effects alone is not the same as integrating predicted probabilities over the random-intercept distribution.
Worked Example: Construct a Wald Confidence Interval
Using the illustrative treatment estimate 0.76 and standard error 0.36, a 95% Wald interval on the log-odds scale is the estimate plus or minus 1.96 standard errors:
Exponentiating both limits gives a 95% Wald confidence interval for the conditional odds ratio:
On this illustrative large-sample calculation, the interval ranges from about 1.06 to 4.33 for the conditional odds ratio. The interval’s width indicates substantial uncertainty about the effect size. It is not a 95% probability statement about the fixed parameter. With few randomized clinics, the usual Wald calculation may be unreliable, so the interval’s inferential method and small-cluster limitations should be made explicit.
Diagnostics, Alternatives, and Limitations
A successful optimizer message is necessary but not sufficient evidence that the analysis is appropriate. Check for convergence warnings, a singular fit, and an estimated random-intercept variance near zero. Review response counts by clinic and arm: a clinic with no responses or all responses can create separation-related difficulties, especially when the number of clinics is small. Also inspect whether a few clinics dominate the apparent treatment contrast. These checks do not prove that the model is correct, but they can reveal data or fitting problems that require investigation.
The random-intercept model assumes a particular distribution of clinic effects and a shared treatment effect on the conditional log-odds scale. If clinic response patterns are poorly described by this structure, or if data are sparse, estimates may be unstable. Missing outcomes require a stated strategy and assumptions; silently dropping records is not an adequate account of missingness. In a small trial, inference based on large-sample Wald approximations may be especially questionable. The analysis plan should identify an appropriate method for the number of randomized clinics and any sensitivity analyses before interpreting a p-value as a trial conclusion.
The main alternatives answer related but not identical questions. A logistic GLM that ignores clinics treats patient outcomes as independent and can understate uncertainty when responses within clinics are correlated. A clinic-level analysis aggregates outcomes and respects the assignment unit, but discards patient-level detail and requires a clear choice of how clinics contribute. Generalized estimating equations target a population-averaged contrast and use a different approach to within-clinic dependence. The GLMM is useful when the conditional, clinic-specific model is of interest and its assumptions are defensible; it is not automatically superior for every design or estimand.
In presentation, identify the randomization unit, outcome unit, number of clinics and patients by arm, outcome coding, model formula, link, and random-effects structure. State the treatment coefficient on its original log-odds scale or report its exponentiated conditional odds ratio with an interval, clearly naming the scale. Include the inferential procedure and any convergence or small-cluster caveat. Avoid describing the odds ratio as a probability ratio or as a population-averaged effect.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A trial randomizes 8 clinics and records outcomes for 25 patients per clinic. What are the randomization unit and the outcome unit?
- In a logistic random-intercept model, the treatment estimate is 0.50. Calculate the conditional odds ratio.
- Why is the fitted probability at random intercept \(b_j=0\) not necessarily the population-averaged probability?
- Name two data checks that should be made before fitting the model.
Solutions. (1) The clinic is the randomization unit; the patient is the outcome unit. There are 8 randomized units and 200 patient records. (2) The conditional odds ratio is \(\exp(0.50)\approx1.65\). (3) The population-averaged probability requires averaging the inverse-logit probabilities over the random-intercept distribution; because the inverse-logit is nonlinear, this generally differs from evaluating the model at \(b_j=0\). (4) For example, verify that treatment is constant within each clinic and that response is coded only 0 or 1; also check clinic counts, duplicate patient identifiers, and missing outcomes.