seqdef {TraMineR}R Documentation

Create a state sequence object

Description

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.

Usage

seqdef(data, var, informat="STS", stsep="-",
        alphabet, states, id=NULL, start=1,
        left=NA, right="DEL", gaps=NA, missing=NA, void="%", nr="*",
        cnames, cpal, missing.color="darkgrey", labels, ...)

Arguments

data a data frame or matrix containing sequence data.
var the list of columns containing the sequences. Defaut to NULL, ie all the columns. Whether the sequences are in the compressed (successive states in a character string) or extended format is automatically detected.
informat format of the original data. Default is 'STS'. Avalaible formats are: STS, SPS, SPELL. See TraMineR user's manual (Gabadinho et al., 2008) for a description of the formats.
stsep the character used as separator in the original data if input format is successive states in a character string. By default, "-".
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 NULL, the alphabet is set to the distinct states appearing in the data as returned by the seqstatl function.
states an optional vector containing the labels for the states. Must have a length equal to the number of states in the data, and the labels must be ordered accordingly with the values returned by the seqstatl function.
id optinal vector containing the rownames of the sequence object. If NULL, rownames are labelled from 1 to number of sequences in the input data.
start starting time. For instance, if your 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. See Gabadinho et al. (2008) for more details on the options for handling missing values when defining sequence objects. By default, left missing values are treated as 'real' missing values and converted to the internal missing value code defined by the nr option.
right the behavior for missing values appearing after the last (rightmost) valid state in each sequence. See Gabadinho et al. (2008) for more details on the options for handling missing values when defining sequence objects. By default, right missing values are treated as 'void' elements and converted to the internal code for void values defined by the void option.
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. See Gabadinho et al. (2008) for more details on the options for handling missing values when defining sequence objects. By default, gap missing values are treated as 'real' missing values and converted to the internal missing value code defined by the nr option.
missing the code used for missing values in the input data. When specified, all cells containing this value will be replaced by NA's, the internal R code for missing values. If 'missing' is not specified, cells containing NA's are considered to be missing values.
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. When not specified, names are taken from the original column names in the data.
cpal an optional color palette for representing the states in the graphics. If not specified, a color palette is created with the RColorBrewer package, using the "Accent" palette. Note that the maximum number of colors in this palette is 8. If the number of states in the data is greater than 8, you have to specify your own palette. The list of available colors is displayed by the colors function. You can also use alternatively some other palettes from the RColorBrewer package.
missing.color alternative color for representing missing values inside the sequences. Defaults to "darkgrey".
labels state labels used for the color legend of TraMineR's graphics.
... options passed to the seqformat function for handling input data that is not in STS format.

Details

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) adapted to the selected column or row subset. If only one column is specified, a factor is returned.

Value

An object of class stslist. There are methods for print, summary, and subscripting sequence objects. State sequence objects are required as argument to other functions such as plotting functions (seqdplot, seqiplot or seqfplot), functions to compute distances (seqdist), etc...

References

Gabadinho, A., G. Ritschard, M. Studer and N. S. Müller (2008). Mining Sequence Data in R with TraMineR: A user's guide. Department of Econometrics and Laboratory of Demography, University of Geneva.

See Also

plot.stslist to plot state sequence objects, seqecreate to create an event sequence object.

Examples

## 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")

## Frequency plot for the monthes June to September
seqfplot(actcal.seq[,6:9], pbarw=TRUE)

## 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)
actcal.seq[1:10,]

[Package TraMineR version 1.2-1 Index]