# [R] Question on 'predict' in 'markovchain' package

Huang, Cassie Jingyi.Huang at warwick.ac.uk
Mon Nov 21 18:47:40 CET 2016

```Dear Sir/Madam,

I want to report a problem of 'predict' function in the 'markovchain' package and I will use to examples to explain the problem.

Problem:
-It only follows the path with transition probability greater or equal than 0.5.

Here are two examples.
Example (1)
I created an MC with the transition matrix  (by rows)  is defined as follows:

0     1
0     0.5   0.5
1     0.6   0.4
-I applied 'predict' on the MC above starting at 0 and 1 respectively and get the transition counts as follows:
(start at 0)
0  1
0 34  32
1 33  0

(start at 1)
0  1
0 35 32
1 32  0
In Example (1), we observe that 1-1 has the probability less than 0.5 and it never happens in prediction.

Example (2)
I created an MC with the transition matrix  (by rows)  is defined as follows:

0     1
0     0.53   0.47
1     0.47  0.53

I get all 0's after applied 'prediction' with starting state 0 while I get all 1's with starting state 1.
This may because only 0-0 and 1-1  have >0.5 probability in the MC so they are the only two path will appear in the prediction.

Code as follows.

statesNames=c("0","1")
mcA<-new("markovchain", transitionMatrix=matrix( c(0.5,0.5,0.6,0.4),byrow=TRUE,
nrow=2, dimnames=list(statesNames,statesNames)))
mcA
createSequenceMatrix(stringchar = mcApred0)
createSequenceMatrix(stringchar = mcApred1)

statesNames=c("0","1")
mcB<-new("markovchain", transitionMatrix=matrix( c(0.53,0.47,0.47,0.53),byrow=TRUE,
nrow=2, dimnames=list(statesNames,statesNames)))
mcB