Create an object of class
Lexis to represent follow-up in
multiple states on multiple time scales.
a named list of entry times. Each element of the list is
a numeric variable representing the entry time on the named time
scale. All time scales must have the same units (e.g. years).
The names of the timescales must be different from any column name in
a named list of exit times.
a numeric vector giving the duration of follow-up.
a vector or a factor giving the status at entry
a vector or factor giving status at exit. Any change in status during follow-up is assumed to take place exactly at the exit time.
a vector giving a unique identity value for each person
represented in the Lexis object. Defaults to
an optional data frame, list, or environment containing
the variables. If not found in
a logical flag. If
A vector of labels for the states. If given, the state
Numerical tolerance for follow-up time. Rows with duration less than this value are automatically dropped.
Logical. Should dropped rows from
The analysis of long-term population-based follow-up studies typically
requires multiple time scales to be taken into account, such as
age, calender time, or time since an event. A
Lexis object is
a data frame with additional attributes that allows these multiple time
dimensions of follow-up to be managed.
Separate variables for current end exit state allows representation of multistate data.
Lexis objects are named after the German demographer Wilhelm Lexis (1837-1914), who is credited with the invention of the "Lexis diagram" for representing population dynamics simultaneously by several timescales.
Lexis function can create a minimal
with only those variables required to define the follow-up history in
each row. Additional variables can be merged into the
object using the
merge method for
Lexis objects. The
latter is the default.
There are also
transform methods for
Lexis objects. They work as the corresponding methods for data-frames
but ensures that the result is a
An object of class
Lexis. This is represented as a data frame
with a column for each time scale (with neaes equal to the union of
the names of
exit), and additional columns with the
Identification of the persons.
Duration of follow-up.
Entry status (
Exit status (e
merge=TRUE (the default) then the
Lexis object will also contain
all variables from the
Only two of the three arguments
duration need to be given. If the third parameter is missing,
it is imputed.
exit must be numeric, using
variables will cause some of the utilites to crash. Transformation by
cal.yr is recommended.
If only either
duration are supplied it is assumed that
entry is 0. This is only meaningful (and therefore checked) if there
is only one timescale.
If any of
exit.status are of mode character,
they will both be converted to factors.
entry.status is not given, then its class is automatically
set to that of
exit.status is a
character or factor, the value of
entry.status is set to the
first level. This may be highly undesirable, and therefore noted. For
exit.status is character the first level will be
the first in the alphabetical ordering; slightly unfortunate if values
exit.status is logical, the
entry.status set to
exit.status is numeric, the value of
entry.status set to
exit.status are factors or character,
the corresponding state variables in the returned
lex.Xst will be (unordered) factors with
identical set of levels, namely the union of the levels of
Martyn Plummer with contributions from Bendix Carstensen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# A small bogus cohort xcoh <- structure( list( id = c("A", "B", "C"), birth = c("14/07/1952", "01/04/1954", "10/06/1987"), entry = c("04/08/1965", "08/09/1972", "23/12/1991"), exit = c("27/06/1997", "23/05/1995", "24/07/1998"), fail = c(1, 0, 1) ), .Names = c("id", "birth", "entry", "exit", "fail"), row.names = c("1", "2", "3"), class = "data.frame" ) # Convert the character dates into numerical variables (fractional years) xcoh <- cal.yr( xcoh, format="%d/%m/%Y", wh=2:4 ) # See how it looks xcoh str( xcoh ) # Define as Lexis object with timescales calendar time and age Lcoh <- Lexis( entry = list( per=entry ), exit = list( per=exit, age=exit-birth ), exit.status = fail, data = xcoh ) Lcoh # Using character states may have undesired effects: xcoh$Fail <- c("Dead","Well","Dead") Lexis( entry = list( per=entry ), exit = list( per=exit, age=exit-birth ), exit.status = Fail, data = xcoh ) # ...unless you order the levels correctly ( xcoh$Fail <- factor( xcoh$Fail, levels=c("Well","Dead") ) ) Lexis( entry = list( per=entry ), exit = list( per=exit, age=exit-birth ), exit.status = Fail, data = xcoh )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.