splitLexis: Split follow-up time in a Lexis object

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

View source: R/splitLexis.R

Description

The splitLexis function divides each row of a Lexis object into disjoint follow-up intervals according to the supplied break points.

Usage

1
splitLexis(lex, breaks, time.scale, tol=.Machine$double.eps^0.5)

Arguments

lex

an object of class Lexis

breaks

a vector of break points

time.scale

the name or number of the time scale to be split

tol

numeric value >= 0. Intervals shorter than this value are dropped

Value

An object of class Lexis with multiple rows for each row of the argument lex. Each row of the new Lexis object contains the part of the follow-up interval that falls inside one of the time bands defined by the break points.

The variables representing the various time scales, are appropriately updated in the new Lexis object. The entry and exit status variables are also updated according to the rule that the entry status is retained until the end of follow-up. All other variables are considered to represent variables that are constant in time, and so are replicated across all rows having the same id value.

Note

The splitLexis() function divides follow-up time into intervals using breakpoints that are common to all rows of the Lexis object. To split a Lexis object by break points that are unique to each row, use the cut.Lexis function.

Author(s)

Martyn Plummer

See Also

timeBand, cutLexis, mcutLexis, summary.Lexis

Examples

 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
37
38
39
40
41
42
43
44
45
46
47
# 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$bt <- cal.yr( xcoh$birth, format="%d/%m/%Y" )
xcoh$en <- cal.yr( xcoh$entry, format="%d/%m/%Y" )
xcoh$ex <- cal.yr( xcoh$exit , format="%d/%m/%Y" )

# See how it looks
xcoh

# Define as Lexis object with timescales calendar time and age
Lcoh <- Lexis( entry = list( per=en ),
                exit = list( per=ex, age=ex-bt ),
         exit.status = fail,
                data = xcoh )

# Default plot of follow-up
plot( Lcoh )

# With a grid and deaths as endpoints
plot( Lcoh, grid=0:10*10, col="black" )
points( Lcoh, pch=c(NA,16)[Lcoh$lex.Xst+1] )

# With a lot of bells and whistles:
plot( Lcoh, grid=0:20*5, col="black", xaxs="i", yaxs="i",
      xlim=c(1960,2010), ylim=c(0,50), lwd=3, las=1 )
points( Lcoh, pch=c(NA,16)[Lcoh$lex.Xst+1], col="red", cex=1.5 )

# Split time along two time-axes
( x2 <- splitLexis( Lcoh, breaks = seq(1900,2000,5), time.scale="per") )
( x2 <- splitLexis( x2, breaks = seq(0,80,5), time.scale="age" ) )
str( x2 )

# Tabulate the cases and the person-years
summary( x2 )
tapply( status(x2,"exit")==1, list( timeBand(x2,"age","left"),
                                    timeBand(x2,"per","left") ), sum )
tapply( dur(x2),  list( timeBand(x2,"age","left"),
                        timeBand(x2,"per","left") ), sum )

Example output

Attaching package: 'Epi'

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

    merge.data.frame

  id      birth      entry       exit fail       bt       en       ex
1  A 14/07/1952 04/08/1965 27/06/1997    1 1952.533 1965.589 1997.485
2  B 01/04/1954 08/09/1972 23/05/1995    0 1954.246 1972.686 1995.388
3  C 10/06/1987 23/12/1991 24/07/1998    1 1987.437 1991.974 1998.559
   lex.id      per       age   lex.dur lex.Cst lex.Xst id      birth      entry
1       1 1965.589 13.056810 4.4106776       0       0  A 14/07/1952 04/08/1965
2       1 1970.000 17.467488 5.0000000       0       0  A 14/07/1952 04/08/1965
3       1 1975.000 22.467488 5.0000000       0       0  A 14/07/1952 04/08/1965
4       1 1980.000 27.467488 5.0000000       0       0  A 14/07/1952 04/08/1965
5       1 1985.000 32.467488 5.0000000       0       0  A 14/07/1952 04/08/1965
6       1 1990.000 37.467488 5.0000000       0       0  A 14/07/1952 04/08/1965
7       1 1995.000 42.467488 2.4852841       0       1  A 14/07/1952 04/08/1965
8       2 1972.686 18.439425 2.3141684       0       0  B 01/04/1954 08/09/1972
9       2 1975.000 20.753593 5.0000000       0       0  B 01/04/1954 08/09/1972
10      2 1980.000 25.753593 5.0000000       0       0  B 01/04/1954 08/09/1972
11      2 1985.000 30.753593 5.0000000       0       0  B 01/04/1954 08/09/1972
12      2 1990.000 35.753593 5.0000000       0       0  B 01/04/1954 08/09/1972
13      2 1995.000 40.753593 0.3880903       0       0  B 01/04/1954 08/09/1972
14      3 1991.974  4.536619 3.0260096       0       0  C 10/06/1987 23/12/1991
15      3 1995.000  7.562628 3.5585216       0       1  C 10/06/1987 23/12/1991
         exit fail       bt       en       ex
1  27/06/1997    1 1952.533 1965.589 1997.485
2  27/06/1997    1 1952.533 1965.589 1997.485
3  27/06/1997    1 1952.533 1965.589 1997.485
4  27/06/1997    1 1952.533 1965.589 1997.485
5  27/06/1997    1 1952.533 1965.589 1997.485
6  27/06/1997    1 1952.533 1965.589 1997.485
7  27/06/1997    1 1952.533 1965.589 1997.485
8  23/05/1995    0 1954.246 1972.686 1995.388
9  23/05/1995    0 1954.246 1972.686 1995.388
10 23/05/1995    0 1954.246 1972.686 1995.388
11 23/05/1995    0 1954.246 1972.686 1995.388
12 23/05/1995    0 1954.246 1972.686 1995.388
13 23/05/1995    0 1954.246 1972.686 1995.388
14 24/07/1998    1 1987.437 1991.974 1998.559
15 24/07/1998    1 1987.437 1991.974 1998.559
   lex.id      per       age   lex.dur lex.Cst lex.Xst id      birth      entry
1       1 1965.589 13.056810 1.9431896       0       0  A 14/07/1952 04/08/1965
2       1 1967.533 15.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
3       1 1970.000 17.467488 2.5325120       0       0  A 14/07/1952 04/08/1965
4       1 1972.533 20.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
5       1 1975.000 22.467488 2.5325120       0       0  A 14/07/1952 04/08/1965
6       1 1977.533 25.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
7       1 1980.000 27.467488 2.5325120       0       0  A 14/07/1952 04/08/1965
8       1 1982.533 30.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
9       1 1985.000 32.467488 2.5325120       0       0  A 14/07/1952 04/08/1965
10      1 1987.533 35.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
11      1 1990.000 37.467488 2.5325120       0       0  A 14/07/1952 04/08/1965
12      1 1992.533 40.000000 2.4674880       0       0  A 14/07/1952 04/08/1965
13      1 1995.000 42.467488 2.4852841       0       1  A 14/07/1952 04/08/1965
14      2 1972.686 18.439425 1.5605749       0       0  B 01/04/1954 08/09/1972
15      2 1974.246 20.000000 0.7535934       0       0  B 01/04/1954 08/09/1972
16      2 1975.000 20.753593 4.2464066       0       0  B 01/04/1954 08/09/1972
17      2 1979.246 25.000000 0.7535934       0       0  B 01/04/1954 08/09/1972
18      2 1980.000 25.753593 4.2464066       0       0  B 01/04/1954 08/09/1972
19      2 1984.246 30.000000 0.7535934       0       0  B 01/04/1954 08/09/1972
20      2 1985.000 30.753593 4.2464066       0       0  B 01/04/1954 08/09/1972
21      2 1989.246 35.000000 0.7535934       0       0  B 01/04/1954 08/09/1972
22      2 1990.000 35.753593 4.2464066       0       0  B 01/04/1954 08/09/1972
23      2 1994.246 40.000000 0.7535934       0       0  B 01/04/1954 08/09/1972
24      2 1995.000 40.753593 0.3880903       0       0  B 01/04/1954 08/09/1972
25      3 1991.974  4.536619 0.4633812       0       0  C 10/06/1987 23/12/1991
26      3 1992.437  5.000000 2.5626283       0       0  C 10/06/1987 23/12/1991
27      3 1995.000  7.562628 2.4373717       0       0  C 10/06/1987 23/12/1991
28      3 1997.437 10.000000 1.1211499       0       1  C 10/06/1987 23/12/1991
         exit fail       bt       en       ex
1  27/06/1997    1 1952.533 1965.589 1997.485
2  27/06/1997    1 1952.533 1965.589 1997.485
3  27/06/1997    1 1952.533 1965.589 1997.485
4  27/06/1997    1 1952.533 1965.589 1997.485
5  27/06/1997    1 1952.533 1965.589 1997.485
6  27/06/1997    1 1952.533 1965.589 1997.485
7  27/06/1997    1 1952.533 1965.589 1997.485
8  27/06/1997    1 1952.533 1965.589 1997.485
9  27/06/1997    1 1952.533 1965.589 1997.485
10 27/06/1997    1 1952.533 1965.589 1997.485
11 27/06/1997    1 1952.533 1965.589 1997.485
12 27/06/1997    1 1952.533 1965.589 1997.485
13 27/06/1997    1 1952.533 1965.589 1997.485
14 23/05/1995    0 1954.246 1972.686 1995.388
15 23/05/1995    0 1954.246 1972.686 1995.388
16 23/05/1995    0 1954.246 1972.686 1995.388
17 23/05/1995    0 1954.246 1972.686 1995.388
18 23/05/1995    0 1954.246 1972.686 1995.388
19 23/05/1995    0 1954.246 1972.686 1995.388
20 23/05/1995    0 1954.246 1972.686 1995.388
21 23/05/1995    0 1954.246 1972.686 1995.388
22 23/05/1995    0 1954.246 1972.686 1995.388
23 23/05/1995    0 1954.246 1972.686 1995.388
24 23/05/1995    0 1954.246 1972.686 1995.388
25 24/07/1998    1 1987.437 1991.974 1998.559
26 24/07/1998    1 1987.437 1991.974 1998.559
27 24/07/1998    1 1987.437 1991.974 1998.559
28 24/07/1998    1 1987.437 1991.974 1998.559
Classes 'Lexis' and 'data.frame':	28 obs. of  14 variables:
 $ lex.id : int  1 1 1 1 1 1 1 1 1 1 ...
 $ per    : num  1966 1968 1970 1973 1975 ...
 $ age    : num  13.1 15 17.5 20 22.5 ...
 $ lex.dur: num  1.94 2.47 2.53 2.47 2.53 ...
 $ lex.Cst: num  0 0 0 0 0 0 0 0 0 0 ...
 $ lex.Xst: num  0 0 0 0 0 0 0 0 0 0 ...
 $ id     : chr  "A" "A" "A" "A" ...
 $ birth  : chr  "14/07/1952" "14/07/1952" "14/07/1952" "14/07/1952" ...
 $ entry  : chr  "04/08/1965" "04/08/1965" "04/08/1965" "04/08/1965" ...
 $ exit   : chr  "27/06/1997" "27/06/1997" "27/06/1997" "27/06/1997" ...
 $ fail   : num  1 1 1 1 1 1 1 1 1 1 ...
 $ bt     : num  1953 1953 1953 1953 1953 ...
 $ en     : num  1966 1966 1966 1966 1966 ...
 $ ex     : num  1997 1997 1997 1997 1997 ...
 - attr(*, "breaks")=List of 2
  ..$ per: num  1900 1905 1910 1915 1920 ...
  ..$ age: num  0 5 10 15 20 25 30 35 40 45 ...
 - attr(*, "time.scales")= chr  "per" "age"
 - attr(*, "time.since")= chr  "" ""
    
Transitions:
     To
From  0 1  Records:  Events: Risk time:  Persons:
   0 26 2        28        2      61.18         3
   1965 1970 1975 1980 1985 1990 1995
0    NA   NA   NA   NA   NA    0   NA
5    NA   NA   NA   NA   NA    0    0
10    0   NA   NA   NA   NA   NA    1
15    0    0   NA   NA   NA   NA   NA
20   NA    0    0   NA   NA   NA   NA
25   NA   NA    0    0   NA   NA   NA
30   NA   NA   NA    0    0   NA   NA
35   NA   NA   NA   NA    0    0   NA
40   NA   NA   NA   NA   NA    0    1
       1965     1970     1975     1980     1985      1990     1995
0        NA       NA       NA       NA       NA 0.4633812       NA
5        NA       NA       NA       NA       NA 2.5626283 2.437372
10 1.943190       NA       NA       NA       NA        NA 1.121150
15 2.467488 4.093087       NA       NA       NA        NA       NA
20       NA 3.221081 6.778919       NA       NA        NA       NA
25       NA       NA 3.221081 6.778919       NA        NA       NA
30       NA       NA       NA 3.221081 6.778919        NA       NA
35       NA       NA       NA       NA 3.221081 6.7789185       NA
40       NA       NA       NA       NA       NA 3.2210815 2.873374

Epi documentation built on Feb. 28, 2021, 1:06 a.m.

Related to splitLexis in Epi...