-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b746516
commit 02bcefb
Showing
11 changed files
with
1,018 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
--- | ||
title: "Gambler's Ruin" | ||
subtitle: Simulations with R | ||
author: DragonflyStats.github.io | ||
output: | ||
prettydoc::html_pretty: | ||
theme: cayman | ||
highlight: github | ||
--- | ||
|
||
|
||
\section{Gambler's Ruin} | ||
|
||
Consider a gambler who starts with an initial fortune of \$1 and then on each successive gamble | ||
either wins \$1 or loses \$1 independent of the past with probabilities p and q = 1-p respectively. | ||
|
||
Suppose the gambler has a starting kitty of A. | ||
This gamblers places bets with the “Banker”, who has an initial fortune B. We will look at the game from the perspective of the gambler only. | ||
The Banker is, by convention, the richer of the two. | ||
|
||
\begin{itemize} | ||
\item Probability of successful gamble for gambler : p | ||
\item Probability of unsuccessful gamble for gambler : q (where q = 1 - p ) | ||
\item Ratio of success probability to failure success: $s = p / q$ | ||
\item Conventionally the game is biased in favour of the Banker (i.e. $q>p$ and $s<1$) | ||
\end{itemize} | ||
|
||
Let $R_n$ denote the Gambler’s total fortune after the $n-$th gamble. | ||
|
||
If the Gambler wins the first game, his wealth becomes $R_n =A+1$. | ||
If he loses the first gamble, his wealth becomes $R_n = A-1$. | ||
The entire sum of money at stake is the “Jackpot” i.e. $A+B$. | ||
The game ends when the Gambler wins the Jackpot ($R_n = A+B$) or loses everything ($R_n = 0$). | ||
|
||
|
||
### Simulation a Single Gamble} | ||
|
||
|
||
To simulate one single bet, compute a single random number between 0 and 1. | ||
```{r} | ||
runif(1) | ||
``` | ||
|
||
|
||
Lets assume that the game is biased in favour of the Banker | ||
p = 0.45 , q = 0.55. | ||
If the number is less than 0.45, the gamble wins. Otherwise the Banker wins. | ||
|
||
|
||
> runif(1) | ||
[1] 0.1251274 | ||
>#Gambler Loses | ||
> | ||
> runif(1) | ||
[1] 0.754075 | ||
>#Gambler wins | ||
> | ||
> runif(1) | ||
[1] 0.2132148 | ||
>#Gambler Loses | ||
> | ||
> runif(1) | ||
[1] 0.8306269 | ||
``` | ||
%----------------------------------------------------------------------% | ||
\newpage | ||
Let A be the Gambler's Kitty at the start of the gambling. | ||
Let B be the Banker's Wealth. | ||
The probability of A winning a gamble is p. | ||
The vector $R_n$ records the gambler's worth on an ongoing basis. At the start, The first value is A. | ||
```{r} | ||
A=20;B=100;p=0.47 | ||
Rn=c(A) | ||
probval = runif(1) | ||
if (probval < p) | ||
{ | ||
A = A+1; B =B-1 | ||
}else{A=A-1;B=B+1} | ||
#Save the values from each bet | ||
Rn=c(Rn,A) | ||
``` | ||
|
||
\newpage | ||
Should the Gambler win the entire jackpot (A+B). The game would also cease. We include a \textbf{\texttt{break}} statement to stop the loop if the gambler wins the entire jackpot. A break statement will stop a loop if a certain logical condition is met. | ||
|
||
```{r} | ||
A=20;B=100;p=0.47 | ||
Rn=c(A) | ||
Total=A+B | ||
while(A>0) | ||
{ | ||
UnifVal=runif(1) | ||
if(UnifVal <= p) | ||
{ | ||
A = A+1; B =B-1 | ||
}else{A=A-1;B=B+1} | ||
Rn=c(Rn,A) | ||
if(A==Total){break} | ||
} | ||
``` | ||
|
||
We can construct a plot to depict the gambler's ongoing fortunes in the game. We use a \texttt{for} loop, that implements the game, recording the duration of the game each time. The duration of each game is the dimension of the \texttt{Rn} vector, i.e. \texttt{length(Rn)}. | ||
|
||
|
||
```{r} | ||
A.ini=20;B=100;p=0.47 | ||
M=1000 | ||
RnDist=numeric() | ||
Total=A+B | ||
for (i in 1:M) | ||
{ | ||
Rn=numeric() | ||
Rn[1]=A | ||
A=A.ini | ||
while(A>0) | ||
{ | ||
UnifVal=runif(1) | ||
if(UnifVal <= p) | ||
{ | ||
A = A+1; B =B-1 | ||
}else{A=A-1;B=B+1} | ||
Rn=c(Rn,A) | ||
if(A==Total){break} | ||
} | ||
RnDist=c(RnDist,length(Rn)) | ||
} | ||
``` | ||
|
||
### Distribution of Durations} | ||
We can use for loop to get a sense of the duration (i.e. the number of rounds a game will last). | ||
\newpage | ||
\end{document} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Probability/PREPAREA/rsconnect/documents/Monty_Hall_Problem.Rmd/rpubs.com/rpubs/Document.dcf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Document | ||
title: | ||
username: | ||
account: rpubs | ||
server: rpubs.com | ||
hostUrl: rpubs.com | ||
appId: https://api.rpubs.com/api/v1/document/1104051/9fc3555f99504a54b62bbc8adaf7d53b | ||
bundleId: https://api.rpubs.com/api/v1/document/1104051/9fc3555f99504a54b62bbc8adaf7d53b | ||
url: http://rpubs.com/publish/claim/1104051/ca2a8a184dd94c818f5a6e64654bf1e2 | ||
when: 1698175835.74178 | ||
lastSyncTime: 1698175835.74178 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
325 changes: 95 additions & 230 deletions
325
Statistics/01-ModellingCountVariables/22-Fishing-ZeroInflatedPoisson.html
Large diffs are not rendered by default.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...ables/rsconnect/documents/22-Fishing-ZeroInflatedPoisson.Rmd/rpubs.com/rpubs/Document.dcf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Document | ||
title: | ||
username: | ||
account: rpubs | ||
server: rpubs.com | ||
hostUrl: rpubs.com | ||
appId: https://api.rpubs.com/api/v1/document/1104046/5e16dd3951c6407faab922c4597345a2 | ||
bundleId: https://api.rpubs.com/api/v1/document/1104046/5e16dd3951c6407faab922c4597345a2 | ||
url: http://rpubs.com/publish/claim/1104046/93a72405f50c43f0bbbfa41b8bd33469 | ||
when: 1698175575.65415 | ||
lastSyncTime: 1698175575.65415 |
Oops, something went wrong.