Lexis.diagram: Plot a Lexis diagram

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Lexis.diagram.R

Description

Draws a Lexis diagram, optionally with life lines from a cohort, and with lifelines of a cohort if supplied. Intended for presentation purposes.

Usage

 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
Lexis.diagram( age = c( 0, 60), 
              alab = "Age",
              date = c( 1940, 2000 ),
              dlab = "Calendar time",
               int = 5,
           lab.int = 2*int, 
          col.life = "black",
          lwd.life = 2,
          age.grid = TRUE,
         date.grid = TRUE,
          coh.grid = FALSE,
          col.grid = gray(0.7),
          lwd.grid = 1,     
               las = 1,
        entry.date = NA,
         entry.age = NA,
         exit.date = NA,
          exit.age = NA,
         risk.time = NA,
        birth.date = NA,
              fail = NA,
          cex.fail = 1.1, 
          pch.fail = c(NA,16),
          col.fail = rep( col.life, 2 ),
              data = NULL, ... )

Arguments

age

Numerical vector of length 2, giving the age-range for the diagram

alab

Label on the age-axis.

date

Numerical vector of length 2, giving the calendar time-range for the diagram

dlab

label on the calendar time axis.

int

The interval between grid lines in the diagram. If a vector of length two is given, the first value will be used for spacing of age-grid and the second for spacing of the date grid.

lab.int

The interval between labelling of the grids.

col.life

Colour of the life lines.

lwd.life

Width of the life lines.

age.grid

Should grid lines be drawn for age?

date.grid

Should grid lines be drawn for date?

coh.grid

Should grid lines be drawn for birth cohorts (diagonals)?

col.grid

Colour of the grid lines.

lwd.grid

Width of the grid lines.

las

How are the axis labels plotted?

entry.date, entry.age, exit.date, exit.age, risk.time, birth.date

Numerical vectors defining lifelines to be plotted in the diagram. At least three must be given to produce lines. Not all subsets of three will suffice, the given subset has to define life lines. If insufficient data is given, no life lines are produced.

fail

Logical of event status at exit for the persons whose life lines are plotted.

pch.fail

Symbols at the end of the life lines for censorings (fail==0) and failures (fail != 0).

cex.fail

Expansion of the status marks at the end of life lines.

col.fail

Character vector of length 2 giving the colour of the failure marks for censorings and failures respectively.

data

Dataframe in which to interpret the arguments.

...

Arguments to be passed on to the initial call to plot.

Details

The default unit for supplied variables are (calendar) years. If any of the variables entry.date, exit.date or birth.date are of class "Date" or if any of the variables entry.age, exit.age or risk.time are of class "difftime", they will be converted to calendar years, and plotted correctly in the diagram. The returned dataframe will then have colums of classes "Date" and "difftime".

Value

If sufficient information on lifelines is given, a data frame with one row per person and columns with entry ages and dates, birth date, risk time and status filled in.

Side effect: a plot of a Lexis diagram is produced with the life lines in it is produced. This will be the main reason for using the function. If the primary aim is to illustrate follow-up of a cohort, then it is better to represent the follow-up in a Lexis object, and use the generic plot.Lexis function.

Author(s)

Bendix Carstensen, http://BendixCarstensen.com

See Also

Life.lines, Lexis.lines

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Lexis.diagram( entry.age = c(3,30,45),
               risk.time = c(25,5,14),
              birth.date = c(1970,1931,1925.7),
                    fail = c(TRUE,TRUE,FALSE) )
LL <- Lexis.diagram( entry.age = sample( 0:50, 17, replace=TRUE ),
                     risk.time = sample( 5:40, 17, r=TRUE),
                    birth.date = sample( 1910:1980, 17, r=TRUE ),
          		  fail = sample( 0:1, 17, r=TRUE ), 
	              cex.fail = 1.1,
	              lwd.life = 2 )
# Identify the persons' entry and exits
text( LL$exit.date, LL$exit.age, paste(1:nrow(LL)), col="red", font=2, adj=c(0,1) )
text( LL$entry.date, LL$entry.age, paste(1:nrow(LL)), col="blue", font=2, adj=c(1,0) )
data( nickel )
attach( nickel )
LL <- Lexis.diagram( age=c(10,100), date=c(1900,1990), 
	             entry.age=age1st, exit.age=ageout, birth.date=dob, 
		     fail=(icd %in% c(162,163)), lwd.life=1,
		     cex.fail=0.8, col.fail=c("green","red") )
abline( v=1934, col="blue" )
nickel[1:10,]
LL[1:10,]

Example output

Attaching package: 'Epi'

The following object is masked from 'package:base':

    merge.data.frame

   id icd exposure      dob  age1st   agein  ageout
1   3   0      5.0 1889.019 17.4808 45.2273 92.9808
2   4 162      5.0 1885.978 23.1864 48.2684 63.2712
3   6 163     10.0 1881.255 25.2452 52.9917 54.1644
4   8 527      9.0 1886.340 24.7206 47.9067 69.6794
5   9 150      0.0 1879.500 29.9575 54.7465 76.8442
6  10 163      2.0 1889.915 21.2877 44.3314 62.5413
7  15 334      0.0 1890.500 23.2836 43.7465 62.0000
8  16 160      0.5 1874.332 50.3569 59.9149 65.5835
9  17 420      0.0 1909.500 15.4618 34.7465 50.5137
10 18  12      0.0 1892.500 24.1394 51.7465 57.5931
   entry.date entry.age exit.date exit.age birth.date risk.time  fail
1    1906.500   17.4808  1982.000  92.9808   1889.019   75.5000 FALSE
2    1909.164   23.1864  1949.249  63.2712   1885.978   40.0848  TRUE
3    1906.500   25.2452  1935.419  54.1644   1881.255   28.9192  TRUE
4    1911.060   24.7206  1956.019  69.6794   1886.340   44.9588 FALSE
5    1909.457   29.9575  1956.344  76.8442   1879.500   46.8867 FALSE
6    1911.203   21.2877  1952.456  62.5413   1889.915   41.2536  TRUE
7    1913.784   23.2836  1952.500  62.0000   1890.500   38.7164 FALSE
8    1924.688   50.3569  1939.915  65.5835   1874.332   15.2266 FALSE
9    1924.962   15.4618  1960.014  50.5137   1909.500   35.0519 FALSE
10   1916.639   24.1394  1950.093  57.5931   1892.500   33.4537 FALSE

Epi documentation built on May 31, 2017, 5:15 a.m.

Search within the Epi package
Search all R packages, documentation and source code