createtrMat: (General)Convert raw data into a transition matrix

Description Usage Arguments Value Examples

Description

General function to create a transition matrix from raw data

Usage

1
createtrMat(y, states, transition = FALSE)

Arguments

y

Data frame that contains the frequency of the transitions of each state/Raw data in the form of numeric vector, character vector or matrix.

states

The character or numeric vector of states.

transition

Choose whether the data uploaded is in the form of transition matrix or not. The default value is FALSE.

Value

The transition matrix of the Markov chain

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#raw data in "data.frame" class is used
data(bigram)
statenames<-c("a", "b", "c", "d", "e", "f", "g", "h", "i",
             "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
             "t", "u", "v", "w", "x", "y", "z")
createtrMat(bigram,statenames)

#vector of raw data in "numeric" class is used
x <- c(1,4,1,4,3,4,4,4,3,1,3,2,3,3,3,4,2,2,3)
createtrMat(x,c(1:4))

#vector of raw data in "character" class is used
y<-c("a","d","a","d","c","d","d","d","c",
    "a","c","b","c","c","c","d","b","b","c")
createtrMat(y,c("a","b","c","d"))

#data in "matrix" class is used
y<-matrix(c(5,6,7,8),byrow=TRUE,nrow=2)
createtrMat(y,c(1,2))

ZiqingHo/BasicMC documentation built on May 21, 2019, 2:29 a.m.