# Coin toss: Probability of a run of certain length out of a longer sequence

$\begingroup$ First the empirical proof to motivate the long explanation:
We can get the answer with a one-line Monte Carlo simulation, corresponding to $1$ million trials, which in R would be :

> mean(replicate(1e6, sum(rle(sample(c(0,1), 100, T))$lengths ==7) > 0)) $ \Pr ( \text { operate of 7 heads in 100 tosses } ) = $0.317567 now the close, algebraic solution : I am going to assume miss of familiarity with Markov chains, and make it very easily to follow . The theme is that we go through$ 100 $steps, and at each transition, there is a given probability distribution for things to stay as they are or to change. here by “ things ” I just mean the number of straight heads ($ \text H $‘s ) . So we start tossing the mint and we have the follow distribution of events :$ $\small\begin { bmatrix } s_0=\text { T } & s_1=\text { H } _1\\1/2 & 1/2\end { bmatrix }$ $either tails or heads, and it is a fairly coin … The key is to realize that if it was tail, we are back to were we began – let ‘s call it state$ 0 $or$ s_0. $otherwise, we are taking the first base footfall towards building a sequence of$ 7 $consecutive heads, i.e.$ s_1. $We toss again. And this is now in truth critical to appreciate … If we had actually built up the begin of a run ( i.e. if we had a drumhead in the beginning pass ) we would be in the gloomy military position right before the second flip :$ $\small\begin { bmatrix } s_0 & \color { gloomy } { s_1 } \\1/2 & \color { gloomy } { 1/2 } \end { bmatrix }$ $and we would have, naturally, a probability of$ 1/2 $to build up a longer footrace ( a run of$ 2 $consecutive$ \text { H } $‘s, or$ s_2 $) by simply getting another oral sex, or we could go back to the begin by getting a$ \text { T } $. We have no matter to in runs that are less than$ 7 $as per your initial question . So we can either obtain a oral sex and keep construction up our sequence of$ 7 $heads, or go bet on to$ s_0 $. If we are lucky we land in$ s_2 $– a “ accumulative ” run of$ 2 $heads, which would look like this :$ $\small\begin { bmatrix } \quad & s_0 & \color { blue } { s_1 } & \color { green } { s_2 } \\\text { 1st toss } & 1/2 & \color { aristocratic } { 1/2 } & 0\\\text { 2nd convulse } & 1/2 & 0 & \color { green } { 1/2 } \end { bmatrix }$ $now we are either rear to “ square one ” or$ s_0 $, with nothing to account for, if a tail came up on the second pass, or we have advanced to$ s_2 $, and each scenario has$ 1/2 $probabilities. Notice that there is no scenario in which we could find ourselves in$ s_1 $: we either built up a succession of two straight heads, i.e.$ s_2=\ { \text { H, H } \ } $if we got a principal, or we are back to zero . next attack …$ $\small \begin { bmatrix } \quad & s_0 & \color { blue } { s_1 } & \color { green } { s_2 } & \color { crimson } { s_3 } \\\text { 1st toss } & 1/2 & \color { gloomy } { 1/2 } & 0 & 0\\\text { 2nd convulse } & 1/2 & 0 & \color { green } { 1/2 } & 0\\\text { 3rd pass } & 1/2 & 0 & 0 & \color { red } { 1/2 } \end { bmatrix }$ $That ‘s right … We either have a run of$ 3 $heads or we are back to zero. So we keep on going and we get …$ $\small \begin { bmatrix } \quad & s_0 & \color { blue } { s_1 } & \color { green } { s_2 } & \color { crimson } { s_3 } & \cdots & \color { orange } { s_7 } \\\text { 1st flip } & 1/2 & \color { gloomy } { 1/2 } & 0 & 0 & \cdots & 0\\\text { 2nd discard } & 1/2 & 0 & \color { greens } { 1/2 } & 0 & \cdots & 0\\\text { 3rd chuck } & 1/2 & 0 & 0 & \color { red } { 1/2 } & \cdots & 0\\\vdots & \vdots & \vdots & \vdots & \vdots & \cdots & \vdots\\ \text { 7th flip } & 1/2 & 0 & 0 & 0 & \cdots & \color { orange } { 1/2 } \end { bmatrix }$ $But we are not done, because we are going to multiply this transition matrix$ T $over and over again$ 100 $times by itself – i.e. we are going to$ T^ { 100 } $( more on this below ). And we have to prevent that the ongoing probability reckoning of$ s_7 $in the last column gets modified by itself. How do we do it ? We add a row of all zeros except for a$ 1 $in the last entrance as under. Why ? Because it will systematically guarantee that the last column, which is what we very want ( our “ accounting column ” or the probabilities of$ s_7 $), does not have any influence from one step to the future in the recalculation – only the column to the leave of$ s_7 $will influence or contribute to updating$ s_7 $at every pass :$ $\small T=\begin { bmatrix } \quad & s_0 & \color { blue } { s_1 } & \color { green } { s_2 } & \color { loss } { s_3 } & \cdots & \color { orange } { s_7 } \\\text { 1st flip } & 1/2 & \color { amobarbital sodium } { 1/2 } & 0 & 0 & \cdots & 0\\\text { 2nd toss } & 1/2 & 0 & \color { green } { 1/2 } & 0 & \cdots & 0\\\text { 3rd toss } & 1/2 & 0 & 0 & \color { red } { 1/2 } & \cdots & 0\\\vdots & \vdots & \vdots & \vdots & \vdots & \cdots & \vdots\\ \text { 7th discard } & 1/2 & 0 & 0 & 0 & \cdots & \color { orange } { 1/2 } \\\quad & 0 & 0 & 0 & 0 & \cdots & \color { empurpled } 1\end { bmatrix }$ $This is the transition matrix or stochastic matrix,$ T $. Check absorbing states hera . In multiplying this matrix times itself, you can observe that the stopping point submission of each row will be multiplied by$ 0 $( except for the final quarrel we merely added ), leaving the last, column$ \color { orange } { s_7 } $wholly nullified in the$ [ \text { course } ] \cdot [ \text { column } ] $department of transportation product . nowadays for the home stretch … We have built this matrix as a story, with the implicit logic that we went from$ s_1 $to$ s_2 $as we transitioned from the one-element,$ s_1 $, to the two-element run,$ s_2 $( or went back to$ s_0 $) in the second toss with certain probabilities. however, we never considered the probability of transitioning to$ s_1 $on the fourth toss, for exercise, which is going to depend on the probabilities of all potential anterior states. The probability distribution at each point in time will depend on the prior distribution, explaining why we have to raise$ T $to the$ 100 $office. Let ‘s hone down on one of these multiple dot products within the powers of$ T $: we focus on the evolution of probabilities in the first rowing and see that when we dot it with the third column in the serve of calculating$ T^2  $\small \begin { bmatrix } s_0 & \color { aristocratic } { s_1 } & \color { k } { s_2 } & \color { crimson } { s_3 } & \cdots & \color { orange } { s_7 } \\1/2 & \underbrace { \ ; \color { blue } { 1/2 } \ ; } _ { \text { step } triiodothyronine } & 0 & 0 & \cdots & 0\\\end { bmatrix } \cdot\tiny\begin { bmatrix } \color { green } { s_2 } \\0\\\text { footstep } t+1 { \lbrace { \\\ ; \color { park } { 1/2 } \ ; } \\ } \\0\\0\\0\\0\end { bmatrix }$ $we split ( multiply by$ \color { green } { 1/2 } $) the probability associated with a run in the immediate anterior state ($ t=s_1 $) ( at this point$ \color { aristocratic } { 1/2 } $) to assign a probability to a run that is one element longer ($ t+1=s_2 ). $We can find the final solution after calculating$ T^ { 100 } $in precisely this position :$ $\small T^ { 100 } =\begin { bmatrix } \quad & s_0 & \color { blasphemous } { s_1 } & \color { green } { s_2 } & \color { red } { s_3 } & \cdots & \color { orange } { s_7 } \\ & & & & & & \bbox [ 5px, border:2px solid red ] { \text { answer } } \\ & & & & & & & \\ & & & & & & & \\ & \vdots & \vdots & \vdots & \vdots & \cdots & \vdots\\ & & & & & & & \\ & 0 & 0 & 0 & 0 & \cdots & \color { purple } 1\end { bmatrix }$ $after performing$ T^ { 100 } $. Notice how in every calculation measure, we dot the foremost row with each column, in what is actually a bunch of and and or statements to calculate the probability of each state in the first base row . This ends up being$ \bbox [ 5px, border:2px solid crimson ] { T^ { 100 } [ 1,8 ] = 0.31752 } \$ .

require(expm)
m= matrix(c( .5,  .5,0,0,0,0,0,0,
.5, 0, .5,0,0,0,0,0,
.5, 0,0, .5,0,0,0,0,
.5, 0,0,0, .5,0,0,0,
.5, 0,0,0,0, .5,0,0,
.5, 0,0,0,0,0, .5,0,
.5, 0,0,0,0,0,0, .5,
0, 0,0,0,0,0,0,  1), nrow = 8, byrow=T)
t(c(1,0,0,0,0,0,0,0)) %*% (m%^%100 %*% c(0,0,0,0,0,0,0,1))

source : https://ontopwiki.com
Category : Finance