Last data update: 2014.03.03

R: Extract time band data from a split Lexis object
timeBandR Documentation

Extract time band data from a split Lexis object

Description

The break points of a Lexis object (created by a call to splitLexis) divide the follow-up intervals into time bands along a given time scale. The breaks function returns the break points, for a given time scale, and the timeBand classifies each row (=follow-up interval) into one of the time bands.

Usage

timeBand(lex, time.scale, type="integer")
breaks(lex, time.scale)

Arguments

lex

an object of class Lexis

time.scale

a character or integer vector of length 1 identifying the time scale of interest

type

a string that determines how the time bands are labelled. See Details below

Details

Time bands may be labelled in various ways according to the type argument. The permitted values of the type argument, and the corresponding return values are:

"integer"

a numeric vector with integer codes starting from 0.

"factor"

a factor (unordered) with labels "(left,right]"

"left"

the left-hand limit of the time band

"middle"

the midpoint of the time band

"right"

the right-hand limit of the time band

Value

The breaks function returns a vector of break points for the Lexis object, or NULL if no break points have been defined by a call to splitLexis. The timeBand function returns a numeric vector or factor, depending on the value of the type argument.

Note

A newly created Lexis object has no break points defined. In this case, breaks will return NULL, and timeBand will a vector of zeros.

Author(s)

Martyn Plummer

See Also

Lexis

Examples

data(diet)
diet <- cal.yr(diet)
diet.lex <- Lexis(entry=list(period=doe),
                   exit=list(period=dox, age=dox-dob),
            exit.status=chd,
                   data=diet)
diet.split <- splitLexis(diet.lex, breaks=seq(40,70,5), "age" )
age.left <- timeBand(diet.split, "age", "left")
table(age.left)
age.fact <- timeBand(diet.split, "age", "factor")
table(age.fact)
age.mid <- timeBand(diet.split, "age", "mid")
table(age.mid)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Epi)

Attaching package: 'Epi'

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

    merge.data.frame

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Epi/time.band.Rd_%03d_medium.png", width=480, height=480)
> ### Name: timeBand
> ### Title: Extract time band data from a split Lexis object
> ### Aliases: timeBand breaks
> ### Keywords: attribute
> 
> ### ** Examples
> 
> data(diet)
> diet <- cal.yr(diet)
> diet.lex <- Lexis(entry=list(period=doe),
+                    exit=list(period=dox, age=dox-dob),
+             exit.status=chd,
+                    data=diet)
> diet.split <- splitLexis(diet.lex, breaks=seq(40,70,5), "age" )
> age.left <- timeBand(diet.split, "age", "left")
> table(age.left)
age.left
-Inf   40   45   50   55   60   65 
  26   78  195  238  272  237  149 
> age.fact <- timeBand(diet.split, "age", "factor")
> table(age.fact)
age.fact
(-Inf,40]   (40,45]   (45,50]   (50,55]   (55,60]   (60,65]   (65,70]  (70,Inf] 
       26        78       195       238       272       237       149         0 
> age.mid <- timeBand(diet.split, "age", "mid")
> table(age.mid)
age.mid
-Inf 42.5 47.5 52.5 57.5 62.5 67.5 
  26   78  195  238  272  237  149 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>