Lexis : An R Class for Epidemiological Studies with Long-Term Follow-Up

The Lexis class in the R package Epi provides an object-based framework for managing follow-up time on multiple time scales, which is an important feature of prospective epidemiological studies with long duration. Follow-up time may be split either into fixed time bands, or on individual event times and the split data may be used in Poisson regression models that account for the evolution of disease risk on multiple time scales. The summary and plot methods for Lexis objects allow inspection of the follow-up times.


Introduction
Prospective epidemiological studies follow a cohort of individuals until disease occurrence or death, or until the scheduled end of follow-up.The data for each participant in a cohort study must include three variables: time of entry, time of exit and status at exit.In the R language (R Development Core Team 2010), working with such data is made easy by the Surv class in the survival package (Therneau and Lumley 2010).The survival package also provides modelling functions that use Surv objects as outcome variables, and use the standard S syntax for model formulae.
In epidemiological studies with long-term follow-up, there may be more than one time scale of interest.If follow-up time is measured in decades, for example, any analysis of disease risk must take account of the impact of the ageing of the population.In this case, "calendar time" and "age" are both time scales of interest.A time scale may also measure the time elapsed since an important event, such as study entry, first exposure to a risk factor or beginning of treatment.The statistical problem of accounting for multiple time scales can be addressed using tools developed in the field of demography in the 19th century.Such tools are also used in descriptive epidemiology to separate time trends in chronic disease incidence rates into age, period and cohort effects.The increasing number of large population-based cohort studies with long-term follow-up has created a demand for these tools in analytical epidemiology.
The Epi (Carstensen, Plummer, Laara, and Hills 2010) package contains functions and classes to facilitate the analysis of epidemiological studies in R.Among these, the Lexis class was designed to simplify the analysis of long term follow-up studies by tracking follow-up time on multiple time scales.It also accounts for many possible disease outcomes by having a status variable that is not a simple binary indicator (alive/dead or healthy/diseased) but may take multiple values.

Lexis diagrams and Lexis objects
Figure 1 shows a simple example of a Lexis diagram, named after the demographer Wilhelm Lexis (1837Lexis ( -1914)).Each line in a Lexis diagram represents the follow-up of a single individual from entry to exit on two time scales: age and calendar time.Both time scales are measured in the same units (years) so that the follow-up traces a line at 45 degrees.Exit status is denoted by a circle for the 4 subjects who experienced a disease event.The other subjects are disease-free at the end of follow-up.
The follow-up line of an individual in a Lexis diagram is defined by his or her entry time on the two time scales of interest (age and calendar time) and the duration of follow up.The Lexis class formalises this representation of follow-up in an R object.Lexis objects are not limited to 2 time scales, but allow follow-up time to be tracked on an arbitrary number of time scales.The only restriction is that time scales must be measured in the same units.
To illustrate Lexis objects, we use a cohort of nickel smelting workers in South Wales (Doll, Mathews, and Morgan 1977), which was included as an example by Breslow and Day (1987).
The data from this study are contained in the data set nickel in the Epi package.
R> data("nickel") R> nicL <-Lexis(entry = list("period" = agein + dob, "age" = agein, + "tfe" = agein -age1st), exit = list("age" = ageout), exit.status= icd, + id = id, data = nickel) Follow-up time is defined by entry, a named list of entry times on each time scale, and exit, another named list of exit times.Since duration of follow-up is the same on all time scales, it is only necessary to define the exit time on one of them, in this case age.
The three time scales in this Lexis object are: period, representing calendar time.Date of entry is calculated as date of birth (dob) plus age at entry (agein).
tfe, representing time since first employment, which is used as a proxy for first exposure.Entry time on this scale is calculated as the difference between age at entry and age at first employment (age1st).
The exit.status argument gives the individual's status at the end of follow-up.Since this is a study of mortality, the exit status is the cause of death according to the Seventh Revision of the International Classification of Diseases (ICD, World Health Organization 1957).For individuals who were still alive at the end of follow-up, the exit status is 0.
The data argument gives a data frame that is the source of all the variables used to define entry time, exit time, status, and so on.The Lexis function transforms this data frame into a Lexis object.

Plotting Lexis objects
Not surprisingly, the plot method for Lexis objects plots a Lexis diagram.Figure 2 shows a Lexis diagram for the nickel smelters cohort.The points method is used to annotate the Lexis diagram with the times of all deaths from lung cancer (ICD code 162 or 163): R> plot(nicL) R> case <-status(nicL) %in% c(162,163) R> points(subset(nicL, case), pch = "+", col = "red") This example also illustrates the extractor function status, which returns the status at the beginning or (by default) end of each follow-up period.Other extractor functions dur, entry, and exit return respectively the duration of follow-up and the entry and exit times on any given time scale.
By default, the plot method chooses the first two time scales of the Lexis object to plot.
Other time scales may be chosen using the argument time.scale.A single time scale may be specified: R> plot(nicL, time.scale= "tfe", + xlab = "Time since first employment (years)") This produces Figure 3, in which the y-axis is the unique id number and all history lines are horizontal.Such plots may reveal important features of the data.For example, Figure 3 shows that, on the "tfe" time scale, there are many late entries into the study with some participants entering over 20 years after first employment.Due to the method of selection for this cohort, no participant came under observation until 1934, even if they had been working many years in the smelting industry (Breslow and Day 1987).

Structure of a Lexis object
Lexis objects inherit from the class data.frame.The Lexis object contains all the variables in the source data frame that was given as the data argument to the Lexis function.In this example, the first 3 variables (period, age, and tfe) show the entry times on the 3 time scales.The variable lex.dur shows the duration, lex.Cst and lex.Xst show the current status and exit status respectively, and lex.id shows the unique identifier for each individual.

Splitting follow-up time
The This creates a simple Lexis object with only one row.The object may be split into separate time bands using the splitLexis function: R> lx <-splitLexis (lx, breaks=c(1955, 1960, 1965, 1970) Splitting the follow-up time by 5-year calendar periods creates a new Lexis object with 3 rows.The total follow-up time of 11.12 years is divided up into 3 periods of 3.97+5.00+2.15= 11.12 years.A second call to splitLexis may be used to split the follow-up time along the age axis.
R> lx <-splitLexis (lx, breaks=c(40, 45, 50, 55)  The follow-up time is now divided into the 5 separate parts falling in different time bands defined by age and calendar time.Under the Poisson model, these separate follow-up periods make independent contributions to the likelihood and may therefore be treated as if they come from separate individuals (although, if needed, the lex.id variable keeps track of split follow-up times that come from the same individual).
This simple example also shows what happens to the entry and exit status when follow-up time is split.It is assumed that an individual keeps their current status (entry status = 0) at each splitting time until the end of follow-up (exit status = 1) in the last interval.
A call to the plot method for Lexis objects creates the plot shown in Figure 4. R> plot(lx, xlim = c(1955, 1971), ylim = c(40, 56), pty = "s", + xlab = "Calendar year of follow-up", + ylab = "Age at follow-up (years)") R> points(lx) When a split Lexis object is plotted, the break points are shown as a background grid.The points method annotates the end of each follow-up segment with a circle, showing how the follow-up line is split whenever it crosses either a horizontal or a vertical grid line.
The summary output also shows that the Lexis object has data on 2468 persons instead of the 2470 in the original object.In fact the 2 individuals who were dropped have no follow-up time in the study: their exit date is the same as the entry date.The cutLexis function automatically drops follow-up intervals with zero length.
Survival from liver cancer can be analyzed by selecting only the rows of the Lexis object that represent follow-up after diagnosis, when the participant is in state 4.
R> cases <-subset(thoroL2, status(thoroL2, at = "entry") == 4) R> plot(cases, col = "red") The results are shown in Figure 5. Survival from liver cancer in this cohort is very short, except for one case who survives more than 10 years after diagnosis.Such an anomalous result may prompt further checking of the data to ensure that the date of diagnosis or date of death had not been mis-coded.
The same technique of splitting follow-up by event times can also be applied to multi-state disease models, in which arbitrarily complex transitions between disease states are possible.The additional machinery in the Epi package to handle this more complex situation is the subject of a companion paper (Carstensen and Plummer 2011).

Figure 1 :
Figure 1: A simple example of a Lexis diagram showing schematically the follow-up of 13 individuals.

Figure 2 :
Figure 2: Lexis diagram of the nickel smelters cohort.

Figure 3 :
Figure 3: Schematic representation of follow-up in the nickel smelters cohort.

Figure 4 :
Figure 4: Lexis diagram showing the follow-up of one person in a cohort study.
In addition, a variable is created for each time scale as well as a four variables with reserved names starting with lex.(lex.dur,lex.Cst, lex.Xst, and lex.id).
Breslow and Day (1987)ds model, which is the most commonly used model for timeto-event data in epidemiology, does not generalize to more than one time scale.A simpler parametric alternative is to use Poisson regression with a piecewise-constant hazard.In typical applications of Poisson regression the hazard is constant within time bands defined by 5-year periods of age or calendar year.A single individual may pass through several time bands as shown by Figure4which shows the follow-up of a single hypothetical individual and reproduces Figure2.1 ofBreslow and Day (1987).The individual represented in this Lexis diagram passes through 5 time bands before the end of follow-up.The total follow-up time is created by a call to the Lexis function: Factors are labelled in the same way as for the cut function, as can be seen from the selected output for subject 8.Since no deaths occur from lung cancer before age 40 in this cohort, we have removed the lowest level of the age factor from the model using the subset argument to the glm function.