Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Encoding Irregular Visit Histories

Informative Observation Schedules · Tutorial 36 of 697

Encoding Irregular Visit Histories

Build a patient-level representation of irregular visit histories that keeps exact visit times, outcomes, intervals, and information available before each visit distinct.

Advanced 12 min read

What You'll Learn

  • Define a patient’s follow-up window and ordered visit history.
  • Represent visit times, measured outcomes, and inter-visit intervals consistently.
  • Record observed history using only information available by the relevant time.
  • Handle patients with no recorded visits without undefined interval endpoints.
  • Diagnose common errors in wide, long, and interval-based data structures.

Why Encoding Matters

In longitudinal follow-up, patients are not always measured at the same scheduled times. One patient may have visits on days 4, 15, and 39; another may have visits on days 10 and 41. A representation that stores only a sequence of outcome values loses the timing information that distinguishes these histories. Conversely, a list of visit times without the measurements and observed history available at those times is incomplete for many analyses.

The aim here is to construct a patient-level record that preserves four things: the follow-up window, each visit’s exact time, the outcome measured at that visit, and the time spans between visits. A separate history record can preserve observed covariates and prior measurements as they were known over time. This is a data-organization task, not a model for why visits occurred.

Definition: For patient \(i\), let \([a_i,b_i]\) denote the recorded follow-up window, and let \(m_i\) be the number of recorded visits in that window. Write the ordered visit times as \(t_{i1}<\cdots<t_{im_i}\), and let \(y_{ij}\) be the outcome measured at visit \(j\), when it was measured. The visit history is the collection of these times, measurements, and any time-stamped observed history linked to the patient. If \(m_i=0\), the visit-time and outcome lists are empty; the follow-up window is still recorded.

A Patient-Level Representation

A useful representation has a patient-level record plus linked visit-level and interval-level records. The patient-level record stores the patient identifier, the start and end of the follow-up window, the time unit, and the available information about whether that window is fully covered by the data. The visit-level record has one row per visit, with at least the patient identifier, visit index, visit time, and measured outcome. It can also include observed covariates measured at that visit.

The interval-level record makes the time between visits explicit. For \(m_i>0\), define the first segment as \([a_i,t_{i1}]\), the segment ending at visit \(j\) as \((t_{i,j-1},t_{ij}]\) for \(j=2,\ldots,m_i\), and the final segment as \((t_{im_i},b_i]\). For \(m_i=0\), the observed interval is \([a_i,b_i]\), with its coverage status recorded. This zero-visit case must be represented directly: there is no last visit time from which to define a final segment. The closed start endpoint is a bookkeeping convention; another endpoint convention is possible, but it must be used consistently.

These segments partition the recorded follow-up window under the stated convention. Each segment ending in a visit has no other recorded visit in its interior, and the final segment has no later recorded visit in the window. The segment ending at a visit includes that endpoint; it does not mean that a visit-free interval includes its endpoint. It is often helpful to store the segment start, segment end, elapsed duration, and whether the window is known to be covered through that end.

$$ d_{i1}=t_{i1}-a_i,\qquad d_{ij}=t_{ij}-t_{i,j-1}\ (j=2,\ldots,m_i),\qquad d_{i,m_i+1}=b_i-t_{im_i}\quad(m_i>0). $$

The durations are elapsed calendar time in the chosen units, such as days. When \(m_i=0\), the sole interval has duration \(b_i-a_i\). The time units and the meaning of the window endpoints should be stated in the data definition; otherwise a recorded gap such as “12” is ambiguous.

For observed history, a useful notation is \(H_i(t-)\): the recorded information for patient \(i\) available strictly before time \(t\). It may include baseline covariates, earlier measured outcomes, and time-stamped treatment history, provided those records genuinely precede \(t\). Store the original timestamped records, or an auditable summary linked to them, rather than attaching later information to an earlier visit. If two records share a timestamp and their order is unknown, retain that fact rather than imposing an invented sequence.

Worked Example: Encoding Visits and Their Gaps

Suppose a hypothetical patient has a recorded follow-up window from day 0 through day 40, known to be covered throughout. Visits occurred on days 6, 18, and 31, with biomarker values 8.4, 7.9, and 6.8 units, respectively. Encode the visit and interval history.

The visit-level rows are \((i,1,6,8.4)\), \((i,2,18,7.9)\), and \((i,3,31,6.8)\), where the columns are patient, visit index, day, and biomarker value. The visit times are ordered, and each outcome remains attached to its actual measurement time.

The interval durations are \(6-0=6\) days, \(18-6=12\) days, \(31-18=13\) days, and \(40-31=9\) days. Thus the interval records are \([0,6]\), \((6,18]\), \((18,31]\), and \((31,40]\), with durations 6, 12, 13, and 9 days. Their total is \(6+12+13+9=40\) days, matching the window length \(40-0=40\).

The record says that no other recorded visit occurred in the interiors of these segments. It does not supply an outcome value for every day within them. If the patient’s treatment changed on day 20, that change belongs in the time-stamped history: it is part of the history available before the day-31 visit, but not before the day-18 visit.

Worked Representations and Edge Cases

Worked Example: A Patient With No Recorded Visits

Consider a hypothetical patient whose data cover the window from day 3 to day 28, and for whom no visit was recorded. The patient record has \(a_i=3\), \(b_i=28\), and \(m_i=0\); the visit-time and outcome lists are empty.

There is one interval, \([3,28]\), with duration \(28-3=25\) days. Suppose the data source confirms coverage for the entire window. Record that coverage status with the interval. If coverage is known only through day 20, record the known coverage limit and do not label days 20 through 28 as confirmed visit-free follow-up. In either case, do not create a “last visit” field with a fabricated value, and do not try to calculate \(b_i-t_{im_i}\), because \(t_{im_i}\) does not exist when \(m_i=0\).

This record describes the observed visit history and its coverage. It does not by itself determine why no visit was recorded or what the unmeasured outcome would have been.

Worked Example: Keeping Observed History Time-Ordered

In a hypothetical record, a patient has a biomarker measurement of 5.2 units on day 8, begins a new treatment on day 13, and has a second biomarker measurement of 4.7 units on day 22. The window is day 0 through day 30, and coverage is complete.

The visit records are \((8,5.2)\) and \((22,4.7)\). The gap between visits is \(22-8=14\) days; the initial and final durations are \(8-0=8\) days and \(30-22=8\) days. The interval durations sum to \(8+14+8=30\) days.

The treatment change is a separate history record at day 13. Therefore, \(H_i(8-)\) does not include the treatment change, while \(H_i(22-)\) does. Attaching the day-13 treatment status to the day-8 visit would put later information into earlier history. Keeping the treatment timestamp separate allows an analyst to construct the observed history at the appropriate time without changing the original measurement record.

Why the Interval Construction Works

The interval representation is useful partly because it gives a simple consistency check. For \(m_i>0\), add the durations of the initial segment, all between-visit segments, and the final segment:

$$ (t_{i1}-a_i)+\sum_{j=2}^{m_i}(t_{ij}-t_{i,j-1})+(b_i-t_{im_i})=b_i-a_i. $$

Every intermediate visit time appears once with a positive sign and once with a negative sign, so those terms cancel. Only \(b_i-a_i\) remains. If \(m_i=0\), the total interval duration is \(b_i-a_i\) by direct definition. This identity justifies checking that the interval records cover exactly the stated window, without an unexplained gap or overlap in elapsed time.

1
Set the window.
Record the start and end times, their units, and what is known about data coverage over that span.
2
Order the visits.
For each patient, sort recorded visits by time and attach each measured outcome to its own visit time.
3
Build the intervals.
Use the visit-to-visit boundaries when \(m_i>0\); when \(m_i=0\), store the full window \([a_i,b_i]\) as the observed interval.
4
Link history without looking ahead.
Retain time-stamped covariates and use only information recorded before the time being described.
5
Check the encoding.
Verify visit order, outcome linkage, interval durations, window coverage, and the zero-visit case.

Choosing and Checking a Data Layout

A long visit table is usually a clear primary representation: one row per patient-visit pair, with exact times and outcomes. It accommodates unequal numbers of visits naturally and can be linked to a patient table and to time-stamped history records. A wide table, with columns such as “visit 1 outcome” and “visit 2 outcome,” can be convenient for a small fixed schedule, but irregular numbers and times of visits create many empty columns or risk hiding when measurements occurred. A compact patient-level vector of visit times and a matching vector of outcomes is also possible, provided their positions stay aligned and the interval information is recoverable.

Whichever layout is used, run basic diagnostics before analysis:

  • Check that each patient has one defined window and that every recorded visit lies within it.
  • Check that visit times are ordered and that visit indices agree with that order.
  • Check that every outcome is linked to the intended patient and visit, rather than matched by row position after sorting.
  • Recalculate all interval durations and verify that they sum to \(b_i-a_i\), including the \(m_i=0\) case.
  • Check whether equal timestamps represent duplicate records, multiple measurements at one encounter, or records whose order is unresolved; do not silently sort ties into a false sequence.
  • Record coverage limitations explicitly. A span with no recorded visit is not automatically evidence that data collection continued throughout that span.

A common mistake is to treat visit number as elapsed time—for example, to regard every “visit 2” as occurring at the same time for every patient. The correction is to retain actual timestamps and calculate gaps from them. Another mistake is to assume that an interval without recorded visits contains a known outcome trajectory. It contains no recorded visit in the represented span; the outcome between measurements is not supplied by this encoding.

This representation does not explain why observation schedules differ, and it does not resolve what unrecorded outcomes mean. It is a foundation for later analyses, not a substitute for specifying their assumptions. The introductory material on informative visit timing motivates why those differences can matter; the practical task here is to preserve enough detail that they are not erased by data processing.

Key takeaway: Keep the follow-up window, exact visit times, visit-specific measurements, inter-visit intervals, and time-ordered observed history linked but distinguishable. Always define the no-visit record explicitly: when \(m_i=0\), the interval is the full window \([a_i,b_i]\), with its coverage status recorded.

Check Your Understanding

Answer each question using the interval and history conventions defined above. Brief solutions follow.

  1. A patient is followed from day 2 to day 20 and has visits on days 5 and 14. What are the three interval durations?
  2. A patient has no recorded visits in a window from day 7 to day 19. What interval should be recorded, and what is its duration?
  3. Why should a treatment change recorded after a visit not be included in the observed history immediately before that visit?
  4. For a window from day 0 to day 24, visits on days 4, 11, and 20 produce interval durations 4, 7, 9, and 4 days. Check their total against the window length.
  5. What does a final interval with no recorded visit establish, and what does it not establish about the outcome?

Solutions. (1) The durations are \(5-2=3\), \(14-5=9\), and \(20-14=6\) days. (2) Record \([7,19]\), with duration \(19-7=12\) days, and attach the appropriate coverage status. (3) The history immediately before a visit must contain only information available before that time; including a later treatment change would introduce future information. (4) The sum is \(4+7+9+4=24\) days, equal to \(24-0\). (5) It establishes that no later visit was recorded in that represented span, subject to the recorded coverage status. It does not establish the patient’s unmeasured outcome during the span.

Clinical Biostats