Tutorials › Nonlinear Mixed-Effects Models (NLME) › Longitudinal Count Modeling With Changing Exposure

Categorical, Count and Time-to-Event Responses · Tutorial 439 of 797

Longitudinal Count Modeling With Changing Exposure

Build and interpret longitudinal count models that account for changing exposure without confusing longer observation with a higher event rate.

Advanced 11 min read

What You'll Learn

  • Define interval-specific exposure and construct its log offset in a repeated-count model.
  • State the conditional assumptions behind a Poisson mixed-effects model with changing exposure.
  • Interpret covariate effects as rate ratios while keeping exposure duration separate.
  • Calculate fitted counts and observed rates for intervals of different lengths.
  • Recognize zero-exposure intervals and within-interval changes that invalidate a simple offset.
  • Diagnose common failures and compare offsets with alternative exposure handling.

Why Changing Exposure Needs Special Treatment

A count is partly determined by how long, or how much, an event could occur. A patient observed for ten days has more opportunity to experience episodes than a patient observed for two days, even if their event rates are identical. Comparing their raw counts as if the observation periods were equal can therefore confuse duration of exposure with event intensity.

In longitudinal data, exposure can change from one interval to another for the same subject. A patient may contribute a full week in one interval and only three days in another, or may be at risk for an event during only part of a visit interval. The model must pair each count with the exposure that generated its opportunity. Time-varying covariates also need to be aligned to those intervals: a covariate value for one interval should describe the conditions under which that interval's count accumulated.

The key construction is an interval-specific offset. It enters the log-mean model with its coefficient fixed at one, so doubling exposure doubles the expected count while leaving the modeled rate unchanged.

Definition: Let \(Y_{ij}\) be the event count for subject \(i\) during interval \(j\), and let \(E_{ij}>0\) be the corresponding exposure, measured in a stated unit such as person-days. An exposure offset is the known quantity \(\log(E_{ij})\) included in a log-mean model with coefficient fixed at one. It adjusts the expected count for the amount of event opportunity represented by that interval.

Model and Assumptions

A basic longitudinal model uses a Poisson distribution conditional on subject-specific random effects and the covariates. For a random-intercept model, write

$$ Y_{ij}\mid b_i \sim \operatorname{Poisson}(\mu_{ij}), \qquad \log(\mu_{ij})=\log(E_{ij})+\beta_0+\boldsymbol{\beta}^{\mathsf T}\mathbf{x}_{ij}+b_i, \qquad b_i\sim N(0,\omega^2). $$

Here \(\mathbf{x}_{ij}\) contains covariates applying to subject \(i\) during interval \(j\), \(\boldsymbol{\beta}\) contains their fixed-effect coefficients, and \(b_i\) is a subject-specific deviation in log rate. Conditional on \(b_i\), the rate is

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

This decomposition separates the interval's exposure from its rate. For example, changing \(E_{ij}\) from two to four days doubles \(\mu_{ij}\) if the covariates and random effect are unchanged; it does not change \(r_{ij}\). A coefficient \(\beta_k\) for a one-unit increase in covariate \(x_k\) gives the conditional rate ratio \(\exp(\beta_k)\), holding exposure and the other modeled quantities fixed.

The model relies on several substantive conditions. Counts must be nonnegative integers that refer to clearly defined events, and exposure must measure the time or opportunity during which those events could occur. The exposure value and the covariates must correspond to the same interval as the count. Conditional on the random effect and covariates, the Poisson specification assumes the count mean equals its variance and that interval counts are independent. The shared random effect can induce dependence among a subject's repeated counts, but it does not automatically represent every possible serial pattern.

The simple product \(E_{ij}r_{ij}\) assumes the modeled rate is constant over the interval, conditional on the specified covariates and random effects. If the rate changes materially within an interval, the expected count is instead an integrated rate:

$$ \mu_{ij}=\int_{a_{ij}}^{b_{ij}} r_i(t)\,dt. $$

In that situation, use shorter intervals with appropriately updated covariates, or calculate the integral under a model for the changing rate. A single offset multiplied by one rate is not generally exact when the rate varies within the interval.

Why the Offset Has Coefficient One

The offset follows directly from expressing a rate model as a count model. Suppose the conditional rate is \(r_{ij}=\exp(\eta_{ij})\), where \(\eta_{ij}=\beta_0+\boldsymbol{\beta}^{\mathsf T}\mathbf{x}_{ij}+b_i\). Over exposure \(E_{ij}\), the expected count is \(\mu_{ij}=E_{ij}r_{ij}\). Taking logarithms gives

$$ \log(\mu_{ij})=\log(E_{ij})+\log(r_{ij}) =\log(E_{ij})+\eta_{ij}. $$

Thus \(\log(E_{ij})\) enters additively with coefficient one because exposure multiplies the rate on the count scale. Estimating a separate coefficient for \(\log(E_{ij})\) would change the assumption: a coefficient other than one implies that doubling exposure does not exactly double the expected count. That may be investigated as a different model when scientifically justified, but it is not the standard offset adjustment.

Worked Example: Different Durations, Same Event Rate

Suppose two hypothetical observation intervals have the same modeled event rate, 1.2 episodes per day. The first interval has four days of exposure and records five episodes; the second has two days and records two episodes. Compare their expected counts and observed rates.

For the first interval, the modeled expected count is \(4\text{ days}\times1.2\text{ episodes/day}=4.8\) episodes. Its observed rate is \(5/4=1.25\) episodes per day.

For the second interval, the expected count is \(2\text{ days}\times1.2\text{ episodes/day}=2.4\) episodes. Its observed rate is \(2/2=1.00\) episode per day.

The expected count is twice as large in the four-day interval because its exposure is twice as long, not because the modeled rate is higher. The observed rates differ because realized counts vary around their expected values; these two intervals alone do not establish a difference in underlying rates.

Time-Varying Covariates and Interval-Specific Offsets

A covariate that changes over time belongs in the interval-specific predictor. For example, if a treatment indicator or dose category can change between visits, use the value applying during each count interval rather than assigning one value to the entire subject. The offset and the covariates do different jobs: \(\log(E_{ij})\) represents the amount of opportunity, while covariates describe factors that may change the rate per unit of opportunity.

Worked Example: Interpreting a Time-Varying Rate Effect

Consider a hypothetical fitted model with baseline rate \(0.8\) episodes per day and a binary interval-specific covariate \(x_{ij}\). Let its coefficient be \(\beta_1=\log(1.5)\), so the rate is multiplied by 1.5 when \(x_{ij}=1\). Assume the subject-specific random effect is zero for these predictions.

When \(x_{ij}=0\), the rate is \(0.8\) episodes per day. Over two days, the expected count is \(2\times0.8=1.6\) episodes. When \(x_{ij}=1\), the rate is \(0.8\times1.5=1.2\) episodes per day. Over the same two days, the expected count is \(2\times1.2=2.4\) episodes.

If \(x_{ij}=1\) instead applies over five days, the expected count is \(5\times1.2=6.0\) episodes. The increase from 2.4 to 6.0 is due to longer exposure; the rate ratio comparing \(x=1\) with \(x=0\) remains \(1.5\), not \(6.0/1.6\). That latter count ratio compares different exposure durations as well as different covariate values.

The interpretation is conditional on the model and the other quantities held fixed: intervals with \(x=1\) have a modeled event rate 1.5 times the rate for \(x=0\). It is not a claim that the covariate caused the rate difference.

If a covariate varies within an interval, a single interval-level value may be inadequate. For instance, a rate multiplier that is two for the first half of an interval and one for the second half cannot generally be represented by multiplying the total duration by the rate multiplier at the midpoint. The expected count must account for the separate portions, or the data should be divided at the covariate change. When the rate is piecewise constant, this is a sum of exposure-times-rate contributions across pieces.

Worked Example: Splitting an Interval at a Covariate Change

A hypothetical subject contributes a four-day interval. The baseline rate is \(0.5\) events per day, and a covariate doubles the rate during the final two days but is absent during the first two days. Assume a zero random effect.

During the first two days, the expected count is \(2\times0.5=1.0\) event. During the final two days, the rate is \(0.5\times2=1.0\) event per day, so the expected count is \(2\times1.0=2.0\) events. The total expected count is \(1.0+2.0=3.0\) events.

Equivalently, splitting the interval produces two contributions with distinct covariate values. Treating the whole four days as exposed to the elevated rate would predict \(4\times1.0=4.0\) events and overstate the mean. Treating the whole interval as unexposed would predict \(4\times0.5=2.0\) events and understate it.

Practical Construction and Diagnostics

Before fitting the model, create one record for each subject-interval and verify that its count, exposure, and covariate values refer to the same period. State the exposure unit explicitly; person-days, person-weeks, and hours are not interchangeable without conversion. Changing the unit changes the intercept's numerical value but, when the conversion is constant, does not change rate ratios for covariates.

An interval with \(E_{ij}=0\) has no defined \(\log(E_{ij})\). It should not be handled by adding an arbitrary small constant. If there was truly no opportunity for the event, a positive count is inconsistent with that exposure definition and should prompt data review. A zero-exposure interval with a zero count contributes no event-rate information under this model and is generally omitted from its count likelihood. If exposure is missing rather than zero, it must not be silently treated as zero.

Useful checks include inspecting exposure distributions by subject and interval, verifying that intervals neither overlap nor leave unrecorded gaps that matter to the question, and plotting counts against exposure. Counts will often rise with exposure even when rates do not. Also examine observed rates \(Y_{ij}/E_{ij}\) with care: they can be highly variable for short exposures and are undefined at zero exposure. Compare observed and model-predicted counts across exposure ranges and covariate patterns. Remaining subject-level clustering, systematic time patterns, or variance substantially exceeding the Poisson mean can indicate that the assumed random-effects or count distribution is inadequate. The earlier material on count dispersion and excess zeros gives further context for those diagnostics.

ApproachWhat it impliesMain caution
Log-exposure offsetExpected count is exposure multiplied by the modeled rate; exposure coefficient is fixed at one.Requires exposure to represent event opportunity and the rate structure to be appropriate.
Raw count with no exposure termIntervals are treated as comparable in opportunity unless exposure is otherwise identical.Can mistake longer observation for a higher rate.
Log exposure as an estimated predictorExposure is allowed to have a fitted coefficient rather than the fixed value one.It no longer imposes proportional scaling of expected counts with exposure; needs a scientific rationale.
Observed rate as the responseModels count divided by exposure directly.Rates have different precision at different exposures and are not generally Poisson counts.

The offset is therefore not merely a data-format adjustment. It states a proportionality assumption about how opportunity accumulates. If that assumption is implausible, changing the offset mechanically will not solve the problem; the exposure definition, time partition, or rate model needs reconsideration. Likewise, the random intercept accounts for persistent subject-level differences in rates, but it does not guarantee that a Poisson variance is sufficient or that all temporal dependence has been captured.

Common Mistakes

  • Comparing raw counts across unequal durations. A count of six over six days is not necessarily a higher rate than a count of three over two days. Compare modeled rates or account for duration with the offset.
  • Putting duration in as an ordinary covariate by default. The standard offset fixes the coefficient of \(\log(E_{ij})\) at one; it is not a freely estimated duration effect.
  • Using one exposure value for all intervals. Each count needs the exposure that corresponds to its own interval.
  • Using an interval average when the covariate changes sharply. If rates differ across portions of an interval, split the interval or model the integrated rate.
  • Adding a small number to zero exposure. This creates an arbitrary offset rather than a meaningful opportunity measure. Investigate the data and the event definition instead.
Key takeaway: In a longitudinal count model, the offset \(\log(E_{ij})\) adjusts each interval's expected count for its exposure, while time-varying covariates model changes in rate. Correct interpretation depends on matching counts, exposure, and covariates to the same interval.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A model has a rate of \(0.4\) events per hour. What is the expected count over 10 hours, and what is the expected count over 5 hours if all rate predictors remain unchanged?
  2. A covariate coefficient is \(\log(0.75)\). Interpret its rate ratio, assuming the other predictors and exposure are held fixed.
  3. A count interval has 12 events over 6 person-days. Another has 10 events over 3 person-days. Calculate both observed rates and explain why the larger count does not imply a larger observed rate.
  4. A covariate doubles the rate during only the final day of a three-day interval. The baseline rate is 2 events per day. Find the total expected count by splitting the interval.

Solutions. (1) The means are \(10\times0.4=4.0\) events and \(5\times0.4=2.0\) events; the longer exposure doubles the expected count. (2) The rate ratio is \(\exp(\log(0.75))=0.75\), so the modeled rate is 25% lower for a one-unit increase in the covariate, conditional on the other model quantities. (3) The observed rates are \(12/6=2.0\) events per person-day and \(10/3=3.33\) events per person-day. The interval with fewer events has the higher observed rate because its exposure is shorter. (4) The first two days contribute \(2\times2=4\) expected events; the final day has rate \(2\times2=4\) events per day and contributes 4 more. The total expected count is \(4+4=8\) events.