Longitudinal Outcomes Modeling
A family of regression methods for repeatedly-measured (panel) outcomes on the same patients over time, whose central choice is whether the target estimand is subject-specific (conditional, from a mixed model) or population-averaged (marginal, from GEE), with MMRM as the regulatory-favored special case for continuous endpoints.
In plain language
Longitudinal outcomes modeling analyzes outcomes that are measured on the same patient at multiple points in time — for example, a blood sugar value recorded at every clinic visit for a year. Because measurements from the same person tend to move together (a patient who runs high in January is likely to run high in June), you cannot treat each visit row as if it came from a different person; doing so underestimates uncertainty and can produce false-positive findings. These methods explicitly account for that within-person similarity, letting you estimate how a patient's outcome trajectory changes over time and whether treatment alters that trajectory. The main decision you face is whether you want a result about a specific patient's own trend (a subject-specific model) or about the average trend in the whole population (a population-averaged model).
Longitudinal outcomes modeling
addresses the analytic problem created when each patient contributes multiple measurements of the same outcome over time — monthly HbA1c, quarterly total cost, repeated PHQ-9 or pain scores, serial eGFR. Those measurements are correlated within a patient, so ordinary regression that treats every (person, time) row as independent reports standard errors that are too small and tests that are anti-conservative. This entry is the family-level decision concept: it does not re-derive any single model but tells you how to choose among a linear mixed-effects model (LMM), a generalized estimating equation (GEE), a mixed-model repeated measures (MMRM) analysis, and a generalized linear mixed model (GLMM) for a binary or count longitudinal outcome — and, just as importantly, when a longitudinal model is the wrong tool and a time-to-event or count-rate model belongs instead. The detailed mechanics of each member live in the sibling concepts (`mixed-effects-models-longitudinal-rwe`, `gee-population-average-models-rwe`, `mmrm-repeated-measures-rwe`); the value added here is the estimand-first selection logic.
Core estimand distinction
. The single most consequential — and most frequently botched — choice is conditional vs marginal. A mixed model with a random patient intercept (or slope) estimates a subject-specific (conditional) effect: the expected change in a given patient's outcome holding that patient's random effect fixed ("how much does this patient's HbA1c fall on drug A vs what it would have been on drug B"). A GEE estimates a population-averaged (marginal) effect: the contrast in the population mean outcome between exposure groups, averaging over the random-effect distribution. For an identity-link Gaussian outcome the two coefficients coincide, so the LMM-vs-GEE debate is mostly about robustness and missing-data assumptions. For a non-linear link (logistic, log) they do not coincide: the marginal log-odds is attenuated toward the null relative to the subject-specific log-odds by a factor governed by the random-effect variance, so a GLMM and a GEE on the same binary panel return numerically different — and differently interpretable — estimates. Hubbard et al. (2010) make this the explicit deciding question: report a marginal effect when the audience is a population/policy contrast (utilization, budget impact, a coverage decision) and a subject-specific effect when the clinical question is about an individual patient's trajectory. MMRM is a particular LMM for a continuous endpoint that uses only fixed effects for time (categorical visit) with an unstructured within-patient covariance and no random subject effect, giving a marginal-mean estimate at each visit that is valid under missing-at-random (MAR) — which is why the PhRMA working group and FDA reviewers treat it as the default primary analysis for continuous longitudinal trial-like endpoints (Mallinckrodt et al., 2008).
Interpreting the output
Longitudinal modeling produces different outputs depending on which family member you choose, and the estimand determines which number is reported.
If a linear mixed model (LMM) with random intercepts was fit to serial HbA1c data, a fixed-effect treatment coefficient of −0.90 means: for a given patient, the drug arm reduces HbA1c by 0.90 points more than the comparator on average over follow-up, holding that patient's own random intercept (and slope, if modeled) fixed. This is a subject-specific (conditional) estimate — appropriate when the clinical question is about an individual patient's trajectory.
If a GEE was fit to the same data with a log link for binary or count outcomes, the exponentiated coefficient is a population-average (marginal) rate ratio or odds ratio — the contrast between group means averaging over the patient distribution. For a Gaussian identity-link outcome the conditional (LMM) and marginal (GEE) coefficients coincide; for non-linear links (logit, log) the conditional coefficient is larger in magnitude. Pre-specifying which estimand you target — and which model delivers it — is mandatory before seeing results.
If MMRM was fit for a continuous endpoint at scheduled visits, the primary output is the arm-by-visit interaction contrast at the target visit (e.g., mean difference in eGFR change from baseline at Month 12 = 6.4 mL/min, 95% CI 4.1 to 8.7), a marginal estimate valid under missing-at-random. Route to the appropriate sibling entry (`mixed-effects-models-longitudinal-rwe`, `gee-population-average-models-rwe`, `mmrm-repeated-measures-rwe`) for method-specific output interpretation.
Pros, cons, and trade-offs
. - Mixed model (LMM/GLMM) vs GEE: The mixed model gives a likelihood, valid inference under MAR (missingness can depend on observed prior outcomes), subject-specific interpretation, and direct modeling of the correlation structure via random effects; it can borrow strength to predict individual trajectories. Cost: it assumes the random-effect distribution is correctly specified, the conditional/marginal gap confuses non-statistical audiences for non-linear links, and it is more sensitive to misspecification. GEE is semiparametric, needs only the mean model correct (the working correlation can be wrong) with sandwich/robust SEs, and yields the population-averaged effect directly. Cost: GEE is only valid under missing-completely-at-random (MCAR) unless you add inverse-probability-of-observation weights, it discards partially-observed cycles less gracefully, and the sandwich variance is unreliable with few clusters (<~40 patients). Prefer the mixed model / MMRM when dropout is non-trivial (the norm in RWE); prefer GEE for a clean marginal effect with many patients and near-MCAR missingness. - MMRM vs a random-slope LMM with parametric time: MMRM (categorical visit, unstructured covariance) makes the fewest assumptions about the shape of the time trend and the form of the covariance, which is why it is regulatory-preferred; it needs roughly balanced, pre-specified visit windows and enough patients to estimate the full covariance. A random-slope LMM with continuous time is more parsimonious and handles irregular measurement times — common in claims/EHR — but imposes a trajectory shape (linear, spline) and a structured covariance. Prefer MMRM for a confirmatory continuous endpoint with scheduled visits; prefer a parametric-time LMM when visit timing is irregular or the covariance is too rich to estimate. - Longitudinal mean model vs the time-to-event / count families: If the question is "time to first event" or "are events recurring faster," a longitudinal mean model is the wrong family — use survival (`standard-cox-time-dependent`, `cumulative-incidence-risk-rwe`) or recurrent-event/count methods (`recurrent-events-analysis-rwe`, `poisson-negative-binomial-count-models`). Modeling a repeatedly-measured continuous or scalar outcome is this family's job; modeling event occurrence is not.
When to use
. A continuous, ordinal, count, or binary outcome is measured repeatedly on the same patients at two or more time points and you want the treatment effect on the level or trajectory of that outcome (e.g., HbA1c change to month 12, monthly per-patient cost, serial PRO scores); within-patient correlation must be respected; and either an individual-trajectory (subject-specific) or a population-mean (marginal) estimand is clearly specified in the protocol/SAP before you pick the model.
When NOT to use — and when it is actively misleading or dangerous
. - The outcome is an event, not a repeated measurement. Forcing "did the patient have an MI this month (0/1)" into a GLMM panel when the real question is incidence invites immortal-time and informative-censoring problems that survival/recurrent-event methods are built to handle; use those instead. - Reporting a conditional estimate for a population question (or vice versa). Presenting a subject-specific GLMM odds ratio as if it were the population-averaged effect a payer cares about — or a marginal GEE estimate as an individual-patient prognosis — is a silent estimand error that survives every model diagnostic and is genuinely misleading. - GEE with informative dropout. In RWE the sicker arm typically drops out or disenrolls faster; under that MAR-not-MCAR pattern, naive GEE is biased toward the null while an MMRM/LMM remains valid — defaulting to GEE "because it's marginal" can fabricate a false equivalence. - Too few clusters/patients. With a small number of patients the GEE sandwich SE is downward-biased and the mixed-model variance components are unstable; tests become anti-conservative. - Outcome measured at a single time point. There is no within-patient correlation to model; a longitudinal apparatus adds nothing and can obscure a simple cross-sectional contrast.
Data-source operational depth
. - Claims (FFS or commercial): The "repeated measurement" is usually a constructed monthly or quarterly aggregate — total paid cost, fill-derived adherence, a flag for any qualifying diagnosis — built by binning claims into fixed windows keyed off `index_date`. Two failure modes dominate. (1) MA-only person-time: months in which a patient is enrolled in Medicare Advantage (or a capitated arrangement) have no fee-for-service claims, so a "$0 cost" or "no diagnosis" cell is missingness disguised as data; you must carry an enrollment indicator and drop or explicitly model those cells, not treat them as observed zeros. (2) Differential disenrollment by arm makes month-level missingness depend on the (unobserved future) outcome — MAR at best — so an LMM/MMRM under MAR is safer than GEE; restrict to continuous medical+pharmacy enrollment per cycle and verify balance of observed person-months across arms. - EHR: Labs and PROs are recorded only when a visit happens, so measurement timing is irregular and informatively sampled — the sicker arm is drawn more often, which biases any method that assumes measurement times are unrelated to the outcome. Prefer a parametric-time LMM (continuous time, not categorical visit) and consider modeling the visit process; never assume equally-spaced visits when feeding a GEE working correlation like AR(1) that presumes equal spacing. Patients who leave the system are differentially lost; treat loss to follow-up as potentially informative. - Registry: Visit schedules are often protocolized (an advantage for MMRM), and outcomes may be adjudicated, but pharmacy exposure and out-of-registry care are weak; link to claims for complete exposure and to a death index so that "missing" late visits are correctly distinguished from death (a competing terminal event that must not be modeled as ordinary MAR dropout). - Linked claims–EHR–vital records: The ideal substrate — EHR severity and lab values, claims completeness, reliable mortality — but linkage selects the linkable subset and introduces date-discrepancy between order, fill, and service dates that must be reconciled before binning measurements into cycles relative to time zero.
Worked claims example
Question: 12-month HbA1c trajectory after initiating a DPP-4 inhibitor vs a second-generation sulfonylurea in an active-comparator new-user cohort (commercial + Medicare FFS). (1) Cohort: incident initiators with 365 days of continuous A/B/D (or commercial medical+pharmacy) enrollment before the first qualifying fill; `index_date` = that fill; arm = NDC dispensed that day. (2) Build the panel: define visits at months 0, 3, 6, 9, 12; for each (`person_id`, `visit`) take the HbA1c lab value nearest the scheduled month within a ±45-day window from the linked EHR/lab feed; carry an `observed` flag and an `enroll_ffs` flag per cycle so MA-only or disenrolled months are missing, not zero. (3) Fit three models on the same panel to make the estimand visible: (a) MMRM — `PROC MIXED` with categorical `visit`, `arm`, `visitarm`, baseline HbA1c as covariate, and `REPEATED visit / SUBJECT=person_id TYPE=UN` (unstructured), reading the month-12 `visitarm` LS-means contrast as the regulatory primary marginal effect under MAR; (b) GEE — exchangeable working correlation with robust SEs for the population-averaged mean difference; (c) random-intercept LMM for the subject-specific trajectory. (4) Expect the MMRM and random-intercept-LMM fixed effects to be similar (Gaussian, identity link) but their standard errors and missing-data validity to differ, and report the MMRM contrast as primary because dropout is informative. (5) Sensitivity: pattern-mixture or multiple-imputation under not-MAR (`multiple-imputation-longitudinal-rwe`), alternative covariance structures (TYPE=AR(1), TYPE=CS), and a tipping-point analysis on the month-12 contrast.
Worked example
Scenario
A researcher is studying monthly pain scores (0-10 scale) in five patients with chronic knee pain enrolled in a 3-visit study (baseline, month 3, month 6). All five patients are measured at each visit. The goal is to describe the average pain trajectory over 6 months. Before fitting any model, the researcher checks whether it is valid to treat each row in the dataset as independent. This small example shows why it is not, and what the long-format data actually looks like.
Dataset
Long-format pain score table — one row per patient per visit (15 rows total for 5 patients x 3 visits).
| patient_id | visit_month | pain_score |
|---|---|---|
| 1 | 8 | |
| 1 | 3 | 6 |
| 1 | 6 | 5 |
| 2 | 4 | |
| 2 | 3 | 3 |
| 2 | 6 | 3 |
| 3 | 7 | |
| 3 | 3 | 5 |
| 3 | 6 | 4 |
| 4 | 5 | |
| 4 | 3 | 4 |
| 4 | 6 | 4 |
| 5 | 9 | |
| 5 | 3 | 7 |
| 5 | 6 | 6 |
Steps
Notice that each patient appears in three rows. Patient 1 starts at 8, drops to 6, then 5. Patient 5 starts at 9 and also trends down. The data already hints that a high baseline score tends to pair with high later scores — within the same person.
If you ran a naive ordinary regression ignoring patient identity, the model would treat all 15 rows as independent observations from 15 different people. It would see 15 pain scores and estimate a trend, but its standard error would be too small because it is pretending there are 15 independent data points when there are really only 5 independent patients.
A longitudinal model adds a patient-level term that captures each person's overall average pain level. Patient 5 runs about 2 points higher than Patient 2 across all visits; the model learns this and no longer treats those differences as mysterious noise.
With within-person correlation accounted for, the model estimates the average trajectory across all five patients: baseline mean of 6.6, month-3 mean of 5.0, month-6 mean of 4.4 — a drop of about 2.2 points over 6 months.
Because the model correctly assigns observations to their source patients, the uncertainty estimate (standard error) around the 2.2-point drop reflects having 5 independent patients, not 15 independent rows. This gives an honest picture of how confident we should be.
Result
Average pain score fell from 6.6 at baseline to 4.4 at month 6 — a mean reduction of 2.2 points over 6 months. Accounting for within-person correlation (5 patients, not 15 independent rows) produces a standard error roughly 1.5-2x wider than a naive independent-row analysis would, correctly reflecting that the effective sample size is 5, not 15.
Runnable example
python implementation
Fit a subject-specific LMM and a population-averaged GEE on the SAME longitudinal claims panel to expose the estimand difference. Required input (one row per person-visit, already built and cleaned): panel : person_id, visit (int month: 0,3,6,9,12), arm...
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
panel = panel[panel["observed"] == 1].copy() # missing cycles are NOT observed zeros
panel["visit"] = panel["visit"].astype("category") # categorical visit -> MMRM-style means
# (a) Subject-specific: random intercept per patient, treatment-by-visit interaction.
lmm = smf.mixedlm(
"hba1c ~ C(arm) * visit + hba1c_baseline",
data=panel,
groups=panel["person_id"],
).fit(reml=True)
print(lmm.summary()) # coefficients are CONDITIONAL (subject-specific)
# (b) Population-averaged: GEE with exchangeable working correlation + robust (sandwich) SE.
gee = smf.gee(
"hba1c ~ C(arm) * visit + hba1c_baseline",
groups="person_id",
data=panel,
cov_struct=sm.cov_struct.Exchangeable(),
family=sm.families.Gaussian(),
).fit()
print(gee.summary()) # coefficients are MARGINAL (population-averaged)
# Gaussian/identity -> point estimates align; SE & missing-data validity (MAR vs MCAR) differ.r implementation
Same panel, same contrast in R: nlme::gls for the MMRM (unstructured within-patient covariance, no random effect) and geepack::geeglm for the population-averaged marginal effect. Input data frame `panel`: person_id, visit (factor of 0/3/6/9/12), arm (factor...
library(nlme)
library(geepack)
panel <- subset(panel, observed == 1) # missing cycles are not observed zeros
panel$visit <- factor(panel$visit)
panel$arm <- relevel(factor(panel$arm), ref = "SU")
panel <- panel[order(panel$person_id, panel$visit), ]
## (a) MMRM via gls: NO random effect; the unstructured within-patient covariance is
## modeled entirely through corSymm + varIdent (a random intercept here would be
## redundant with / non-identifiable against the unstructured residual covariance,
## so MMRM deliberately omits it). Gives marginal visit means valid under MAR.
mmrm <- gls(
hba1c ~ arm * visit + hba1c_baseline,
correlation = corSymm(form = ~ as.integer(visit) | person_id),
weights = varIdent(form = ~ 1 | visit),
data = panel,
na.action = na.omit,
method = "REML"
)
summary(mmrm) # marginal (MMRM) effects
## (b) Population-averaged GEE: exchangeable working correlation, robust SE.
gee <- geeglm(
hba1c ~ arm * visit + hba1c_baseline,
id = person_id, data = panel,
family = gaussian(), corstr = "exchangeable"
)
summary(gee) # MARGINAL effects (sandwich SE)