Epi (version 2.30)

transform.Lexis: Transform a Lexis (or stacked.Lexis) objects

Description

Modify a Lexis object.

Usage

# S3 method for Lexis
transform( `_data`, …)
# S3 method for Lexis
Relevel( x, states, print = TRUE, … )
# S3 method for Lexis
levels( x )
# S3 method for Lexis
factorize( x, states, print = TRUE, … )


# S3 method for 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 or Relevel.

Value

A transformed Lexis object.

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

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.

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.

See Also

Lexis, merge.Lexis, subset.Lexis, subset.stacked.Lexis, Relevel

Examples

Run this code
# NOT RUN {
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 )
# }

Run the code above in your browser using DataLab