Create event sequence objects.

Description

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

Usage

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

Arguments

data

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

id

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

timestamp

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

event

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).

endEvent

If specified this event serves as a flag for the end of observation time (total length of event sequences).

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

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

weighted

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

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.

Author(s)

Matthias Studer (with Gilbert Ritschard for the help page)

See Also

seqformat for converting between sequence formats, 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
##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.seqe <- seqecreate(biofam.seq)

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

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.