Tutorials › Generalized Linear Mixed Models (GLMM) › Adding Exposure Offsets in R Count Models

Software and Case Studies · Tutorial 669 of 698

Adding Exposure Offsets in R Count Models

You will fit a Poisson GLMM with a fixed log-exposure offset in R and interpret its coefficients on the event-rate scale.

Intermediate 10 min read

What You'll Learn

  • Write a Poisson GLMM whose expected count is proportional to a known exposure.
  • Add the log of person-time or population-time using `offset()` in an `lme4` formula.
  • Interpret exponentiated fixed effects as conditional rate ratios.
  • Check whether the exposure is positive, correctly measured, and appropriate to fix at coefficient one.
  • Recognize why raw counts, crude rates, and an offset answer different modeling questions.

Why Include an Exposure Offset?

A count of 12 events is difficult to compare with a count of 8 unless the opportunities for events were similar. Twelve events during 1,000 person-years may represent a lower rate than 8 events during 200 person-years. The same issue arises when counts are observed over unequal follow-up times or in populations of different sizes. A Poisson GLMM can account for this unequal exposure by including its logarithm as an offset.

The earlier material on fitting Poisson GLMMs with glmer provides the basic count-model structure. Here the central point is that the offset makes the expected count proportional to exposure while leaving the coefficients of interest on a rate-ratio scale.

Definition: Let \(Y_{ij}\) be a count for observation \(i\) in cluster \(j\), and let \(E_{ij}\) be its known, positive exposure, such as person-years at risk. A Poisson GLMM with a log-exposure offset has the conditional model $$ Y_{ij}\mid \mathbf{b}_j \sim \operatorname{Poisson}(\mu_{ij}),\qquad \log(\mu_{ij})=\log(E_{ij})+\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+\mathbf{z}_{ij}^{\mathsf T}\mathbf{b}_j. $$ The offset is the known term \(\log(E_{ij})\), included with its coefficient fixed at one. Thus the model is equivalently $$ \mu_{ij}=E_{ij}\exp\!\left(\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+\mathbf{z}_{ij}^{\mathsf T}\mathbf{b}_j\right). $$

Here \(\mu_{ij}\) is the expected count conditional on the cluster random effects. The random effects \(\mathbf{b}_j\) represent modeled cluster-level variation; for a random-intercept model, a usual specification is \(b_j\sim N(0,\sigma_b^2)\). Conditional on those effects, the model assumes Poisson counts, so the conditional variance equals the conditional mean, and observations are independent given the random effects and predictors. It also assumes that the expected count scales proportionally with exposure: doubling exposure while holding other terms fixed doubles the expected count.

Exposure must be positive because \(\log(0)\) is undefined. A zero count, by contrast, is valid: it contributes an observed count of zero at a positive exposure. The exposure should describe the amount of time, population, or other opportunity during which the event could occur. Its measurement and the chosen unit must be consistent across observations.

Adding the Offset in R

In lme4, put offset(log(exposure_variable)) in the fixed-effects part of the formula. For example, with event counts, an intervention indicator, and a clinic random intercept, the formula is:

R formula: events ~ intervention + offset(log(person_years)) + (1 | clinic)

A full call can be written as:

R call: glmer(events ~ intervention + offset(log(person_years)) + (1 | clinic), family = poisson(link = "log"), data = dat)

The family and link specify a Poisson model with a log link. The offset is not an estimated predictor: the software adds \(\log(\text{person\_years})\) to the linear predictor with coefficient one. The data should contain a nonnegative integer count in each row and a finite, strictly positive exposure for each row.

Worked Example: Interpreting an Intervention Rate Ratio

Suppose a hypothetical study follows patients in several clinics and records event counts and person-years. Each clinic contributes observations under usual care and intervention. The intended model has a clinic random intercept and a log-person-years offset. Assume, for illustration, that the fitted fixed-effect estimates are \(\hat{\beta}_0=-3.912\) and \(\hat{\beta}_1=0.4055\), where intervention equals 1 for intervention and 0 for usual care. These assumed estimates illustrate interpretation; they are not claimed to be calculated from a particular dataset.

For clinic \(j\), the fitted conditional mean is \(\hat{\mu}_{ij}=E_{ij}\exp(\hat{\beta}_0+\hat{\beta}_1\text{intervention}_{ij}+\hat{b}_j)\). At random intercept \(b_j=0\), the usual-care rate is \(\exp(-3.912)\approx0.0200\) events per person-year. The intervention rate is \(\exp(-3.912+0.4055)\approx0.0300\) events per person-year.

The intervention-to-usual-care rate ratio is \(\exp(0.4055)\approx1.500\). Under the fitted model, the intervention group has an estimated event rate 1.50 times the usual-care rate, conditional on the clinic effect and the model covariates. For an observation with 40 person-years and \(b_j=0\), the corresponding expected counts are \(40(0.0200)=0.800\) under usual care and \(40(0.0300)=1.20\) under intervention. The rate ratio is about rates; the expected-count ratio is the same only when comparing equal exposures.

Why the Exponentiated Coefficient Is a Rate Ratio

The rate interpretation follows directly from the model. Define the conditional event rate as the conditional expected count divided by exposure, \(\mu_{ij}/E_{ij}\). Dividing the offset model’s mean by exposure removes the exposure term:

$$ \frac{\mu_{ij}}{E_{ij}} =\exp\!\left(\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+\mathbf{z}_{ij}^{\mathsf T}\mathbf{b}_j\right). $$

For a binary predictor whose coefficient is \(\beta_k\), compare two otherwise identical observations with that predictor set to 1 and 0. Their log rates differ by \(\beta_k\); exponentiating gives a conditional rate ratio of \(\exp(\beta_k)\). The cluster effect cancels in this comparison when both observations share the same cluster effect. A confidence interval for \(\beta_k\) can be exponentiated at both endpoints to obtain a confidence interval for the rate ratio.

The proportional-exposure assumption can also be seen from the mean. If exposure changes from \(E\) to \(cE\), with all other terms unchanged, then:

$$ \mu(cE)=cE\exp(\mathbf{x}^{\mathsf T}\boldsymbol{\beta}+\mathbf{z}^{\mathsf T}\mathbf{b}) =c\mu(E). $$

This is the defining constraint imposed by an offset. It is appropriate when the expected count should scale one-for-one with the amount of exposure, rather than when the data should estimate that scaling.

Worked Example: Converting Person-Days to Person-Years

Suppose a hypothetical dataset records 730 person-days for one observation. This is 2 person-years when using 365 days per year. The log offsets are \(\log(730)\) when exposure is measured in person-days and \(\log(2)\) when it is measured in person-years. Since \(730=365(2)\), the first offset is \(\log(2)+\log(365)\).

The fitted linear predictor must give the same expected count after changing the exposure unit. If the intercept under person-days is \(\beta_{0,\mathrm{day}}\), then the intercept under person-years must satisfy \(\beta_{0,\mathrm{year}}=\beta_{0,\mathrm{day}}+\log(365)\), because \(\log(2)+\beta_{0,\mathrm{year}}=\log(730)+\beta_{0,\mathrm{day}}\). The intercept therefore represents a rate per chosen exposure unit and changes when the unit changes.

For example, if a rate is \(0.001\) events per person-day, its equivalent rate is \(0.365\) events per person-year. The fitted expected count remains the same: \(730(0.001)=0.730\) and \(2(0.365)=0.730\). Rate-ratio coefficients for predictors do not change under this unit conversion, because the added constant in the log offset is absorbed by the intercept.

Worked Example: Unequal Population-Time

Suppose two hypothetical regions contribute 4,000 and 5,000 person-years, with 12 and 20 events, respectively. Their observed rates are \(12/4000=0.00300\) and \(20/5000=0.00400\) events per person-year. The second crude rate is \(0.00400/0.00300=1.333\) times the first. These two rows alone do not support a cluster random-effects fit, but they show how the offset represents differing population-time.

For a larger dataset with repeated observations within regions, the corresponding model might be written as: events ~ region_type + offset(log(person_years)) + (1 | region). If a hypothetical fitted coefficient for region type were \(0.2877\), its rate ratio would be \(\exp(0.2877)\approx1.333\). This would compare modeled rates, accounting for the specified region random effect and other model terms, not simply compare the two raw counts. A coefficient of zero exposure is not used; both example exposures are positive.

Assumptions, Diagnostics, and Alternatives

Before fitting, verify that the exposure has the intended meaning, is positive for every analyzed row, and uses a common unit. Also check that counts refer to the same event definition and observation unit, and that the model’s random-effects structure matches the clustering represented in the data. The offset treats exposure as known and assumes a proportional relationship between exposure and expected count. If exposure is measured with substantial error, or if time at risk is related to unmodeled event risk, the resulting rate estimates can be misleading.

After fitting, inspect convergence messages and the fitted model’s diagnostics, including whether residual patterns or unusually influential observations indicate a poor fit. Compare observed and fitted counts or rates across meaningful exposure ranges and clusters. Strong extra-Poisson variation, many unexplained zeros, or systematic changes in rate with exposure can signal that the specified conditional distribution or mean structure is inadequate. An offset does not by itself correct every form of model misspecification.

A frequent alternative is to use the raw count as the response but omit exposure. That model treats a count of 10 as comparable regardless of whether it came from 100 or 10,000 person-years, so it answers a different question and can confound rate differences with exposure differences. Modeling observed rates directly is also not automatically equivalent: rates can have very different precision at different denominators, and a Gaussian model may not respect the count-generating process. The offset retains the count response and incorporates exposure in the mean model.

Another possibility is to include \(\log(E_{ij})\) as an ordinary predictor with an estimated coefficient. That approach tests or estimates how expected counts scale with exposure; it does not impose proportional scaling. It is not a substitute for an offset when proportionality is substantively justified. Conversely, fixing the coefficient at one is restrictive: if the scientific question concerns departures from proportional scaling, an estimated exposure effect may be relevant, but its interpretation and assumptions must be considered explicitly.

Common pitfall: Do not calculate count divided by exposure and then fit a count model as though that rate were the count. Nor should you add raw exposure as an offset: the offset must be its logarithm. Use the count as the response and \(\log(E)\) as the known offset; then exponentiated fixed-effect coefficients describe modeled rate ratios.

In practical use, confirm the exact exposure column before fitting and check its minimum value. In R, a quick check is: all(is.finite(dat$person_years) & dat$person_years > 0). If this is false, determine why before modeling rather than silently adding a small constant to make the logarithm computable. A zero exposure typically means there was no opportunity to observe an event and needs substantive handling, not an arbitrary offset value.

Check Your Understanding

Answer each question, then compare your reasoning with the brief solutions.

  1. A fitted treatment coefficient is \(0.20\) in a Poisson GLMM with a log-person-time offset. What is the estimated conditional rate ratio?
  2. Why is a zero count acceptable in an offset model while zero exposure is not?
  3. An analyst uses an offset of \(\log(E)\) and changes all exposure values from years to days, with 365 days per year. What happens to the intercept, and why should fitted expected counts remain unchanged?
  4. What modeling constraint does the offset impose on expected counts when exposure doubles?

Solutions. (1) The rate ratio is \(\exp(0.20)\approx1.221\), so the modeled rate is about 1.22 times the comparison rate, conditional on the model terms. (2) A zero count is an observed outcome at positive opportunity; zero exposure makes \(\log(E)\) undefined and represents no observation opportunity. (3) The log offset increases by \(\log(365)\), so the intercept must decrease by \(\log(365)\) to preserve the linear predictor and fitted counts; the numerical rate unit changes from per year to per day. (4) Expected counts double, since \(\mu(2E)=2\mu(E)\) with other model terms held fixed.

Clinical Biostats