Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

transform.Lexis

Transform a Lexis (or stacked.Lexis) object


Description

Modify a Lexis object.

Usage

## S3 method for class 'Lexis'
factorize(x, ...)
## S3 method for class 'Lexis'
Relevel(x, ref, ...)
## S3 method for class 'Lexis'
levels(x)
## S3 method for class 'Lexis'
transform(`_data`, ...)
## S3 method for class 'stacked.Lexis'
transform(`_data`, ...)
 order.Lexis(x)
  orderLexis(x)
   sortLexis(x)

Arguments

_data

an object of class Lexis.

x

an object of class Lexis.

ref

New names (or order) 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 type of operation is undertaken.

...

Additional arguments to be passed to transform.data.frame, Relevel.factor.

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 sets of levels.

Relevel does the same as Relevel.factor, but for both the factors lex.Cst and lex.Xst in x. lex.Cst and lex.Xst must be factors with the same levels. They can be made so by factorize.

If ref is an integer or character vector, the levels of lex.Cst and lex.Xst are permuted to match the order of ref.

If ref 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.

order.Lexis returns the order of the rows in a Lexis object to sort it by ()lex.id,ts), where ts is a timescale in the Lexis object with no NAs. orderLexis is just a synonym.

sortLexis returns the Lexis object sorted by (lex.id, ts) where ts is one of the timeScales with no NAs.

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

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 end as 2 and other deaths as 1
       exit.status = factor((icd > 0) + (icd %in% c(162,163)),
                            labels = c("Alive","Dead","Lung") ) )
str( nic )
levels( nic )
nit <- transform( nic, cumex = exposure * (agein - age1st) )
str( nit )

# It is still a Lexis object!
summary(nic)

# change order of levels
nix <- Relevel(nic, c("Alive", "Lung", "Dead"))
summary(nix)

# change names of levels 
niw <- Relevel(nix, list("Alive" = 1, "Pulm" = "Lung", "Mort" = "Dead"))
summary(niw)
boxes(niw, boxpos = TRUE)

# combine levels
niz <- Relevel(niw, list("Alive", c("Pulm", "Mort")), coll=" \n& ")
summary(niz)
par( new = TRUE )
boxes(niz, boxpos = TRUE)

#stack Lexis object
siw <- stack(niw)
str(siw)

Epi

Statistical Analysis in Epidemiology

v2.44
GPL-2
Authors
Bendix Carstensen [aut, cre], Martyn Plummer [aut], Esa Laara [ctb], Michael Hills [ctb]
Initial release
2021-02-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.