Learn R Programming

Epi (version 1.1.20)

msdata.Lexis: Create a dataframe suitable for use with the mstate package.

Description

The mstate package requires input in the form of a stacked dataset with specific variable names. This is provided by this function. The resulting dataframe contains the same information as the result of a call to stack.Lexis.

Usage

msdata(obj, ...)
## S3 method for class 'Lexis':
msdata(obj, time.scale = timeScales(obj)[1], ...)

Arguments

obj
A Lexis object.
time.scale
Name or number of timescale in the Lexis object.
...
Not used.

Value

  • A dataframe with the Lexis specific variables stripped, and with the following added: id, Tstart, Tstop, from, to, trans, status, which are used in the mstate package.

See Also

stack.Lexis

Examples

Run this code
data(DMlate)
str(DMlate)
dml <- Lexis( entry=list(Per=dodm,Age=dodm-dobth,DMdur=0),
               exit=list(Per=dox),
        exit.status=factor(!is.na(dodth),labels=c("DM","Dead")),
               data=DMlate )
dmi <- cutLexis( dml, cut=dml$doins, new.state="Ins", pre="DM" )
summary( dmi )
ms.dmi <- msdata.Lexis( dmi )
summary( dmi )
# Check that all the transitions and person-years got across.
with( ms.dmi, rbind( table(status,trans),
                     tapply(Tstop-Tstart,trans,sum) ) )

Run the code above in your browser using DataLab