Learn R Programming

Epi (version 2.19)

foreign.Lexis: Create a data structures suitable for use with packages mstate, etm.

Description

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

The etm package requires input (almost) in the form of a Lexis object, but with specific column names etc. This is provided by etm.Lexis.

Usage

msdata(obj, ...)
# S3 method for Lexis
msdata(obj,
                time.scale = timeScales(obj)[1],
                       ... )
# S3 method for Lexis
etm( obj,
              time.scale = timeScales(obj)[1],
               cens.name = "cens",
                       s = 0,
                       t = "last",
              covariance = TRUE,
                delta.na = TRUE,
                     ... )

Arguments

obj

A Lexis object.

time.scale

Name or number of timescale in the Lexis object.

cens.name

Name of the code for censoring used by etm. It is only necessary to change this if one of the states in the Lexis object has name "cens".

s

Passed on to etm.

t

Passed on to etm.

covariance

Passed on to etm.

delta.na

Passed on to etm.

Further arguments.

Value

msdata.Lexis returns 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.

etm.Lexis transforms the Lexis object into a dataframe suitable for analysis by the function etm from the etm package, and actually calls this function, so returns an object of class etm.

See Also

stack.Lexis, msprep, etm

Examples

Run this code
# NOT RUN {
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[1:1000,] )
dmi <- cutLexis( dml, cut=dml$doins, new.state="Ins", pre="DM" )
summary( dmi )

# Use the interface to the mstate package
if( require(mstate) )
{
ms.dmi <- msdata.Lexis( dmi )
# Check that all the transitions and person-years got across.
with( ms.dmi, rbind( table(status,trans),
                     tapply(Tstop-Tstart,trans,sum) ) )
}

# Use the etm package directly with a Lexis object
if( require(etm) )
{
dmi <- subset(dmi,lex.id<1000)
etm.D <- etm.Lexis( dmi, time.scale=3 )
plot( etm.D, col=rainbow(5), lwd=2, lty=1, xlab="DM duration" )
}
# }

Run the code above in your browser using DataLab