Sunday, July 18, 2021

But are Fetch and Fitch also Dalmations?

I have three dogs: Fatch, Fetch and Fitch. Yesterday, I found a brown 12-inch stick for them to play with. I marked the top and bottom of the stick and then threw it for Fatch. Fatch, a Dalmatian, bit it in a random spot — leaving a mark — and returned it to me. In her honor, I painted the stick black from the top to the bite and white from the bottom to the bite.

I subsequently threw the stick for Fetch and then for Fitch, each of whom retrieved the stick by biting a random spot. What is the probability that Fetch and Fitch both bit the same color (i.e., both black or both white)?

Let's denote the random spot (measured in feet from the bottom of the stick) where Fatch the Dalmatian and Fetch and Fitch of unknown breed bit the stick as $A$, $E$ and $I$, where each can now be modeled as i.i.d. uniform random variables on $[0,1].$

Once Fatch has returned the stick with say $A = a$ for some $a \in [0,1],$ by the independence of $E$ and $I,$ we can calculate \begin{align*}\mathbb{P} \{ \text{same color} \mid A = a \} &= \mathbb{P} \{ E, I \in [0,a] \} + \mathbb{P} \{E, I \in [a,1]\} \\ &= \mathbb{P} \{ E \in [0,a] \} \mathbb{P} \{ I \in [0,a] \} + \mathbb{P} \{ E \in [a,1] \} \mathbb{P} \{ I \in [a,1] \}\\ &= a^2 + (1-a)^2.\end{align*} So if we integrate over all the possible Fatch the Dalmatian bite marks, we get the probability that Fetch and Fitch bite the same colored portion of the stick as $$\mathbb{P} \{ \text{same color} \} = \int_0^1 \mathbb{P} \{ \text{same color} \mid A = a \} \, da = \int_0^1 a^2 + (1-a)^2 \,da = \frac{2}{3}.$$ However, we are still no closer to divining the breed of Fetch and Fitch.

If I were to get more dogs of unknown parentage, say $n,$ then (a) I would likely eventually run of out vowels in order to fit the naming F*tch naming convention, but also (b) end up with a probability that all of then would bite in the same color of $$\mathbb{P} \{ n \,\text{bites in same color} \} = \int_0^1 a^n + (1-a)^n \,da = \frac{2}{n+1}.$$ If I went full Cruella and secured $100$ dogs of unknown breed and $1$ Dalmatian, the probability that all $100$ dogs after Fatch would bite in the same color would be a not insignificant $\frac{2}{101} = 1.98\%.$

Shootout at the UP Corral

Italy defeated England in a heartbreaking (for England) European Championship that came down to a penalty shootout. In a shootout, teams alternate taking shots over the course of five rounds. If, at any point, a team is guaranteed to have outscored its opponent after five rounds, the shootout ends prematurely, even if each side has not yet taken five shots. If teams are tied after five rounds, they continue one round at a time until one team scores and another misses. If each player has a 70 percent chance of making any given penalty shot, then how many total shots will be taken on average?

Let $p = 0.7$ be the probability of each individual penalty shot going in. The setup of the penalty shootout lends itself to simulation, so in a moment I will fire up the old Jupyter notebook and get busy simulating since $2^{10} = 1024$ possible outcomes for the just the first $5$ rounds and I don't want to sort it all out by hand, but I will tackle part of it analytically.

Let's assume that the first $10$ penalties have ended in a tie and we are going into sudden death rounds. In this case, there will always be a multiple of $2$ shots since the first team to shoot cannot conclusively win after its shot alone. Since the shootout can only end once a round where one team scores and the other doesn't, we see that $$\mathbb{P} \{ N = 10+2k \mid N > 10 \} = 2p(1-p) (1 - 2p(1-p))^{k-1}.$$ So in particular, we have $$\mathbb{E} [ N \mid N > 10 ] = \sum_{k=1}^\infty (10 + 2k) 2p(1-p) (1 - 2p(1-p))^{k-1} = 10 + \frac{1}{p(1-p)}.$$ We can use this to simulate only the first 5 rounds of the shootout and for every simulation where the score at the end of 10 kicks is tied, we can put in the expected number of kicks in this case.

I drew a $2 \times 5$ array of Bernoulli random variables with probability $p$ and used the $1$'s as goals and $0$'s as misses. For each draw, we can determine how many kicks were needed to win the shootout (substituting the expected number of $10 + \frac{1}{p(1-p)}$ if the first 10 shots end in a tie). The average number of shots in the penalty shootout (using 100,000 simulations) is $13.02$ shots. See the Python snippet below:

SoccerIsDumbWhyNotJustKeepPlaying
In [1]:
import numpy as np
import pandas as pd
from scipy.stats import bernoulli

def num_kicks(u, max_kicks=5):
    i = 0
    stop = False
    while not stop:
        if u[i,0] > u[i,1] + (5-i):
            num_kicks = 2 * i + 1
            stop = True
        elif u[i,1] > u[i,0] + (4-i):
            num_kicks = 2 * (i + 1)
            stop = True
        elif i==max_kicks-1:
            num_kicks = 2*max_kicks+1
            stop = True
        else:
            i += 1
    return num_kicks

def calculate_mean_kicks(p, max_kicks=5, num_sims=100000):
    u = bernoulli.rvs(p, size=(max_kicks,2,num_sims))
    kicks = { k:0 for k in range(1,2 * max_kicks+2)}
    for s in range(num_sims):
        tmp = np.cumsum(u[:,:,s], axis=0)
        kicks[num_kicks(tmp,max_kicks=max_kicks)] += 1

    mean = 0
    for k, v in kicks.items():
        if k < 2 * max_kicks:
            mean += k * v
        else:
            ## The conditional expected number of kicks given that the first 10 are tied is 
            ## given by \sum_{k=1}^\infty (2*max_kicks+2*k) 2*p*(1-p)*(1-2*p*(1-p))^k = 2*max_kicks + 1/(p*(1-p))
            mean += (10 + 1/(p*(1-p))) * v
    mean /= num_sims
    print('The expected number of kicks in a penalty shootout with p={} goal probability is N={}'.format(p, mean))
    return mean

calculate_mean_kicks(0.7)
The expected number of kicks in a penalty shootout with p=0.7 goal probability is N=13.018944285714287
Out[1]:
13.018944285714287