6
$\begingroup$

You have a biased coin, where the probability of flipping a head is 0.70. You flip once, and the coin comes up tails. What is the expected number of flips from that point (so counting that as flip #0) until the number of heads flipped in total equals the number of tails?

My approach is wrong but I don't understand why!!!

$x=0.7(1)+0.3(1+x)≈1.43$.

with 0.5 we get a head and we are done in 1 flip. with 0.5 we get an additional tail and so we will have made 1 flip but then we will need to repeat X.

Could you please explain clearly Markov chains. I am not very good at it.

$\endgroup$
6
  • 4
    $\begingroup$ $\frac{1}{2}$ doesn't come into the picture with this unfair coin. $\endgroup$ Commented Sep 9, 2021 at 13:00
  • $\begingroup$ If the coin were a fair coin, then you would have a 50/50 shot at getting heads on the first toss. This coin is not fair. As a Markov chain, it seems that the states represent the possible discrepancy between heads and tails. You start with 1 extra tails. Each time you flip the coin, a heads moves you to a state with one fewer extra tails, and a tails moves you to a state with one more extra tails. What are the transition probabilities? How many possible states are there? How can you use this to compute the expected number of tosses until you get to the state with no excess tails? $\endgroup$ Commented Sep 9, 2021 at 13:51
  • $\begingroup$ I'm guessing you can't just do: $1 + 0.3x = 0.7x \implies x = 2.5.$ $\endgroup$ Commented Sep 9, 2021 at 14:01
  • $\begingroup$ Hi guys. Yes, what I meant was actually $x= 0.7(1) + 0.3(1+x) \approx 1.43$. But from what I know, this is not correct. The correct answer should be the one of @AdamRubinson but I really do not understand why. Could you please explain it in a different way, maybe easier for someday who is not very good with markov chains? $\endgroup$ Commented Sep 9, 2021 at 15:23
  • $\begingroup$ @Adam Rubinson: What's wrong with it? After $n$ tosses, the expected number of heads is $0.7n$ and that of tails is $0.3n$. As tails is given a head start of 1, $n$ is determined by $0.7n=1+0.3n$, thus $n=2.5$. $\endgroup$ Commented Sep 9, 2021 at 16:44

4 Answers 4

2
$\begingroup$

The expected number of flip is where the expected number head ($0.7x$) and the expected number of tail ($1+0.3x$) are equal so that's why it's $2.5$.

You're wrong because you forgot to consider the fact that when the tail is flipped, you need to repeat the process twice for the head to catch up, not once. The correct formula is $x=0.7(1)+0.3(1+2x)$ which give the correct answer.

$\endgroup$
2
  • 1
    $\begingroup$ The result is correct, but I would like to comment that there is a slight difference between "at what time is the expected number of tails and heads equal" and "what is the expected time at which the numbers of heads and tails are equal". The process in this question is simple enough that these two are the same, but there is something slightly non-trivial to prove (and for more complicated processes it actually fails) $\endgroup$ Commented Sep 9, 2021 at 16:38
  • $\begingroup$ @duck. Very nice explanation. Just to make sure I understood. Let's say that I am 2 tails down and the game ends when Heads = (Tails + 1). would the equation be $\rightarrow$ $1+07x = 0.3x+2$ ? $\endgroup$ Commented Sep 9, 2021 at 16:42
2
$\begingroup$

I have used a different method for confirmation, converting a straight line to a $2D$ lattice path.

  • Number of tosses taken has to be of the form $(2k+1)$, i.e. odd

  • $k$ can range from $0$ to $\infty$

  • in $(2k+1)$ tosses, there will be $(k+1)$ "$p\;$steps" and $\;k\;$ "$q$ steps" $(p= 0.7)$
    $$\text{Thus the formula} = \sum_{k=0}^\infty \binom{2k+1}{k+1}p^{k+1}q^k$$

Wolfram shows that the sum converges,

and confirms the answer $= 2.5$

PS: Explanation of the Formula

The basic idea is to conceive the problem as one of a $2D$ lattice path rather than a straight line.

If equality is achieved at the $(2k+1)^{\text{th}}$ toss, the first $2k$ tosses must be such that the number of heads is always strictly less than tails till that point, and equality achieved only on the last toss. The number of such arrangements is the well known Catalan Number and is equal to $\dfrac{1}{k+1}\dbinom{2k}{k}$.

Thus with equality being achieved at the $(2k+1)^{th}$ toss, the expected number of tosses is:

$$ = \sum_{k=0}^{\infty}\frac{2k+1}{k+1}\binom{2k}{k}0.7^{k+1}0.3^{k}$$

which further simplifies to the formula used in the body.

$\endgroup$
16
  • $\begingroup$ I think you're forgetting the binomial coefficient ${2k+1 \choose k+1}$ in your formula for the probability. $\endgroup$ Commented Sep 9, 2021 at 18:01
  • $\begingroup$ @MatthewPilling: Thanks, omission rectified :-} $\endgroup$ Commented Sep 9, 2021 at 18:14
  • $\begingroup$ Why is there a downvote ? Is there anything wrong in the process ? $\endgroup$ Commented Sep 10, 2021 at 7:27
  • $\begingroup$ I see a few issues. One, the third bullet is technically wrong. Two, the third bullet has no explanation (the explanation being that you have $2k+1$ flips, $k+1$ of which are heads and $k$ of which are tails). Three, it's not obvious why you can add these probabilities up, since it's not obvious that you're not double counting any processes that actually terminated earlier. $\endgroup$ Commented Sep 10, 2021 at 14:22
  • $\begingroup$ @Ian 1: Thanks for your comment. I have tried to improve the presentation. Re the main point about possibility of double counting, some years back, I had by serendipity hit upon a way of converting a straight line walk to a $2D$ lattice formula, summing up to infinity. However, I am a tyro in this field, so I welcome any further observations you have. You are also free to edit the answer to remove any inadequacies that you still see. $\endgroup$ Commented Sep 10, 2021 at 16:20
2
$\begingroup$

The accepted answer gets the correct result largely by coincidence. There is not a priori any relationship between the time when the expected number of heads and tails are equal vs. the expected time when the number of heads and tails are equal, and the latter is what is asked for.

You first convert to a random walk: look at the number of tails minus the number of heads and then the walk starts at $1$, moves right with probability $0.3$ and moves left with probability $0.7$. Now the expected time for the walk to net-move one step to the left can be determined by conditioning on the first step. If you move left in the first step, then the time is just $1$. If you move right in the first step, then you now need to net-move two steps to the left, which takes on average twice as long as net-moving one step to the left. Therefore using the total expectation formula,

$$E[T]=0.7 \cdot 1 + 0.3 \cdot (1+2E[T])=1+0.6E[T].$$

Solving for $E[T]$ you get $\frac{1}{0.4}=\frac{5}{2}$.

Another way to proceed, which can be applied in a wider variety of problems, is to use the same random walk but now consider starting at any $n \geq 0$ and compute the expected times $T(n)$ to hit $0$ starting from all such $n$ together. To do this you apply the total expectation formula to get the recursive relation

$$T(n)=1+0.3 T(n+1)+0.7T(n-1).$$

You can find the general homogeneous solution to this recurrence which is given by $T(n)=c_1 \lambda_1^n + c_2 \lambda_2^n$ where $\lambda_1,\lambda_2=\frac{1 \pm \sqrt{1-4 \cdot 0.3 \cdot 0.7}}{0.6}=\frac{1 \pm 0.4}{0.6}=1,\frac{7}{3}$.

A particular solution can be obtained by the method of undetermined coefficients; you can guess $T(n)=cn$ which yields $cn=1+0.3c(n+1)+0.7c(n-1)=1+cn-0.4c$ yielding $c=5/2$. So the general solution is $T(n)=\frac{5}{2}n + c_1 + c_2 \left ( \frac{7}{3} \right )^n$.

Now clearly $T(0)=0$, which implies that we have $T(n)=\frac{5}{2} n + c \left ( \left ( \frac{7}{3} \right )^n - 1 \right )$ for some $c$.

Now we want $T(1)$, and $T(1)$ actually depends on $c$, so we need to figure out what $c$ is. This is a bit subtle, since it's not obvious that we have any other boundary condition in the problem. One technique for circumventing this is to consider artificially stopping the process when the state $N>0$ is reached and then send $N \to \infty$ to "suppress" the artificial termination scenario. Thus we consider setting $T(N)=0$ also.

Proceeding in this manner you obtain the equation $\frac{5}{2} N + c \left ( \left ( \frac{7}{3} \right )^N-1 \right )=0$, and so $T(n)=\frac{5}{2} n - \frac{\frac{5}{2} N}{(7/3)^N-1} \left ( (7/3)^n-1 \right )$. Then $T(1)=\frac{5}{2} - \frac{\frac{5}{2} N}{(7/3)^N-1} \frac{4}{3} \to \frac{5}{2}$ as $N \to \infty$.

The one tricky matter in making this latter argument rigorous is to ensure that the probability that a path terminates at $N$ decays faster than the growth of an average length of a path that terminates at $N$.

$\endgroup$
1
$\begingroup$

This is an interesting problem and all the above solutions I think can be obtained using the law of the total expectation, with an assumption that the expected number of flips gets doubled when we have an additional tail to start with.

Let $X$ be the r.v. denoting the number of flips required. Also let's define a r.v $Y$ denoting the first flip after the initial tail.

Now, we have,

$E[X|Y=H]=1$

$E[X|Y=T]=1+2E[X]$

with an assumption that we need to double the number of required flips if we get an additional T (but is the assumption correct?)

Now, by law of total expectation, we have,

$E[X]=E[E[X|Y]]=P(Y=H)E[X|H]+P(Y=T)E[X|T]=p.1+(1-p)(1+2E[X])$

$\implies E[X] = \frac{1}{2p-1}=2.5$, when we have $p=P(Y=H)=0.7$.

Now, let's consider the following Markov chain (which looks like the Gambler's ruin or the birth-death process, but it's not finite, can be extended indefinitely to the right and there is no absorbing state).

enter image description here

  • A state in the chain is represented as the difference in number of tails and heads (#T - #H) in the coin-tossing experiment.

  • We start at state $1$ (one single tail) and want to compute the expected time to reach state $0$ (equal heads and tails).

  • When a head shows up in the coin flip we move to the immediate left state with transition probability $p$ (except for state 0) and if a tail shows up we move to the immediate right state with transition probability $1-p$.

  • Note that the chain is not finite, there is no last state to the right.

  • In this scenario, the problem gets reduced to computing the hitting time from state $1$ to state $0$.

  • In general hitting time $x_n$ from state $n$ to state $0$ can be represented as the following recurrence relation:

    $x_n=1+px_{n-1}+(1-p)x_{n+1}$, with $x_0=0$.

  • We are interested to compute $x_1$.

  • The above is a non-homogeneous recurrence relation $(1-p)x_{n+1}-x_n+px_{n-1}=-1$ and let's solve the homogeneous version of it first, which has characteristic equation as $(1-p)\lambda^2-\lambda+p=0$, with roots $1, \frac{p}{1-p}$, so that the homogeneous solution is:

    $x_h=A\left(\frac{p}{1-p}\right)^n+B.1^n$

  • Now, let's guess a particular solution $x_p=Cn$, s.t., plugging it into the non-homogeneous equation with some algebra, we get $C=\frac{1}{2p-1}$ and $x_p=\frac{n}{2p-1}$, s.t., the solution is

    $x_n=x_h+x_p=A\left(\frac{p}{1-p}\right)^n+B.1^n+\frac{n}{2p-1}$.

  • Note that the particular solution $x_p=\frac{5}{2}$, for $n=1$.

  • With boundary condition $x_0=0$, we get

    $x_n=x_h+x_p=A\left(\left(\frac{p}{1-p}\right)^n-1\right)+\frac{n}{2p-1}$

  • For $p=0.7$, $x_n=A\left(\left(\frac{7}{3}\right)^n-1\right)+\frac{5n}{2}$.

  • If we have an additional boundary condition for the rightmost state $T$ as $x_T=0$ as we have in birth-date process etc., we have $A=-\frac{\frac{5T}{2}}{\left(\left(\frac{7}{3}\right)^T-1\right)}$, but such a state can't exist for a finite $n$, i.e. $T = \infty$ and the limiting value of $A$ at $T \to \infty$ is $0$, i. e., $\lim\limits_{T\to\infty}A=0$.

  • Now, $x_1=\frac{4A}{3}+\frac{5}{2}$.

  • Letting $A=0$, we get back our earlier solution $x_1=\frac{5}{2}=2.5$

The following simulation in R supports the above fact:

set.seed(123) N <- 10000 ns <- replicate(N, { n <- 0 nT <- 1 nH <- 0 while (nT != nH) { toss <- sample(0:1, 1, prob = c(0.3, 0.7)) if (toss == 1) { nH <- nH + 1 } else { nT <- nT + 1 } n <- n + 1 } n }) mean(ns) #[1] 2.493 

with the following histogram of the hitting time for $x_1$.

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ I think you have the role of heads and tails in the problem mixed up; here you start out with a bias in favor of tails and the coin itself is biased in favor of heads, so the process tends to terminate. $\endgroup$ Commented Sep 9, 2021 at 22:36
  • 1
    $\begingroup$ I think your simulation is incorrect because sample() is not taking the bias into account. And no, the expected hitting time is still finite because there is a net drift to the left. The heavy-handed theorem to back this claim up is called the Foster-Lyapunov theorem, which basically says that if you have a "Lyapunov function" (which must have certain properties) which decreases on average in each step then the chain is positive recurrent. $\endgroup$ Commented Sep 9, 2021 at 22:45
  • 1
    $\begingroup$ Very nice illustration. Thanks. $\endgroup$ Commented Oct 17, 2021 at 21:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.