lexisSeq: lexisSeq

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

Description

LexisSeq is one of three split functions defined in heaven. The purpose is to split according a vector of dates. Typical situations are age (e.g. 5 year periods), calender time (e.g. 2 year periods) and selected times after a si- tuation of interest (e.g. three selected time periods after onset of a disea- se). The input is a data.table and splitting guide. The "base" data are the data to be split. They may contain much information, but the key is "id", "start","end" and "event". These describe the participant's id, start of time period, end of time period and the event of interest (must be 0/1).

The other input is data to define splitvector and name. The splitvector may be a fixed vector (format="vector", e.g. a series of fixed calender dates) or a list of 3 integers defining start, end and intervel to split by (format="seq", for a split on age between 20 and 80 by 5 years a splitvector could be defined as: splitvector <- c(20,80,5)*365.25 and provided to the function as a variable). "varname" is a name of a variable in the data.table the defines a value to be added to the splitvector. For the age split just used as an example it would be a variable containing the birthdate. For a split after onset of a conditi- on it should be the date of the condition and NA when the condition does not occur. When no value should be added to the vector (e.g. split by calender time) "varname" should keep its default value of NULL.

On output a new variable with default name "value" defines the result of splitting. The variable can be renamed to a user defined name (e.g. value="myvalue"). This variable will contain zero when time is before the first value of the splitting vector (added the "varname") and then increased by one as each value of the splitting vector is reached.

Overall the function provides identical usefulness as the SAS lexis macro

Usage

1
lexisSeq(indat,invars,varname=NULL,splitvector,format,value="value")

Arguments

indat

- base data with id, start, end, event and other data - possibly already split

invars

- vector of colum names for id/entry/exit/event - in that order, example: c("id","start","end","event")

varname

- name of variable to be added to vector

splitvector

- A vector of calender times (integer). Splitvector can be a sequence of fixed times with format="vector" or generate a sequence of from-to-by if given 3 values and format="seq"

format

- either "vector" for fixed times or "seq" to generate a sequence of from-to-by

value

- 0 to the left of the vector, increase of 1 as each element of vector is passed

Details

The input must be data.table. This data.table is assumed already to be split by other functions with multiple records having identical participant id. The function extracts those variables necessary for splitting, splits by the provided vector and finally merges other variable onto the final result.

A note of caution: This function works with dates as integers. R has a de- fault origina of dates as 1 January 1970, but other programs have different default origins - and this includes SAS and Excell. It is therefor important for decent results that care is taken that all dates are defined similarly.

The output will always have the "next" period starting on the day where the last period ended. This is to ensure that period lengths are calculated pro- perly. The program will also allow periods of zero lengths which is a conse- quence when multiple splits are made on the same day. When there is an event on a period with zero length it is important to keep that period not to loose events for calculations. Whether other zero length records should be kept in calculations depend on context.

Value

The function returns a new data table where records have been split according to the provided vector. Variables unrelated to the splitting are left unchanged.

Author(s)

Christian Torp-Pedersen

See Also

lexis2 lexisFromTo

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(data.table)
dat <- data.table(ptid=c("A","A","B","B","C","C","D","D"),
                start=c(0,100,0,100,0,100,0,100),
                end=c(100,200,100,200,100,200,100,200),
                dead=c(0,1,0,0,0,1,0,1),
                Bdate=c(-5000,-5000,-2000,-2000,0,0,100,100))
#Example 1 - Splitting on a vector with 3 values to be added to "Bdate"                 
out <- lexisSeq(indat=dat,invars=c("ptid","start","end","dead"),
               varname="Bdate",c(0,150,5000),format="vector")
out[]
#Example 2 - splitting on a from-to-by vector with no adding (calender time?)
out2 <- lexisSeq(indat=dat,invars=c("ptid","start","end","dead"),
                 varname=NULL,c(0,200,50),format="seq",value="myvalue")
out2[]

tagteam/heaven documentation built on May 31, 2019, 1:46 a.m.