transform.Lexis {Epi}R Documentation

Transform a Lexis (or stacked.Lexis) object

Description

Modify a Lexis object.

Usage

## S3 method for class 'Lexis'
transform( `_data`, ...)
## S3 method for class 'Lexis'
Relevel( x, states, print = TRUE, ... )
## S3 method for class 'Lexis'
levels( x )
## S3 method for class 'Lexis'
factorize( x, states, print = TRUE, ... )
## S3 method for class 'stacked.Lexis'
transform( `_data`, ...)


Arguments

_data

an object of class Lexis.

x

an object of class Lexis.

states

Names of the factor levels (states) for lex.Cst and lex.Xst. Can be a list, in which case some levels are collapsed, see the documentation for Relevel. No sanity check for the latter operation is undertaken.

print

Should a conversion between old and new levels be printed?

...

Additional arguments to be passed to transform.data.frame, Relevel order or sort.

Details

The transform method for Lexis objects works exactly as the method for data frames, but keeps the Lexis attributes.

factorize transforms the variables lex.Cst and lex.Xst to factors with identical set of levels, optionally with names given in states, and optionally collapsing states.

Relevel is merely an alias for factorize, since the function does the same as Relevel, but for both the factors lex.Cst and lex.Xst. A default sideeffect is to produce a table of old states versus new states if states is a list. Unlike Relevel for factors, Relevel.Lexis does not accept a matrix as a second argument - the number of levels of lex.Cst is rarely (if ever) large.

Note that if states is an integer vector, the levels of lex.Cst and lex.Xst are permuted. If states is a list of numbers or strings, the levels of lex.Cst and lex.Xst will be permuted. But if states is a character vector it must have length nlevels(lex.Cst), and the result will be a renaming of the levels.

If states is NULL, as when for example the argument is not passed to the function, the returned object have levels of lex.Cst, lex.Xst (and for stacked.Lexis objects lex.Tr) shaved down to the actually occurring values; that is, empty levels are discarded.

Value

A transformed Lexis object.

The function levels returns the names of the states (levels of the factors lex.Cst and lex.Xst.

Author(s)

Martyn Plummer, Bendix Carstensen

See Also

Lexis, merge.Lexis, subset.Lexis, subset.stacked.Lexis, Relevel, transient, absorbing

Examples

data( nickel )
nic <- Lexis( data = nickel,
                id = id,
             entry = list(age=agein),
              exit = list(age=ageout,cal=ageout+dob,tfh=ageout-age1st),
    ## Lung cancer deaths are coded 2 and other deaths are coded 1
       exit.status = ( (icd > 0) + (icd %in% c(162,163)) ) )
str( nic )
levels( nic )
nit <- transform( nic, cumex = exposure*(agein-age1st) )
str( nit )
## It is still a Lexis object!
summary( nic )
nix <- factorize.Lexis( nic, c("Alive","Lung","Dead"))
niw <- factorize.Lexis( nix, c("Alive","Pulm","Mort"))
niz <- factorize.Lexis( niw, states=list("Alive",c("Pulm","Mort")), coll=" \n& ")
boxes( niw, boxpos=TRUE )
par( new=TRUE )
boxes( niz, boxpos=TRUE )
siw <- stack( niw )
str( siw )

[Package Epi version 2.42 Index]