seqsurv: Generate a survfit object for state survival times.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/seqsurv.R

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

1
2
seqsurv(seqdata, groups = NULL, per.state = FALSE, state = NULL,
    with.missing = FALSE)

Arguments

seqdata

A sequence stslist object as defined by the seqdef function.

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 argument? If set as TRUE, the state argument must also be specified.

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 NULL, survival probabilities are computed for all cases.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 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)

Example output

Loading required package: TraMineR

TraMineR stable version 2.0-11.1 (Built: 2019-05-12)
Website: http://traminer.unige.ch
Please type 'citation("TraMineR")' for citation information.

TraMineRextras stable version 0.4.5 (Built: 2019-05-11)
Functions provided by this package are still in test
    and subject to changes in future releases.
 [>] state coding:
       [alphabet]  [label]  [long label] 
     1             0P        Parent
     2             1L        Left
     3             2M        Married
     4             3LM       Left+Marr
     5             4C        Child
     6             5LC       Left+Child
     7             6LMC      Left+Marr+Child
     8             7D        Divorced
 [>] 201 sequences in the data set
 [>] min/max sequence length: 16/16
Call: survfit(formula = Surv(spell$dur, spell$status) ~ spell$states, 
    weights = spell$weights, subset = spell$states %in% state)

                   n events median 0.95LCL 0.95UCL
spell$states=P   198    187      7       7       8
spell$states=L    92     70      6       5       7
spell$states=M    25      6     NA      NA      NA
spell$states=LM  113     73      3       2       5
spell$states=C     1      1      2      NA      NA
spell$states=LC    5      1     NA       4      NA
spell$states=LMC  98      3     NA      NA      NA
spell$states=D    10      0     NA      NA      NA
Call: survfit(formula = Surv(spell$dur, spell$status) ~ spell$group, 
    weights = spell$weights, subset = spell$states %in% state)

                   n events median 0.95LCL 0.95UCL
spell$group=FALSE 54      2     NA      NA      NA
spell$group=TRUE  44      1     NA      NA      NA

TraMineRextras documentation built on June 25, 2021, 1:06 a.m.