seqsurv {TraMineRextras} | R Documentation |
Generate a survfit object for state survival times.
Description
The function considers the spells in the different states in sequences and fits survival curves for each state. Alternatively, for a selected state, it fits the survival curves for each level of a stratifying group variable.
Survival curves are fitted with the survfit
function.
Usage
seqsurv(seqdata, groups = NULL, per.state = FALSE, state = NULL,
with.missing = FALSE)
Arguments
seqdata |
A sequence |
groups |
A stratifying group variable of length equal to the number of sequences. |
per.state |
Logical. Should the survival probabilites be computed for the state specified as |
state |
Single state value or a vector. The short name of the state for which to compute survival probabilities. If a vector of state names, survival probabilities are computed for the subset defined by those states. If |
with.missing |
Logical. Should the missing state be accounted for? (Not yet implemented!) |
Details
The function considers the spells in the different states of a state sequence object (of class stslist
).
When per.state = FALSE
, it fits survival curves for each state in the alphabet.
Currently, per.state = FALSE
cannot be used with a non-NULL
groups
argument.
However, seqsplot
handles this case.
When per.state = TRUE
, the survival curve is fitted only for the state provided as state
argument. This is done for each level of the groups
variable.
Survival curves are fitted with the survfit
function.
Value
An object of class stslist.surv. There is a plot
method for such
objects.
Author(s)
Matthias Studer, Gilbert Ritschard, Pierre-Alexandre Fonta
See Also
plot.stslist.surv
for basic plots of stslist.surv objects
and seqsplot
for more elaborated plots.
Examples
## Defining a sequence object with the data in columns 10 to 25
## (family status from age 15 to 30) in the biofam data set
data(biofam)
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.short <- c("P","L","M","LM","C","LC","LMC","D")
sple <- 500:700 ## want a sample with all elements of the alphabet
##seqstatl(biofam[sple,10:25])
biofam <- biofam[sple,]
## creating the state sequence object
biofam.seq <- seqdef(biofam[,10:25], alphabet=0:7, states=biofam.short, labels=biofam.lab)
## Spell survival curves
(biofam.surv <- seqsurv(biofam.seq))
## Cohort distinguishing between those born before or after World War II
biofam$wwii <- biofam$birthyr <= 1945
## Separate survival curves in a given state (here LMC "Left+Marr+Child") according to wwii
(biofam.surv <- seqsurv(biofam.seq, groups=biofam$wwii, per.state=TRUE, state="LMC"))
plot(biofam.surv)