Mixed-effects logistic regression
Mixed-effects logistic regression models a binary outcome with a random cluster intercept and estimates odds ratios conditional on that intercept.
Fit
When to use it, and when not to
Use it when
- Patients share clinics or other clusters, and the outcome is binary.
- You want a conditional odds ratio and can justify a random-intercept model.
Not when
- You want a population-average coefficient directly. Consider generalized estimating equations with suitable cluster inference. Read: Generalized estimating equations
- There is no clustering and observations are independent. Use ordinary logistic regression. Read: Logistic regression
- The outcome is continuous. Use a suitable linear mixed-effects model. Read: Mixed-effects models
Before you start
What you need
- A binary outcome and its time horizonoutcomeTypeUse a defined yes-or-no outcome measured consistently across clusters.
- Cluster identifiers, sizes and event countsclusteredReport independent clusters, not just patients. Group-level exposure requires clustering even when each patient contributes one outcome.
- Exposure level and adjustment factorsState whether exposure varies within clusters or only between clusters. Separate within-cluster and between-cluster associations where needed.
- A conditional or marginal targetsummaryMeasureExponentiating a fixed log-odds coefficient gives a conditional odds ratio. Marginal risks require averaging over a specified population.
- A model-compatible missing-data planUnder missing at random, consider multilevel imputation. Retain people with unmeasured exposure where feasible and assess missing not at random.
- Outcomes are independent after conditioning on covariates and the random intercept.How to check: Check residual dependence and whether a single cluster level is enough.
- Cluster intercepts follow the chosen distribution, usually normal.How to check: Check fit, near-zero variance, convergence and sensitivity to distributional assumptions. Sparse cluster events can destabilize estimates.
- The random intercept is independent of included exposures after appropriate adjustment.How to check: This is especially consequential for group-level exposure. A random intercept alone does not remove cluster-level confounding.
- There are enough independent clusters for the chosen inference.How to check: Under 30 clusters, name a small-sample approach, such as a model-based parametric bootstrap, and check its coverage with design-specific simulation.
Plain language
How it works
The log odds equal a fixed intercept, exposure and adjustment terms, plus a clinic’s random intercept. A normal distribution describes the clinic intercepts. Exponentiating an exposure coefficient gives a conditional odds ratio, holding the random intercept and other covariates fixed.
A marginal odds ratio compares odds formed from averaged probabilities. Integrate over random intercepts and standardize over the target covariates. Because the link is nonlinear, it generally differs from the conditional odds ratio even without confounding.
A clinic exposure is compared between clinics at a fixed random intercept, not within one clinic. Its effect relies on stronger assumptions about clinic differences. Report cluster counts, variance, convergence and singular fits. Use design-specific small-sample inference when clusters are few.
Worked example
A worked example
- Setting
- A binary patient exposure varies within 40 independent clinics. Assume illustrative model output, rather than claiming a model was fitted.
- Question
- How do conditional and marginal odds ratios differ under this assumed model?
- Approach
- At a zero clinic intercept, baseline risk is 20 in 100. Assume a conditional odds ratio of 2.00, log-coefficient standard error 0.20, and normal intercept standard deviation 1.00.
- Result
- The conditional odds ratio is 2.00 (95% Wald interval 1.35 to 2.96). Averaging over the same clinic distribution gives risks of 23.9 and 36.0 in 100.
- What it means
- Those averaged risks give a marginal odds ratio of 1.79. It differs from the conditional odds ratio even without confounding. These are model probabilities, not observed event counts.
In practice
Recent studies PubMed search · not vetted
Watch out
Common mistakes
The one to remember
The fixed coefficient gives a conditional odds ratio, not a marginal odds ratio or risk ratio. A random intercept does not remove confounding. Under 30 clusters, name and validate a small-sample approach; an ordinary Wald interval may be unreliable.
- Calling the conditional odds ratio a population-average odds ratio.Instead: Average predicted probabilities over the target covariates and random effects, then form a marginal contrast. An intercept set to zero is not averaging.
- Using a random intercept to claim an observational association is causal.Instead: Specify confounders and exposure timing. Check within-cluster and between-cluster effects; clustering does not identify a causal effect.
- Reporting only patient count when exposure is assigned to clinics.Instead: Information about a clinic exposure depends heavily on independent clinics. Many patients cannot rescue very few clusters.
- Using a Wilson interval for a regression odds ratio.Instead: Use a log-coefficient Wald or profile-likelihood interval. Few clusters may require a justified bootstrap or another design-specific approach.
Inside Mallard
How Mallard uses this
The method registry links clustered mixed-effects logistic regression to this article and code.
mixed-effects-logistic-clustered).analysis.mixed_effects_logistic, the id a plan cue records.How to report it
Report the binary outcome, exposure level, fixed covariates, cluster counts and sizes, random-intercept distribution, fitting method, convergence and conditional odds ratio interval. A reporting guideline is not a design manual: use it to make the study transparent, not as a substitute for careful design. Check the target journal's own requirements as well, which this page cannot know.
Related Learn pages
Related designs and methods
Evidence
Sources & further reading
- Intermediate and advanced topics in multilevel logistic regression analysis. (opens in a new tab) · Stat Med · doi 10.1002/sim.7336
- Between- and within-cluster covariate effects in the analysis of clustered data. (opens in a new tab) · Biometrics