Tutorials › Generalized Linear Mixed Models (GLMM) › An End-to-End GLMM Case Study of Rural Clinic Visits

Software and Case Studies · Tutorial 698 of 698

An End-to-End GLMM Case Study of Rural Clinic Visits

Follow a hypothetical clinic-visit dataset from exposure-adjusted model specification to diagnostics and interpretable clinic-level rate comparisons.

Intermediate 12 min read

What You'll Learn

  • Specify a clinic-level count GLMM with a log-exposure offset and a random intercept.
  • Calculate crude visit rates and interpret a fitted annual rate ratio with its uncertainty.
  • Translate clinic random effects into exposure-adjusted conditional rates and rate ratios.
  • Check model fit, convergence, exposure measurement, and influential clinics.
  • Distinguish conditional clinic comparisons from population-average comparisons and simpler alternatives.
  • Assemble the analysis into a reproducible report that makes the data, model, and uncertainty auditable.

From Clinic Counts to Comparable Rates

A clinic that sees more visits may serve more patients or may have a higher visit rate. Counts alone cannot distinguish these explanations. In a rural-clinic utilization analysis, the denominator matters: a clinic observed over 1,000 patient-years has had more opportunity to record visits than one observed over 500 patient-years. Clinics are also clusters: repeated observations from one clinic may be more alike than observations from different clinics.

This case study uses hypothetical visit counts from eight rural clinics, each observed in two calendar years. The goal is to estimate annual change while accounting for patient-year exposure and persistent differences among clinics, then report clinic-level rates and comparisons with appropriate uncertainty. The data below are illustrative, not observations from an actual health system.

Model: Let \(Y_{jt}\) be the number of visits at clinic \(j\) in year \(t\), and let \(E_{jt}\) be its exposure in patient-years. Let \(I(t=2025)\) equal 1 in 2025 and 0 in 2024. The random-intercept Poisson GLMM is $$ Y_{jt}\mid b_j \sim \operatorname{Poisson}(\mu_{jt}), \qquad \log(\mu_{jt})=\log(E_{jt})+\beta_0+\beta_1 I(t=2025)+b_j, \qquad b_j\sim N(0,\tau^2). $$ The clinic effects \(b_j\) are independent across clinics. Conditional on the clinic effects, the counts are independent Poisson variables with the stated means. The coefficient of \(\log(E_{jt})\) is fixed at 1, so exposure is an offset, not an estimated predictor.

Assemble and Inspect the Data

Each row in the analysis data represents one clinic-year. Counts are visits recorded during that year; exposure is the corresponding time at risk, in patient-years. The compact table shows the eight clinic records in each year, with exposure of 1,000 patient-years for every clinic-year.

Clinic2024 visits2025 visitsExposure in each year (patient-years)
A2503001,000
B1601951,000
C2202601,000
D1802201,000
E2002401,000
F1702051,000
G2302751,000
H1902351,000

Before fitting a model, verify that counts are nonnegative integers, exposures are positive and expressed in the same units, and clinic identifiers are consistent across years. The total is 1,600 visits in 8,000 patient-years for 2024 and 1,930 visits in 8,000 patient-years for 2025. A crude rate is a useful descriptive check, but it does not account for the repeated observations within clinics.

Worked Example: Calculate a Crude Clinic Rate

Clinic A recorded 250 visits in 2024 over 1,000 patient-years. Its crude 2024 rate per 1,000 patient-years is

$$ \frac{250\ \text{visits}}{1{,}000\ \text{patient-years}} \times 1{,}000 =250\ \text{visits per 1,000 patient-years}. $$

For all clinics combined in 2024, the corresponding rate is \(1{,}600/8{,}000\times1{,}000=200\) visits per 1,000 patient-years. Clinic A’s crude rate is higher than this pooled descriptive rate, but that difference alone does not quantify uncertainty or account for the model’s repeated clinic observations.

Fit and Interpret the Exposure-Adjusted Model

The log link makes the mean visit rate multiplicative. Since \(\mu_{jt}/E_{jt}\) is the expected rate per patient-year, the model implies \(\log(\mu_{jt}/E_{jt})=\beta_0+\beta_1 I(t=2025)+b_j\). Thus, for a clinic with \(b_j=0\), \(\exp(\beta_0)\) is its modelled 2024 rate per patient-year, and \(\exp(\beta_1)\) is the 2025-to-2024 rate ratio. The random intercept permits clinics to have different underlying rates, while partially pooling estimates toward the across-clinic distribution.

For a transparent worked analysis, suppose a correctly converged fit to these hypothetical data gives rounded estimates \(\hat\beta_0=-1.609\), \(\hat\beta_1=0.190\), \(SE(\hat\beta_1)=0.080\), and \(\hat\tau^2=0.025\). The intercept corresponds to \(\exp(-1.609)=0.200\) visits per patient-year, or 200 visits per 1,000 patient-years, for a clinic with random effect zero in 2024. These figures are illustrative rounded model output; a fresh software fit can differ slightly because of estimation and rounding.

Worked Example: Interpret the Annual Rate Ratio

The estimated 2025-to-2024 rate ratio is

$$ \exp(\hat\beta_1)=\exp(0.190)=1.209. $$

Conditional on the clinic random intercept, the model estimates a 20.9% higher visit rate in 2025 than in 2024. A Wald test of \(H_0:\beta_1=0\) uses \(z=\hat\beta_1/SE(\hat\beta_1)\):

$$ z=\frac{0.190}{0.080}=2.375,\qquad p=2\{1-\Phi(2.375)\}=0.01755. $$

At significance level \(\alpha=0.05\), this two-sided test gives evidence of an annual rate difference under the model and its assumptions. A 95% Wald confidence interval for the log rate ratio is \(0.190\pm1.96(0.080)=(0.0332,0.3468)\). Exponentiating the endpoints gives a rate-ratio interval of approximately \((1.034,1.414)\). In context, the model-based interval for the 2025-to-2024 rate ratio is about 1.03 to 1.41, conditional on clinic effects. It is not a 95% probability statement about a fixed parameter.

The Wald calculation uses a large-sample normal approximation for the fixed-effect estimate. It should not be treated as an exact test, particularly with very few clinics. Report the estimate, interval, and model context alongside the p-value; the p-value alone is not a measure of the size or clinical importance of the change.

Compare Clinic-Level Rates

A fitted clinic random effect is a deviation on the log-rate scale. For a specified year, a clinic’s conditional rate per 1,000 patient-years is \(1{,}000\exp(\hat\beta_0+\hat\beta_1 I(t=2025)+\hat b_j)\). A comparison of two clinics in the same year cancels the common fixed year effect: the conditional rate ratio for clinics A and B is \(\exp(\hat b_A-\hat b_B)\). These are conditional, model-based comparisons, not raw rates and not automatically population-average contrasts.

Worked Example: Compare Two Adjusted Clinic Rates

Suppose the fitted conditional clinic effects are \(\hat b_A=0.20\) and \(\hat b_B=-0.15\). In 2025, clinic A’s fitted conditional rate per 1,000 patient-years is

$$ 1{,}000\exp(-1.609+0.190+0.20) =1{,}000\exp(-1.219) \approx 295.4\ \text{visits per 1,000 patient-years}. $$

For clinic B the corresponding calculation is \(1{,}000\exp(-1.609+0.190-0.15) =1{,}000\exp(-1.569)\approx208.2\) visits per 1,000 patient-years. The conditional rate ratio is

$$ \exp\{\hat b_A-\hat b_B\} =\exp\{0.20-(-0.15)\} =\exp(0.35)=1.419. $$

The fitted 2025 rate for clinic A is about 1.42 times the fitted rate for clinic B, conditional on the model and the estimated clinic effects. Suppose the software’s estimated standard error for this log-rate contrast is 0.14. Its 95% Wald interval on the log scale is \(0.35\pm1.96(0.14)=(0.0756,0.6244)\), or \((1.079,1.867)\) after exponentiation. This interval compares rates, not visit counts. It uses uncertainty in the fitted contrast; it must not be replaced by comparing two point estimates alone.

A clinic-effect estimate is typically shrunk toward zero compared with an estimate based only on that clinic’s observed rate. This partial pooling stabilizes estimates, especially for clinics with less exposure, but it means that a model-based clinic rate is not simply that clinic’s count divided by exposure. If many clinic pairs are presented as inferential comparisons, the report should also address multiplicity or clearly label the comparisons as descriptive.

Diagnostics, Assumptions, and Alternatives

The Poisson GLMM assumes that, conditional on the random intercept and fixed effects, the count variance equals the conditional mean. The normal random-intercept distribution is an assumption about between-clinic variation. The offset assumes exposure is measured adequately and that expected counts scale proportionally with exposure. Conditional independence also matters: after accounting for the clinic effect and year, there should not be unmodelled dependence that materially changes the uncertainty.

Check optimizer convergence and inspect warnings, gradients, and estimates near parameter boundaries before interpreting output. Examine observed and simulated counts or simulation-based residuals by clinic and year; investigate systematic residual patterns, unusually many zeros, and clinics with disproportionate influence. Compare observed rates with fitted rates, while remembering that fitted random effects are informed by the same observations. A conspicuous clinic can reflect data error, genuine heterogeneity, or model misspecification; it is not a reason to delete a clinic without justification.

If conditional variation is greater than the Poisson model can explain, a negative-binomial mixed model may be a useful alternative. If there are excess zeros for a substantive reason, consider whether a zero-inflated or hurdle model is appropriate rather than choosing one solely because it improves a fit statistic. A Poisson model without random effects ignores within-clinic dependence and may understate uncertainty. A model with clinic fixed effects instead estimates a separate parameter for each clinic, does not use the same partial pooling, and can be cumbersome when many clinics are present. Each alternative changes the assumptions and often the target of inference; compare fit and scientific purpose, not only a single score.

With only eight clinics, estimates of \(\tau^2\), clinic effects, and their uncertainty may be imprecise. A random-effects distribution can also be a poor description if clinic differences are strongly non-normal or if important clinic-level predictors are omitted. The random intercept does not establish why clinics differ, and the estimated annual association does not show that calendar year caused a change in utilization. The analysis also cannot correct errors in the visit definition, incomplete exposure measurement, or changes in patient composition that have not been represented in the model.

Make the Report Reproducible

A report should let a reader reconstruct the analysis decisions, not merely view a polished table. State the hypothetical or real data source, the unit of analysis, the outcome definition, the exposure unit, the time period, and how missing or excluded records were handled. Specify the model equation, distribution, link, offset, random-effects structure, estimation method, software and package versions, and any convergence warnings. Preserve the analysis data and executable code or a version-controlled source file, and identify the saved model output used for reported estimates.

Present crude totals and rates as descriptive context, followed by adjusted estimates with units, confidence intervals, and the conditioning interpretation. Label the clinic comparisons as model-based conditional rates; include the exposure unit in every rate table. Report diagnostic findings and limitations rather than implying that a successful optimizer proves the model is correct. A useful report also makes clear which values are raw summaries and which are fitted estimates, and avoids excessive decimal precision relative to the data.

1
Validate the analysis rows.
Confirm one row per clinic-year, nonnegative integer counts, positive patient-year exposure, and stable clinic identifiers.
2
Fit the prespecified model.
Use the log of exposure as an offset, year as a fixed effect, and clinic as a random intercept; record software and estimation details.
3
Check fit before interpretation.
Review convergence, residual patterns, dispersion, influential clinics, and whether the exposure and dependence assumptions are defensible.
4
Report rates and contrasts.
Transform log-scale estimates to rate ratios or visits per 1,000 patient-years, retain uncertainty, and state that clinic estimates are conditional.

Common Mistakes and Final Interpretation

  • Comparing raw counts. A larger count can result from greater exposure. Compare rates with the appropriate exposure denominator and model the exposure offset.
  • Calling \(\exp(\hat b_j)\) a causal clinic effect. It is a fitted clinic deviation under the model, not an explanation of why the clinic rate differs.
  • Ignoring clustering. Treating repeated years from one clinic as independent without a clinic effect can misrepresent uncertainty.
  • Reading a conditional estimate as population-average. State whether a rate or contrast conditions on clinic effects; the two targets need not coincide.
  • Reporting a p-value as the finding. Give the rate ratio, interval, units, and assumptions, and describe the p-value as evidence relative to the specified null under the model.
Key takeaway: For rural-clinic visit counts, a GLMM combines an exposure offset for unequal observation time with a clinic random effect for clustering and heterogeneity. Its rate comparisons are useful only when their units, conditional interpretation, uncertainty, diagnostics, and limitations are reported together.

Check Your Understanding

Answer these questions, then compare your reasoning with the solutions below.

  1. A clinic records 90 visits over 450 patient-years. What is its crude rate per 1,000 patient-years?
  2. In the model, what does \(\exp(\beta_1)\) represent, and what is held constant in its interpretation?
  3. Why is \(\log(E_{jt})\) an offset rather than an ordinary predictor with an estimated coefficient?
  4. If the estimated log-rate contrast between two clinics is 0.20, which clinic has the higher fitted conditional rate, and by what factor?
  5. Name two checks that could reveal a problem with the fitted count model.

Solutions. (1) \(90/450\times1{,}000=200\) visits per 1,000 patient-years. (2) It is the 2025-to-2024 conditional rate ratio, holding the clinic random intercept fixed. (3) The offset encodes proportional scaling of expected counts with exposure; its coefficient is constrained to 1 rather than estimated. (4) The clinic in the numerator of the contrast has the higher rate; the factor is \(\exp(0.20)=1.221\), about 1.22. (5) Appropriate checks include optimizer convergence and residual or simulated-count patterns by clinic and year; examining excess zeros, dispersion, and influential clinics is also useful.

Clinical Biostats