Learn R Programming

Epi (version 2.58)

stack.Lexis: Functions to facilitate analysis of multistate models.

Description

stack.Lexis produces a stacked object suited for analysis of several transition intensities simultaneously.

Usage

# S3 method for Lexis
stack(x, ...)
tmat( x, ... )
# S3 method for Lexis
tmat(x, Y=FALSE, mode = "numeric", ...)

Value

tmat.Lexis returns a square transition matrix, classified by the levels of lex.Cst and lex.Xst, for every transition occurring the entry is the number of transitions occurring and NA

in all oter entries. If Y=TRUE, the diagonal will contain the risk time in each of the states.

stack.Lexis returns a dataframe to be used for analysis of multistate data when all transitions are modelled together, for example if some parameters are required to be the same for different transitions. The dataframe has class stacked.Lexis, and inherits the attributes time.scales and breaks from the Lexis

object, and so function timeBand applies to a stacked.Lexis object too.

The dataframe has same variables as the original Lexis object, but with each record duplicated as many times as there are possible exits from the current state, lex.Cst. Two variables are added: lex.Fail, an indicator of wheter an event for the transition named in the factor lex.Tr has occurred or not. lex.Tr is a factor with levels made up of combinations of the levels of lex.Cst and lex.Xst that do occur together in x, joined by a "->".

Arguments

x

A Lexis object.

Y

Logical. Should the risk time be put in the diagonal? This is a facility which is used by boxes.Lexis.

mode

Should the matrix be returned as a numeric matrix with NAs at unused places or (mode="logical") as a logical matrix with FALSE on the diagonal.

...

Not used.

Author

Bendix Carstensen, b@bxc.dk, http://bendixcarstensen.com

See Also

splitLexis cutLexis 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 )
ls.dmi <- stack( dmi )
str( ls.dmi )
# Check that all the transitions and person-years got across.
with( ls.dmi, rbind( table(lex.Fail,lex.Tr),
                     tapply(lex.dur,lex.Tr,sum) ) )

Run the code above in your browser using DataLab