seqecreate: Create event sequence objects.

View source: R/seqecreate.R

seqecreateR Documentation

Create event sequence objects.

Description

Create an event sequence object either from time stamped events or from a state sequence object.

Usage

seqecreate(data = NULL, id = NULL,timestamp = NULL, event = NULL,
  end.event = NULL, tevent = "transition", use.labels = TRUE,
  weighted = TRUE, endEvent)

Arguments

data

A state sequence object (see seqdef) or a data frame

id

Integer. The sequence 'id' column when data are provided in TSE format (ignored if data argument is provided).

timestamp

Double. The event 'timestamp' column when data are provided in TSE format, i.e., the time at which events occur (ignored if data argument is provided).

event

Character or factor. The 'event' column when data are provided in TSE format, i.e., the events occurring at the specified time stamps (ignored if data argument is provided).

end.event

Character. If specified this event indicates the end of observation time (total length of event sequences) when it is not followed by any other valid event. The event is ignored when occurring in between two valid events.

tevent

Either a transition matrix or a method to generate events from state sequences (see seqetm). Used only when data is a state sequence object.

use.labels

Logical. If TRUE, transitions names are built from long state labels rather than from the short state names of the alphabet.

weighted

Logical. If TRUE and data is a state sequence object, use the weights specified in data (see seqdef)

endEvent

Deprecated. Use end.event instead.

Details

There are several ways to create an event sequence object. The first one is by providing the events in TSE format (see seqformat), i.e. by providing three paired lists: id, timestamp and event, such that each triplet (id, timestamp, event) defines the event that occurs at time timestamp for case id. Several events at the same time for a same id are allowed. The lists can be provided with the arguments id, timestamp and event. An alternative is by providing a data frame as data argument in which case the function takes the required information from the "id", "timestamp" and "event" columns of that data frame. In any case with TSE format, listed events should be grouped by id and an error will be thrown otherwise. Such grouping can be achieved by ordering the data according to the id column using the order function (e.g., data[order(data$id), ]).

The other way is to pass a state sequence object (as data argument) and to perform an automatic state-to-event conversion. The simplest way to make a conversion is by means of a predefined method (see seqetm), such as "transition" (one distinct event per possible transition), "state" (a new event for each entering in a new state) and "period" (a pair of events, one start-state event and one end-state event for each found transition). For a more customized conversion, you can specify a transition matrix in the same way as in seqformat. Function seqetm can help you in creating your transition matrix.

Event sequence objects as created by seqecreate are required by most other 'seqe' methods, such as seqefsub or seqeapplysub for example.

Value

An object of class seqelist. There are print, and plot methods for such objects.

Author(s)

Matthias Studer (with Gilbert Ritschard for the help page)

References

Ritschard, G., Bürgin, R., and Studer, M. (2014), "Exploratory Mining of Life Event Histories", In McArdle, J.J. & Ritschard, G. (eds) Contemporary Issues in Exploratory Data Mining in the Behavioral Sciences. Series: Quantitative Methodology, pp. 221-253. New York: Routledge.

Ritschard, G., A. Gabadinho, M. Studer and N. S. Müller. Converting between various sequence representations. in Ras, Z. & Dardzinska, A. (eds.) Advances in Data Management, Springer, 2009, 223, 155-175.

See Also

seqformat for converting between sequence formats, seqeweight for retrieving or assigning weights, seqefsub for searching frequent subsequences, seqecmpgroup to search for discriminant subsequences, seqeapplysub for counting subsequence occurrences, seqelength for information about length (observation time) of event sequences, seqdef to create a state sequence object.

Examples

##Starting with states sequences
##Loading data
data(biofam)
## Creating state sequences
biofam.seq <- seqdef(biofam,10:25, informat='STS')
## Creating event sequences from biofam
biofam.eseq <- seqecreate(biofam.seq)

## Loading data
data(actcal.tse)
## Creating sequences
actcal.eseq <- seqecreate(id=actcal.tse$id, timestamp=actcal.tse$time,
	event=actcal.tse$event)
##printing sequences
actcal.eseq[1:10]
## Using the data argument
actcal.eseq <- seqecreate(data=actcal.tse)

## Example with missings
data(ex1) ## STS data with missing values

## Creating the state sequence object with by default
## the left missings and gaps coded as '*' and
## end missings coded as void ('%')
sqex1 <- seqdef(ex1[,1:13])
## and without ignoring right missings (coded as '*')
sqex1b <- seqdef(ex1[,1:13], right=NA)

## Compare the outcome
seqecreate(sqex1)
seqecreate(sqex1, tevent='state')
seqecreate(sqex1, tevent='state', end.event=attr(sqex1,'void'))
seqecreate(sqex1b, tevent='state')

TraMineR documentation built on May 29, 2024, 5 a.m.