# NOT RUN {
## ========================================
## Examples with raw STS sequences as input
## ========================================
## Loading a data frame with sequence data in the columns 13 to 24
data(actcal)
## Converting to SPS format
actcal.SPS.A <- seqformat(actcal, 13:24, from = "STS", to = "SPS")
head(actcal.SPS.A)
## Converting to compressed SPS format with no
## prefix/suffix and with "/" as state/duration separator
actcal.SPS.B <- seqformat(actcal, 13:24, from = "STS", to = "SPS",
compress = TRUE, SPS.out = list(xfix = "", sdsep = "/"))
head(actcal.SPS.B)
## Converting to compressed DSS format
actcal.DSS <- seqformat(actcal, 13:24, from = "STS", to = "DSS",
compress = TRUE)
head(actcal.DSS)
## ==============================================
## Examples with a state sequence object as input
## ==============================================
## Loading a data frame with sequence data in the columns 10 to 25
data(biofam)
## Limiting the number of considered cases to the first 20
biofam <- biofam[1:20, ]
## Creating a state sequence object
biofam.labs <- c("Parent", "Left", "Married", "Left/Married",
"Child", "Left/Child", "Left/Married/Child", "Divorced")
biofam.short.labs <- c("P", "L", "M", "LM", "C", "LC", "LMC", "D")
biofam.seq <- seqdef(biofam, 10:25, alphabet = 0:7,
states = biofam.short.labs, labels = biofam.labs)
## Converting to SPELL format
bf.spell <- seqformat(biofam.seq, from = "STS", to = "SPELL",
pdata = biofam, pvar = c("idhous", "birthyr"))
head(bf.spell)
## ======================================
## Examples with SPELL sequences as input
## ======================================
## Loading two data frames: bfspell20 and bfpdata20
## bfspell20 contains the first 20 biofam sequences in SPELL format
## bfpdata20 contains the IDs and the years at which the
## considered individuals were aged 15
data(bfspell)
## Converting to STS format with alignement on calendar years
bf.sts.y <- seqformat(bfspell20, from = "SPELL", to = "STS",
id = "id", begin = "begin", end = "end", status = "states",
process = FALSE)
head(bf.sts.y)
## Converting to STS format with alignement on ages
bf.sts.a <- seqformat(bfspell20, from = "SPELL", to = "STS",
id = "id", begin = "begin", end = "end", status = "states",
process = TRUE, pdata = bfpdata20, pvar = c("id", "when15"),
limit = 16)
names(bf.sts.a) <- paste0("a", 15:30)
head(bf.sts.a)
## ==================================
## Examples for TSE and SPELL output
## in presence of missing values
## ==================================
data(ex1) ## STS data with missing values
## creating the state sequence object with by default
## the end missings coded as void ('%')
sqex1 <- seqdef(ex1[,1:13])
as.matrix(sqex1)
## Creating state-event transition matrices
ttrans <- seqetm(sqex1, method='transition')
tstate <- seqetm(sqex1, method='state')
## Converting into time stamped events
seqformat(sqex1, from = "STS", to = "TSE", tevent = ttrans)
seqformat(sqex1, from = "STS", to = "TSE", tevent = tstate)
## Converting into vertical spell data
seqformat(sqex1, from = "STS", to = "SPELL", with.missing=TRUE)
seqformat(sqex1, from = "STS", to = "SPELL", with.missing=TRUE, right=NA)
seqformat(sqex1, from = "STS", to = "SPELL", with.missing=FALSE)
# }
Run the code above in your browser using DataCamp Workspace