Ask Mallard
Analysis method

Mixed-effects logistic regression

5 min read

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

Before you start

What you need

Decide these first
  1. A binary outcome and its time horizonoutcomeTypeUse a defined yes-or-no outcome measured consistently across clusters.
  2. Cluster identifiers, sizes and event countsclusteredReport independent clusters, not just patients. Group-level exposure requires clustering even when each patient contributes one outcome.
  3. Exposure level and adjustment factorsState whether exposure varies within clusters or only between clusters. Separate within-cluster and between-cluster associations where needed.
  4. A conditional or marginal targetsummaryMeasureExponentiating a fixed log-odds coefficient gives a conditional odds ratio. Marginal risks require averaging over a specified population.
  5. 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.
It rests on these
  1. 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.
  2. 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.
  3. 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.
  4. 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.

Average risks before forming a marginal contrast

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.

Cluster-level exposure and sparse data

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.

Conditional and population curves
Several steep S-shaped curves, one per cluster, and a thicker population-average curve that is flatter, because averaging steep logistic curves spreads them out. This holds for a logistic link; with an identity link the two can coincide.Subject-specific curves and the population-average curveExposureProbability of the outcomePopulation average: flatterEach cluster: steepWith a logistic link, averaging steep cluster-specific curves gives a flatter population curve, so a mixedmodel's odds ratio and a GEE odds ratio answer different questions. With an identity link the two cancoincide.
Conceptual diagram. It shows the structure of the idea, not data from any study.

Worked example

A worked example

Invented for illustration
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

Searching PubMed…

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.

Code example in Mallard: Mixed-effects logistic regression for clustered binary outcomes (mixed-effects-logistic-clustered).
Atlas node 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.

Code for this method
Loading…

Related Learn pages

Related designs and methods

Evidence

Sources & further reading

  1. Intermediate and advanced topics in multilevel logistic regression analysis. (opens in a new tab) · Stat Med · doi 10.1002/sim.7336
  2. Between- and within-cluster covariate effects in the analysis of clustered data. (opens in a new tab) · Biometrics
Prepared with AI assistance. PubMed records checked by title, authors, year and available DOI on 2026-11-07: record verified, confirm it supports this use. No independent professional approval is claimed. Austin and Merlo explain marginal effects from multilevel logistic models. Neuhaus and Kalbfleisch show why within-cluster and between-cluster covariate effects need separate attention. The numerical example assumes model output; no fit or bootstrap is claimed.
Last source review: 2026-11-07
AI-generated educational content
Mallard uses reputable methodological and reporting sources, but this material may contain errors or omit important context. Verify important methodological decisions with the cited sources and, when appropriate, a qualified research methodologist or statistician.