Examples
\begin{xmpl}
Suppose we toss a coin, with probability $p$ of landing on heads $n$ times obtaining a sequence of Hs (when it lands heads) and Ts (when it lands tails). Any sequence,
$$
HTH...HTHHH
$$
which has $x$ heads ($H$) and $n-x$ tails ($T$), has the probability $p^x(1-p)^{n-x}$. There are exactly $\binom{n}{x}$ such sequences, so the total probability of landing $x$ heads in $n$ tosses is
$$
\binom{n}{x}p^x(1-p)^{n-x}.
$$
\end{xmpl}
\begin{xmpl}
Let the probability that a certain football club wins a match be equal to 0.4.If the total number of matches played in the season is 30, what is the probability that the football club wins the match 10\% of the time?\\
We first calculate the number of times a match was played and won by multiplying the percentage of wins by the number of matches played.\\
10\% of 30 times = 3 times\\
We can now proceed to calculate the probability that they will win the match given that their probability of a winning is 0.4 if they play 3 times in a season. This can be computed as follows:\\
$$\binom{30}{3} \times (0.4)^3 \times (1-0.4)^{30-3} $$
$$=0.000265$$\\
This can be calculated in R using the code below:
\begin{lstlisting}
dbinom(3,30,0.4)
[1] 0.0002659437
\end{lstlisting}
This is equal to the manual calculation using the binomial theorem.
\end{xmpl}
\begin{xmpl}
Suppose a youngster puts his shirt on by himself every day for five days. The probability that he puts it on the right way each time is $p=0.2$. We let $X$ be a random variable that describes the number of times the youngster puts his shirt on the right way. The youngster can either put the shirt on the wrong or the right way so $X$ follows the binomial distribution with the parameters $p=0.2$ (the probability of a successful trial) and $n=5$ (number of trials). We can now calculate for example the probability that the youngster will put it on the right way for at least 4 days.\\
Putting the shirt on the right way for at least 4 days means that the youngster will either put it on the right way for either four or five days (at least four or more days of five days total). We thus have to calculate the probability that the youngster will put his shirt on the right way for 4 and 5 days separately and then we add it together. We can write this process as follows:
$$P(X\geq4) = P(X=4) + P(X=5)$$
$$= \binom{5}{4}\times0.2^4\times(1-0.2)^{5-4} + \binom{5}{5}\times0.2^5\times(1-0.2)^{5-5}$$
$$= 5\times0.2^4\times0.8^1 + 1\times0.2^5\times0.8^0$$
$$= 5\times0.2^4\times0.8 + 0.2^5\times1$$
$$= 5\times0.8 \times0.2^4 + 0.2^5 $$
$$= 4\times0.2^4 + 0.2^5$$
$$= 4\times0.0016 + 0.00032$$
$$= 0.00672$$
The probability that the youngster will put his shirt on the right way for at least four out of five is thus 0,7\%.\\
This is possible to calculate in R in a several ways, either using the command dbinom or pbinom. The command dbinom calculates $$P(X = k)$$ and the command pbinom calculates $$P(X \leq k)$$ where $k$ is the number of successful trials. If $n$ is the number of trials and $p$ is the probability of a successful trials then the commands are used by writing: $dbinom$($k$,$n$,$p$) and pbinom($k$,$n$,$p$).\\
To calculate the probability that the youngster will put his shirt on the right way for at least four days of five we thus write the command:
\begin{lstlisting}
dbinom(4,5,0.2) + dbinom(5,5,0.2)
\end{lstlisting}
which gives 0.00672.\\
This is the same as writing:
\begin{lstlisting}
dbinom(c(4,5),5,0.2)
\end{lstlisting}
or
\begin{lstlisting}
dbinom(4:5,5,0.2)
\end{lstlisting}
which give two separate numbers: 0.00640 and 0.00032 which can be added together to get 0.00672.\\
There is also a command to add them together for us:
\begin{lstlisting}
sum(dbinom(c(4,5),5,0.2))
\end{lstlisting}
or
\begin{lstlisting}
sum(dbinom(4:5,5,0.2))
\end{lstlisting}
They give the answer 0.00672.\\
The fourth way of calculating this in R is to use pbinom. As said before pbinom calculates $$P(X \leq k)$$ where $k$ is the number of successful trials. Here we want to calculate the probability that the youngster will put his shirt on the right way in 4 or 5 times (of 5 total) so the number of successful trials is 4 or greater. That means we want to calculate $$P(X \geq 4)$$ which equals $$1 - P(X \leq 3)$$. We thus put $k$ as 3 and the R command will be:
\begin{lstlisting}
1 - pbinom(3,5,0.2)
\end{lstlisting}
which also gives 0.00672.
\end{xmpl}
\begin{xmpl}
In a certain degree program, the chance of passing an examination is 20\%. What is the chance of passing at most 2 exams if the student takes five exams?\\
Solution:\\
In this problem, we compute the chance of a student passing, 0.1 or 2 exams.This is given by,
$$p(X=0 \text{ or }1 \text{ or }2)={5\choose 0}0.2^0 0.8^5 +{5\choose 1}0.2^1 0.8^4 +{5\choose 2}0.2^2 0.8^3 $$
$$=1\times0.2^0 0.8^5 +5\times 0.2^1 0.8^4 +10\times0.2^2 0.8^3 $$
$$=0.32768+0.4096+0.2048$$
$$=0.94208$$
In the R console, we can use the command,
$\verb|sum(dbinom(c(0:2),5,0.2))|$,
which also gives $$0.94208.$$
The same answer is obtained with
\begin{lstlisting}
dbinom(0,5,0.2)+dbinorm(1,5,0.2)+dbinom(2,5,0.2)
\end{lstlisting}
and with
\begin{lstlisting}
pbinom(2,5,0.2)
\end{lstlisting}
\end{xmpl}
\begin{xmpl}
Consider the probability of someone jumping off a cliff is 0.35. Suppose we randomly selected four individuals to participate in the cliff jumping activity.
What is the chance that exactly one of them will jump off the cliff?\\
Consider a scenario where one person jumps:\\
P (A =jump , B = refuse, C = refuse, D = refuse)
= P (A =jump) P (B = refuse) P (C = refuse) P (D = refuse)
$= (0.35)(0.65)(0.65)(0.65) = (0.35)^1 (0.65)^3 = 0.096$\\
But there are three other scenarios( B, C, or D) in which one only person decides to jump. In each of these cases, the probability is again 0.096. These four scenarios exhaust all the possible ways that exactly one of the four people jumps:
$4 \cdot (0.35)^1 (0.65)^3 = 0.38.$\\
In the R console we can use the command:
$\verb|dbinom(1,4,0.35)|$
which gives the answer as 0.384475.
\end{xmpl}