Why Fit a Binary Random-Intercept Model?
A binary response, such as remission versus no remission, can be observed repeatedly within clinics, hospitals, or other groups. Outcomes from the same group may be more alike than outcomes from different groups. A random-intercept model represents this clustering while estimating how measured predictors relate to the outcome. This tutorial focuses on specifying and fitting that model with Stata’s melogit, then reading and reporting a fixed-effect estimate.
The model is appropriate when each analysis row represents one person with a binary outcome, the grouping variable identifies the cluster, and the scientific question concerns conditional associations given a cluster’s random intercept. It does not by itself correct a poorly defined analysis sample, incorrect outcome coding, or an unsuitable predictor specification.
The fixed effects describe covariate associations conditional on the clinic random intercept. The random intercept allows each clinic to have a different baseline log odds. Its normal distribution is an assumption about variation across clinics, not a claim that binary outcomes themselves are normally distributed.
From Model to Stata Command
In Stata, melogit fits a mixed-effects logistic regression. The general random-intercept form is melogit outcome predictors || cluster:. Each observation should have a valid 0/1 outcome and a cluster identifier. Use factor-variable notation for categorical predictors, such as i.treatment, and continuous-variable notation, such as c.age. Set or verify the reference category before interpreting a treatment coefficient; for a treatment coded 0 and 1, ib0.treatment explicitly declares 0 as the reference.
The model’s likelihood accounts for the shared random intercept within each cluster. In schematic form, it integrates the conditional Bernoulli likelihood over the distribution of clinic intercepts:
Here \(\phi(b;0,\sigma_b^2)\) is the normal density for the random intercept. Because the integral is generally not available in a simple closed form, software uses numerical methods to estimate the model. The practical consequence is that a coefficient is not calculated by applying ordinary logistic regression separately to each clinic or by treating all records as independent.
Worked Example: Preparing the Patient-Level Command
Suppose a hypothetical dataset has one row per patient, a binary variable remission coded 1 for remission and 0 otherwise, a treatment variable coded 0 for standard care and 1 for a new program, a continuous baseline score, and a clinic identifier. The baseline score is measured in points.
The model with treatment and baseline score as fixed effects and a clinic random intercept is:
A direct Stata specification is melogit remission ib0.treatment c.score || clinic:. The outcome is on the left of the command, treatment is categorical with 0 as its reference, score is continuous, and the term after the double bar requests a random intercept for clinic. The trailing colon is part of Stata’s random-effects syntax.
Before fitting, check that the dataset contains one eligible patient per row, remission is coded only 0 or 1, treatment values and their meanings are correct, and each patient has a clinic identifier. For example, if a value of 2 is actually used to represent “no remission,” it must not be allowed to enter as a third outcome category; recode it according to the study’s coding rules first. A command cannot repair a mistaken definition of the variables.
Reading the Fixed-Effect Output
By default, the fixed-effect table reports estimates on the log-odds scale. Typical columns include the coefficient, its standard error, a z statistic, a p-value, and a confidence interval. The coefficient is the estimated change in conditional log odds for a one-unit predictor increase, holding the other fixed predictors constant and comparing observations at the same random-intercept value. For a binary predictor, it compares the coded category with its reference category.
A coefficient can be exponentiated to obtain a conditional odds ratio. For treatment, \(\exp(\beta_1)\) is the treatment-to-reference odds ratio at the same clinic random intercept and the same values of other covariates. Exponentiating the endpoints of a log-odds confidence interval gives the corresponding odds-ratio interval. Stata’s or option displays exponentiated fixed-effect estimates, but the default coefficient scale is often useful for checking calculations and matching a model equation.
Worked Example: Reporting a Clinic Treatment Estimate
Consider a clearly hypothetical analysis of 240 patients from 12 clinics. The outcome is remission (1 = yes, 0 = no); treatment is 1 for the new program and 0 for standard care; and baseline score is measured in points. The fitted command is melogit remission ib0.treatment c.score || clinic:. Suppose the relevant illustrative fixed-effect output is:
| Term | Coefficient | SE | z | p-value | 95% confidence interval |
|---|---|---|---|---|---|
| New program vs standard care | -0.550 | 0.240 | -2.29 | 0.022 | -1.020 to -0.080 |
The coefficient is a conditional log-odds contrast. Its Wald statistic is the estimate divided by its standard error:
The two-sided p-value of 0.022 is below 0.05, and the reported 95% interval for the log-odds coefficient excludes 0. The corresponding conditional odds ratio is:
Exponentiating the interval endpoints gives \(\exp(-1.020)=0.361\) and \(\exp(-0.080)=0.923\). Thus the illustrative conditional odds ratio is 0.577, with a 95% confidence interval from 0.361 to 0.923. In context, the fitted model estimates that, at the same baseline score and clinic random-intercept value, the new-program group has 0.577 times the odds of remission of the standard-care group. The interval and p-value indicate evidence of a negative conditional treatment association in this hypothetical analysis; they do not establish a causal effect.
The fixed-effect interpretation is distinct from a comparison of overall or population-averaged probabilities. It conditions on the random intercept, and the odds ratio is not a probability ratio. In the output, also inspect the clinic random-intercept variance: it describes estimated between-clinic heterogeneity on the log-odds scale, not the treatment effect.
Understanding the Random-Effects Section
Stata’s output includes a random-effects section identifying the grouping level and the random-intercept variance, commonly labelled var(_cons) under the clinic grouping. If, for example, the estimated variance is 0.64, the estimated standard deviation is \(\sqrt{0.64}=0.80\) log-odds units. This describes the spread of clinic intercepts under the model. It is not a variance of the 0/1 patient outcomes and should not be reported as a fixed-effect coefficient.
A variance estimate near zero means the fitted model estimates little residual clinic-to-clinic variation after accounting for predictors, but it does not automatically prove that clustering is absent. Estimates can be uncertain, especially with few clusters. Conversely, a substantial variance suggests baseline odds differ across clinics under the model, but it does not identify why they differ.
Worked Example: Turning a Clinic Intercept into a Conditional Probability
Continue the hypothetical clinic analysis. Suppose the estimated intercept is \(-0.800\), the treatment coefficient is \(-0.550\), and the baseline-score coefficient is \(0.100\) per point. For a patient with score 0 in a clinic whose random intercept is \(b_j=0\), the fitted linear predictor under standard care is \(-0.800\), so the conditional probability of remission is:
For an otherwise identical patient in the new-program group, the linear predictor is \(-0.800-0.550=-1.350\), giving:
These are model-based conditional probabilities for the specified score and \(b_j=0\), not probabilities averaged over the distribution of clinics. The odds ratio remains \(\exp(-0.550)=0.577\); the difference between the two displayed probabilities is not itself the odds ratio.
Checks, Alternatives, and Common Failure Modes
A successful command is not sufficient evidence that the model is appropriate. Check convergence messages and whether estimates or standard errors are implausibly large. Review outcome frequencies by treatment and clinic, the number of clinics, missingness, and the distribution of continuous predictors. Complete or near-complete separation (a predictor pattern that nearly perfectly predicts the outcome), very sparse outcome information within clinics, or too few clusters can make estimates unstable or make the random-effect variance difficult to estimate. A boundary estimate near zero deserves consideration rather than automatic interpretation as a substantive finding.
The model assumes a linear predictor for continuous covariates on the log-odds scale, a common fixed treatment effect across clinics unless interactions or random slopes are included, and normally distributed random intercepts. Check whether these assumptions are scientifically defensible. A plot of observed outcomes across clusters can reveal sparse clusters or striking differences, but observed proportions alone do not diagnose the full conditional model. Investigate data errors and coding first if the output is unexpected.
An ordinary logistic regression without a clinic effect ignores the specified cluster structure and may understate uncertainty when within-clinic outcomes are correlated. A logistic model with cluster-robust standard errors changes the uncertainty calculation but does not estimate clinic-specific random intercepts. Generalized estimating equations target a population-averaged association rather than this model’s cluster-conditional association. These are alternatives for different assumptions or estimands, not interchangeable command choices. The earlier material on GLMM software and on fitting logistic mixed models with glmer addresses related software choices; here the focus is the Stata specification and its output.
A concise report should identify the outcome, the comparison, the model’s conditional interpretation, the odds ratio and interval (or the coefficient and interval on the log-odds scale), and the clustering level. Include the number of patients and clinics when relevant. State the reference category and units for continuous predictors. Avoid reporting a p-value alone: the effect estimate and uncertainty convey direction and plausible magnitude.
Confirm the 0/1 outcome, predictor coding and reference levels, one-row-per-person structure, and cluster identifier.
Use melogit with the fixed predictors and the random-intercept term after the double bar.
Check convergence and the random-effects estimate, then report the fixed-effect estimate on a clearly identified scale with its uncertainty and context.
Check Your Understanding
Answer each question, then compare your reasoning with the brief solutions below.
- For a binary patient outcome clustered within clinics, what does || clinic: request in a melogit command?
- If treatment is coded 0 for usual care and 1 for a new program, what does the treatment coefficient compare when 0 is the reference?
- A treatment coefficient is 0.30. What is the conditional odds ratio, to three significant figures?
- Why is a coefficient of \(-0.55\) not a 55-percentage-point decrease in outcome probability?
- Name two checks to make if melogit reports convergence problems or unexpectedly large standard errors.
Solutions. (1) It specifies a clinic-level random intercept. (2) It compares the new program with usual care, conditional on the random intercept and other fixed predictors. (3) \(\exp(0.30)=1.35\), so the conditional odds are estimated to be 1.35 times as large. (4) The coefficient is on the log-odds scale; probabilities also depend on the other predictors and random intercept. (5) Check outcome and predictor coding, sparse outcome patterns by clinic, the number of clinics, missingness, and whether estimates indicate separation or other instability.