In: Statistics and Probability
2. Imagine a collection of nine rooms, R1, R2,...,R9 connected as in the figure below. A social gathering involving N people takes place in these rooms, and the percentage of persons in each room is x1, x2,...,x9. As time progresses it is observed that in a time span of fifteen minutes people mingle and either stay where they are or migrate to an adjacent room with equal probability.
(a) Suppose that 100 people are distributed through out the rooms
so that R1 has 30 people, R2 has 40 people, R5 has 10 people and R8
has 20 people. After fifteen minutes how many people do we expect to
have in each room.
(b) The number of people observed at a given time in rooms R1, R2,...,R9 respectively is (125,50,150,75,275,100,125,50,150). What was the number of persons in each room fifteen minutes earlier?
(c) If everybody begins in R1, how long until there are people in R9? At that time, what is the distribution of people throughout the rooms?
(d) If you were to cater an event at this location, how would you divide your resources through out the nine rooms?
In 15 mins., the probabilties of locations are:-
R1 | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | |
R1 | 0.5 | 0.5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
R2 | 0.33 | 0.33 | 0.33 | 0 | 0 | 0 | 0 | 0 | 0 |
R3 | 0 | 0.33 | 0.33 | 0.33 | 0 | 0 | 0 | 0 | 0 |
R4 | 0 | 0 | 0.33 | 0.33 | 0.33 | 0 | 0 | 0 | 0 |
R5 | 0 | 0 | 0 | 0.33 | 0.33 | 0.33 | 0 | 0 | 0 |
R6 | 0 | 0 | 0 | 0 | 0.33 | 0.33 | 0.33 | 0 | 0 |
R7 | 0 | 0 | 0 | 0 | 0 | 0.33 | 0.33 | 0.33 | 0 |
R8 | 0 | 0 | 0 | 0 | 0 | 0 | 0.33 | 0.33 | 0.33 |
R9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.5 | 0.5 |
Now, solving Parts 1,2,3 and 4 in R:-
-----
install.packages("markovchain")
library("markovchain")
States = c("r1","r2","r3","r4","r5","r6","r7","r8","r9")
byRow = TRUE
sMatrix = matrix(data =
c(0.5,0.5,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.33,0.34,0.33,0,0,0,0,0,0,0,0.5,0.5),
byrow = byRow, nrow = 9,dimnames = list(states, states))
#inverse of transition matrix - required for Part 2
smi = solve(sMatrix)
mcrm = new("markovchain", states = States, byrow = byRow,
transitionMatrix = sMatrix, name = "Weather")
mcrmi = new("markovchain", states = States, byrow = byRow,
transitionMatrix = smi, name = "Weather")
## Part 1
initialState = c(30,40,0,0,10,0,0,20,0)
after1day = initialState*(mcrm)
data.frame(room_people = c(after1day))
# room_people
1 28.2
2 28.6
3 13.2
4 3.3
5 3.4
6 3.3
7 6.6
8 6.8
9 6.6
## Part 2
finalState = c(125,50,150,75,275,100,125,50,150)
### initialStateReqd = finalState*(mcrmi)
## Can't get answer of Part 2
## Part 3: All start at R1, time taken to 1st person in R9
initialState = c(100,0,0,0,0,0,0,0,0)
# taking that when total persons in any room > 0.5, there's a
person in that room:
after13days = initialState*(mcrm)^13
after15days = initialState*(mcrm)^15
### ANSWER: Takes 13 time periods (195 minutes) to get a person in
R9
### It takes 15 time periods (225 minutes) to be SURE that a person
is in R9
## Part 4: Allocation to be according to the steady state:-
data.frame(room_allocation = c(steadyStates(mcrm)))
# room_allocation
1 0.07932692
2 0.12019231
3 0.12019231
4 0.12019231
5 0.12019231
6 0.12019231
7 0.12019231
8 0.12019231
9 0.07932692