Smith is in jail and has 1 dollar; he can get out on bail if he has 8
dollars. A guard agrees to make a series of bets with him. If Smith bets
A dollars, he wins A dollars with probability .4 and loses A dollars
with probability .6.
Find the probability that he wins 8 dollars before losing all of his
money if:
possible_outcomes = c('0','1','2','3','4','5','6','7','8')
#$0 to $8 to get out of jail
transit_matrixA = matrix(c(1,0,0,0,0,0,0,0,0,
0.6,0,0.4,0,0,0,0,0,0,
0,0.6,0,0.4,0,0,0,0,0,
0,0,0.6,0,0.4,0,0,0,0,
0,0,0,0.6,0,0.4,0,0,0,
0,0,0,0,0.6,0,0.4,0,0,
0,0,0,0,0,0.6,0,0.4,0,
0,0,0,0,0,0,0.6,0,0.4,
0,0,0,0,0,0,0,0,1),
byrow = T, nrow = 9,
dimnames = list(possible_outcomes,possible_outcomes))
print(transit_matrixA)
## 0 1 2 3 4 5 6 7 8
## 0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
## 1 0.6 0.0 0.4 0.0 0.0 0.0 0.0 0.0 0.0
## 2 0.0 0.6 0.0 0.4 0.0 0.0 0.0 0.0 0.0
## 3 0.0 0.0 0.6 0.0 0.4 0.0 0.0 0.0 0.0
## 4 0.0 0.0 0.0 0.6 0.0 0.4 0.0 0.0 0.0
## 5 0.0 0.0 0.0 0.0 0.6 0.0 0.4 0.0 0.0
## 6 0.0 0.0 0.0 0.0 0.0 0.6 0.0 0.4 0.0
## 7 0.0 0.0 0.0 0.0 0.0 0.0 0.6 0.0 0.4
## 8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0
Now that we have the transition matrix, we can calculate the probability of this strategy.
library(markovchain)
## Package: markovchain
## Version: 0.9.5
## Date: 2023-09-24 09:20:02 UTC
## BugReport: https://github.com/spedygiorgio/markovchain/issues
markovA <- new("markovchain", states = possible_outcomes, transitionMatrix = transit_matrixA)
absorptionProbabilities(markovA)
## 0 8
## 1 0.9796987 0.02030135
## 2 0.9492466 0.05075337
## 3 0.9035686 0.09643140
## 4 0.8350515 0.16494845
## 5 0.7322760 0.26772403
## 6 0.5781126 0.42188739
## 7 0.3468676 0.65313243
The probability that we reach $8 using this timid strategy is represented by the first row of the absorption probabilities: 0.02030135 or 2.03%
possible_outcomes = c('0','1','2','3','4','5','6','7','8')
#$0 to $8 to get out of jail
transit_matrixB = matrix(c(1,0,0,0,0,0,0,0,0,
0.6,0,0.4,0,0,0,0,0,0,
0.6,0,0,0,0.4,0,0,0,0,
0.6,0,0,0,0,0,0.4,0,0,
0.6,0,0,0,0,0,0,0,0.4,
0,0,0.6,0,0,0,0,0,0.4,
0,0,0,0,0.6,0,0,0,0.4,
0,0,0,0,0,0,0.6,0,0.4,
0,0,0,0,0,0,0,0,1),
byrow = T, nrow = 9,
dimnames = list(possible_outcomes,possible_outcomes))
print(transit_matrixB)
## 0 1 2 3 4 5 6 7 8
## 0 1.0 0 0.0 0 0.0 0 0.0 0 0.0
## 1 0.6 0 0.4 0 0.0 0 0.0 0 0.0
## 2 0.6 0 0.0 0 0.4 0 0.0 0 0.0
## 3 0.6 0 0.0 0 0.0 0 0.4 0 0.0
## 4 0.6 0 0.0 0 0.0 0 0.0 0 0.4
## 5 0.0 0 0.6 0 0.0 0 0.0 0 0.4
## 6 0.0 0 0.0 0 0.6 0 0.0 0 0.4
## 7 0.0 0 0.0 0 0.0 0 0.6 0 0.4
## 8 0.0 0 0.0 0 0.0 0 0.0 0 1.0
Now that we have the transition matrix, we can calculate the probability of this strategy.
markovB <- new("markovchain", states = possible_outcomes, transitionMatrix = transit_matrixB)
absorptionProbabilities(markovB)
## 0 8
## 1 0.936 0.064
## 2 0.840 0.160
## 3 0.744 0.256
## 4 0.600 0.400
## 5 0.504 0.496
## 6 0.360 0.640
## 7 0.216 0.784
The probability that we reach $8 using this bold strategy is represented by the first row of the absorption probabilities: 0.064 or 6.4%