seqdef | R Documentation |
Create a state sequence object with attributes such as alphabet, color palette and state labels. Most TraMineR functions for state sequences require such a state sequence object as input argument. There are specific methods for plotting, summarizing and printing state sequence objects.
seqdef(data, var=NULL, informat="STS", stsep=NULL,
alphabet=NULL, states=NULL, id=NULL, weights=NULL, start=1,
left=NA, right="DEL", gaps=NA, missing=NA, void="%", nr="*",
cnames=NULL, xtstep=1, tick.last=FALSE, cpal=NULL,
missing.color="darkgrey", labels=NULL, ...)
data |
a data frame, matrix, or character string vector containing sequence data (tibble will be converted with |
var |
the list of columns containing the sequences. Default is
|
informat |
format of the original data. Default is |
stsep |
the character used as separator in the original
data if input format is successive states in a character string. If
|
alphabet |
optional vector containing the alphabet (the list of all possible states). Use this option if some states in the alphabet don't appear in the data or if you want to reorder the states. The specified vector MUST contain AT LEAST all the states appearing in the data. It may possibly contain additional states not appearing in the data. If |
states |
an optional vector containing the short state labels. Must have a length equal to the size of the alphabet and the labels must be ordered conformably with alpha-numeric ordered values returned by the |
id |
optional argument for setting the rownames of the sequence object. If |
weights |
optional numerical vector containing weights, which are taken into account by plotting and statistical functions when applicable. Weights must be non-negative and cannot be |
start |
starting time. For instance, if sequences begin at age 15, you can specify 15. At this stage, used only for labelling column names. |
left |
the behavior for missing values appearing before the
first (leftmost) valid state in each sequence. When |
right |
the behavior for missing values appearing after the
last (rightmost) valid state in each sequence. Same options as for
the |
gaps |
the behavior for missing values appearing inside the
sequences, i.e. after the first (leftmost) valid state and before the
last (rightmost) valid state of each sequence. Same options as for
the |
missing |
the code used for missing values in the input
data. Default is |
void |
the internal
code used by TraMineR for representing void elements in the
sequences. Default is |
nr |
the internal code used by TraMineR for representing real
missing elements in the sequences. Default is |
cnames |
optional names for the columns composing the
sequence data. Those names will be used by default in the graphics as
axis labels. If |
xtstep |
step between displayed tick-marks and labels on the time x-axis of state sequence plots.
If not overridden by the user, plotting functions retrieve this parameter from the |
tick.last |
Logical. Should a tick mark be enforced at the last position on the time x-axis? |
cpal |
an optional color palette for representing the states
in the graphics. If |
missing.color |
alternative color for representing missing
values inside the sequences. Defaults to |
labels |
optional state labels used for the color legend of
TraMineR's graphics. If |
... |
options passed to the |
Applying subscripts to sequence objects (eg. seq[,1:5]
or seq[1:10,]
) returns a state sequence object with some attributes
preserved (alphabet, missing) and some others (start, column names, weights)
adapted to the selected column or row subset. When the number of
columns selected is 1, the returned object is a factor.
For reordering the states use the alphabet
argument. This may
for instance be useful to compare data from
different sources with different codings of similar states. Using
alphabet
permits to order the states conformably in all
sequence objects. Otherwise, the default state order is the
alpha-numeric order returned by the seqstatl
function
which may differ when you have different original codings.
An object of class stslist
.
There are print
, plot
, rbind
, summary
, and subsetting [,]
methods for such objects.
Alexis Gabadinho and Gilbert Ritschard
Gabadinho, A., G. Ritschard, N. S. Müller and M. Studer (2011). Analyzing and Visualizing State Sequences in R with TraMineR. Journal of Statistical Software 40(4), 1-37.
Gabadinho, A., G. Ritschard, M. Studer and N. S. Müller (2010). Mining Sequence Data in R
with the TraMineR
package: A user's guide. Department of Econometrics and
Laboratory of Demography, University of Geneva.
plot.stslist
plot method for state sequence objects,
print.stslist
print method for state sequence objects,
is.stslist
to test whether an object is a proper stslist
object,
seqplot
for high level plots of state sequence objects,
seqecreate
to create an event sequence object,
seqformat
for converting between various longitudinal data formats.
## Creating a sequence object with the columns 13 to 24
## in the 'actcal' example data set
data(actcal)
actcal.seq <- seqdef(actcal,13:24,
labels=c("> 37 hours", "19-36 hours", "1-18 hours", "no work"))
## Displaying the first 10 rows of the sequence object
actcal.seq[1:10,]
## Displaying the first 10 rows of the sequence object
## in SPS format
print(actcal.seq[1:10,], format="SPS")
## Plotting the first 10 sequences
plot(actcal.seq)
## Re-ordering the alphabet
actcal.seq <- seqdef(actcal,13:24,alphabet=c("B","A","D","C"))
alphabet(actcal.seq)
## Adding a state not appearing in the data to the
## alphabet
actcal.seq <- seqdef(actcal,13:24,alphabet=c("A","B","C","D","E"))
alphabet(actcal.seq)
## Adding a state not appearing in the data to the
## alphabet and changing the states labels
actcal.seq <- seqdef(actcal,13:24,
alphabet=c("A","B","C","D","E"),
states=c("FT","PT","LT","NO","TR"))
alphabet(actcal.seq)
## rbind and summary
seq1 <- actcal.seq[1:10,]
seq2 <- actcal.seq[20:25,]
seq <- rbind(seq1,seq2)
summary(seq)
## ============================
## Example with missing values
## ============================
data(ex1)
## With right="DEL" default value
seqdef(ex1,1:13)
## Eliminating 'left' missing values
seqdef(ex1,1:13, left="DEL")
## Eliminating 'left' missing values and gaps
seqdef(ex1,1:13, left="DEL", gaps="DEL")
## ====================
## Example with weights
## ====================
ex1.seq <- seqdef(ex1, 1:13, weights=ex1$weights)
## weighted sequence frequencies
seqtab(ex1.seq)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.