stn.dtmc: Calculate the Stationary Distribution of Markov Chain

Description Usage Arguments Value Author(s) Examples

View source: R/stn.dtmc.R

Description

Calculate the Stationary Distribution of Markov Chain

Usage

1
2
3
4
## S3 method for class 'dtmc'
stn(obj, k = 10, ending = 10, epsilon = 0.05)
## S3 method for class 'ctmc'
stn(obj, k = 10, ending = 10, epsilon = 0.05)

Arguments

obj

the Markov Chain we want to apply

k

for infinite state Markov Chain, the initial state to do the iterative process in order to find the stationary distribution, default value is 10

ending

for infinite state Markov Chain, the ending criterion of the iterative process, default value is 10

epsilon

for infinite state Markov Chain, the convergence criterion to stop the iterative process, default value is 0.05

Value

A matrix corresponding to the stationary states

Author(s)

Jiexuan Cao, Yuki Liu, Qianhan Zhang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#discrete finite state markov chain
dtftmc = mc(states = c("sunny", "cloudy", "rain"),
                 pijdef = function(i,j,...) {
                           if (i == 1 && j < 3 ||
                               i == 2 && j != 2 ||
                               i == 3 && j > 1)  return(0.5)
                           0
                        },  
       name = "Weather")

dtftsd = stn(dtftmc)

pijdeffunction = function(i,j) {
    p = 0.3
    q = 0.7
    r = 0
    if (i == 1 && j == 1)
        return (1 - p)
    if(j == i + 1)
        return(p)
    if(j == i - 1)
        return(q)
    if(j==i)
        return(r)
    return(0)
}

dtiftmc = mc(states = "infinity",
             pijdef = pijdeffunction, 
             name = "death and birth")

dtiftsd = stn(dtiftmc, ending = 20)

#continuous finite state markov chain
ctftmc = mc(states = c("0", "1", "2"),
            pijdef = matrix(c(0, 0.2857143, 0, 1, 0, 1, 0, 0.7142857, 0), ncol = 3),
            qidef = c(0.25, 0.175, 0.08),
            name = 'Machine Repair')
            
stn(ctftmc)

yuki0425/mc documentation built on May 4, 2019, 7:44 p.m.