transmatrix2sequence | R Documentation |
Creates Markov chains based on a transition matrix. Can be used as parameter for the Monte Carlo function.
transmatrix2sequence(matrix, length, initialIndex, score)
matrix |
transition matrix of Markov process |
length |
length of sequence to be sampled |
initialIndex |
(optional) index of matrix which should be initial value of sequence. If none supplied, a value from the stationary distribution is sampled as initial value. |
score |
(optional) a vector representing the scores (in ascending order) of the matrix index. If supplied, the result will be a vector of these values. |
The transition matrix is considered representing the transition from one score to another such that the score in the first row is the lowest and the last row are the transitions from the highest score to another. The matrix must be stochastic (no rows filled up with only '0' values).
It is possible to have the same score for different states of the markov chain. If no score supplied, the function returns a markov chain with state in 1:ncol(matrix)
a Markov chain sampled from the transition matrix
B <- matrix (c(0.2, 0.8, 0.4, 0.6), nrow = 2, byrow = TRUE)
transmatrix2sequence(B, length = 10)
transmatrix2sequence(B, length = 10, score = c(-2,1))
transmatrix2sequence(B, length = 10, score = c("A","B"))
MyTransMat <-
matrix(c(0.3,0.1,0.1,0.1,0.4,
0.2,0.2,0.1,0.2,0.3,
0.3,0.4,0.1,0.1,0.1,
0.3,0.3,0.1,0.0,0.3,
0.1,0.1,0.2,0.3,0.3),
ncol = 5, byrow=TRUE)
MySeq.CM <- transmatrix2sequence(matrix = MyTransMat,length=90, score =c(-2,-1,0,2,3))
MySeq.CM
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.