# Geometric Distribution - Snowboard

> This document is written in *R*.
>
> ***GitHub***: https://github.com/czs108

## Definition

\begin{equation}
P(X = r) = (1 - p)^{r - 1} \cdot p
\end{equation}

\begin{align}
X &= \text{The number of trials needed to get the first successful outcome.} \\
p &= \text{The probability of a success on an individual trial.}
\end{align}

If a variable $X$ follows a *Geometric Distribution* where the probability of *success* in a trial is $p$, this can be written as

\begin{equation}
X \sim Geo(p)
\end{equation}

For inequalities:

\begin{equation}
P(X > r) = (1 - p)^{r}
\end{equation}

In order for more than $r$ trials to be needed, this means that the first $r$ trials must have ended in *failure*. 

\begin{equation}
P(X \leq r) = 1 - (1 - p)^{r}
\end{equation}

### Expectation

\begin{equation}
E(X) = \frac{1}{p}
\end{equation}

### Variance

\begin{equation}
Var(X) = \frac{(1 - p)}{p^{2}}
\end{equation}

## Background

> The probability $p$ of a snowboarder making a successful run down the slope is **0.4**, and he's going to keep on trying until he succeeds, assuming trials are independent.


```R
p <- 0.4
count <- c(1:20)

probs <- ((1 - p) ^ (count - 1)) * p
probs
```


<ol class=list-inline>
	<li>0.4</li>
	<li>0.24</li>
	<li>0.144</li>
	<li>0.0864</li>
	<li>0.05184</li>
	<li>0.031104</li>
	<li>0.0186624</li>
	<li>0.01119744</li>
	<li>0.006718464</li>
	<li>0.0040310784</li>
	<li>0.00241864704</li>
	<li>0.001451188224</li>
	<li>0.0008707129344</li>
	<li>0.00052242776064</li>
	<li>0.000313456656384</li>
	<li>0.0001880739938304</li>
	<li>0.00011284439629824</li>
	<li>6.7706637778944e-05</li>
	<li>4.06239826673664e-05</li>
	<li>2.43743896004198e-05</li>
</ol>



Use the `dgeom` function directly where the `x` is the number of *failures* prior to the first success.


```R
dgeom(x=c(0:5), prob=p)
```


<ol class=list-inline>
	<li>0.4</li>
	<li>0.24</li>
	<li>0.144</li>
	<li>0.0864</li>
	<li>0.05184</li>
	<li>0.031104</li>
</ol>




```R
barplot(probs, xlab="Number of trials when getting the first success", ylab="Probability")
```

## Question A

What's the probability that he will be successful on his *2nd* attempt, while failing on his *1st*?

\begin{equation}
\begin{split}
P(X = 2) &= (1 - p) \cdot p \\
    &= 0.6 \times 0.4 \\
    &= 0.24
\end{split}
\end{equation}


```R
dgeom(x=1, prob=p)
```


0.24


## Question B

What's the probability that he will be successful in **4** attempts or *fewer*?

\begin{equation}
\begin{split}
P(X \leq 4) &= 1 - P(X > 4) \\
    &= 1 - (1 - p)^{4} \\
    &= 1 - 0.6^{4} \\
    &= 0.8704
\end{split}
\end{equation}


```R
sum(dgeom(x=c(0:3), prob=p))
```


0.8704


Or use the `pgeom` function.


```R
pgeom(q=3, prob=p)
```


0.8704


## Question C

What's the probability that he will need *more* than **4** attempts to be successful?

\begin{equation}
\begin{split}
P(X > 4) &= (1 - p)^{4} \\
    &= 0.6^{4} \\
    &= 0.1296
\end{split}
\end{equation}

## Question D

What's the number of attempts he *expects* he'll need to make before being successful?

\begin{equation}
\begin{split}
E(X) &= \frac{1}{p} \\
    &= \frac{1}{0.4} \\
    &= 2.5
\end{split}
\end{equation}


```R
mean <- sum(count * probs)
mean
```


2.49917736435099


## Question E

What's the *variance* of the number of attempts?

\begin{equation}
\begin{split}
Var(X) &= \frac{(1 - p)}{p^2} \\
    &= \frac{0.6}{0.4^2} \\
    &= 3.75
\end{split}
\end{equation}


```R
var <- sum(((count - mean) ^ 2) * probs)
var
```


3.73523773392841


d584a8b6cff2feef4479808e3efc6cf6c2c9cb76
ipynb
Jupyter Notebook
exercises/Geometric Distribution - Snowboard.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
exercises/Geometric Distribution - Snowboard.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
exercises/Geometric Distribution - Snowboard.ipynb
czs108/Probability-Theory-Exercises
60c6546db1e7f075b311d1e59b0afc3a13d93229
MIT
2022-03-21T05:04:07.000Z
2022-03-21T05:04:07.000Z
Qwen/Qwen-72B
1. YES
2. YES