Project 3

A computer is shared by 2 users who send tasks to a computer remotely and work independently. At any minute, any connected user may disconnect with probability 0.5, and any disconnected user may connect with a new task with probability 0.2. Let X(t) be the number of concurrent users at time t (in minutes). This is a Markov chain with 3 states: 0, 1, and 2. The probability transition matrix can be calculated and it is

Generate 10000 transitions of the Markov chain. What percent of times do you find your generated Markov chain in each of its 3 states?

#We generate/display the matrix
p = matrix(data = c(0.64,0.4,0.25,0.32,0.5,0.5,0.04,0.1,0.25), nrow = 3)
p
##      [,1] [,2] [,3]
## [1,] 0.64 0.32 0.04
## [2,] 0.40 0.50 0.10
## [3,] 0.25 0.50 0.25
# We simulate the data
set.seed(6589)
p = matrix(data = c(0.64,0.4,0.25,0.32,0.5,0.5,0.04,0.1,0.25), nrow = 3)
all.states = c(0, 1, 2)
n = 10000
state = 0
transitions = c()
for (i in 1:n) {
  if(state == 0){
    state = sample(all.states, 1, prob = c(0.64,0.32,0.04))
  }
  if(state == 1){
    state = sample(all.states, 1, prob = c(0.4,0.5,0.1))
  }
  if(state == 2){
    state = sample(all.states, 1, prob = c(0.25,0.5,0.25))
  }
  transitions = c(transitions, state)
}
head(transitions)
## [1] 0 0 1 1 0 0
# We make/create an histogram
hist(transitions, prob=TRUE, main="State Frequencies", xlab = "States", ylab = "Frequency")

We generate 10000 transitions of the Markov chain for different states

# State 0
sum(transitions == 0)/n
## [1] 0.6569
# State 1
sum(transitions == 1)/n
## [1] 0.317
# State 3
sum(transitions == 2)/n
## [1] 0.0261

Discussion

We generated 10000 transitions of the Markov chain for different states and the percentage of times the generated Markov chain is in 3 states are:

State 0: 65.69%

State 1: 31.7%

State 3: 0.0261%