transform.Lexis | R Documentation |
Modify a Lexis object.
## S3 method for class 'Lexis'
factorize(x, ..., verbose = FALSE)
## 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)
_data |
an object of class |
x |
an object of class |
ref |
New names (or order) of the factor levels (states) for
|
... |
Additional arguments to be passed to
|
verbose |
Logical. Should a list of new levels be printed? |
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 NA
s. orderLexis
is just a synonym.
sortLexis
returns the Lexis object sorted by
(lex.id
, ts
) where ts
is one of the
timeScales
with no NA
s.
A transformed Lexis
object.
The function levels
returns the names of the states (levels of
the factors lex.Cst
and lex.Xst
.
Martyn Plummer, Bendix Carstensen
Lexis
,
merge.Lexis
,
subset.Lexis
,
subset.stacked.Lexis
,
Relevel
,
transient
,
absorbing
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.