Learn R Programming

sequence (version 2.0)

geneseq: Generation aof random sequences

Description

Generates nseq random sequences of items represented by codes, either by random sampling (order 0), either using a Discrete Time Markov Chain (DTMC) transition matrix (order 1).

Usage

geneseq(nseq, lmin, lmax, order = 0, dico = NULL, mattrans = NULL)

Arguments

nseq

numeric: number of sequences to generate.

lmin

numeric: minimum length of sequences

lmax

numeric: maximum length of sequences

order

numeric: order of the Markov Process, 0 or 1. See details.

dico

character vector: dictionnary of items.

mattrans

data.frame: transition matrix with identifiers as first column.

Value

A list of nseq items

A1

list: first sequence

A2

list: second sequence

... and so on until nseq.

Details

Generates random sequences of states according to a Markov process of order 0 or 1. order 0: the following state is drawn with equal probabilities in the item list, no influence of previous state. order 1: the following state is drawn with a probability proportional to the product of the transition matrix by the vector of states. nseq sequences of random size are generated. The size of each sequence is a random integer drawn under uniform probability between lmin and lmax (both included).

See Also

compseq

Examples

Run this code
# NOT RUN {
# 1 - generates 5 random sequences of length from 1 to 15 with  
# symbols a,b,c,d.(order = 0)
geneseq(5,1,15,dico=letters[1:4]) 
mat<-data.frame(id=letters[1:3],a=c(0,0.75,0.25),b=c(0.5,0.25,0.25),
c=c(0.1,0.8,0.1))
# 2 - generates 2 random sequences of length 10 with symbols a,b,c,d  
# according to the transition matrix mat
geneseq(2,10,10,order=1,mattrans=mat) 
# }

Run the code above in your browser using DataLab