Presidential Streaks (Solution)
Disclaimer: I’m going to refer to Republicans and Democrats as heads and tails, respectively.
Can we just try all sequences? The number of sequences of 22 heads and 16 tails is \({38 \choose 16} = 22,239,974,430\). Probably not.
Definitions:
- \(total(h, t)\): the total number of sequences with \(h\) heads and \(t\) tails
- \(lt(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak < \(k\).
- \(lte(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak <= \(k\).
- \(lt\_cond\_right\_is\_tails(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak < \(k\) and the rightmost coin flip is tails.
- \(lt\_cond\_right\_is\_heads(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak < \(k\) and the rightmost coin flip is heads.
- \(eq\_cond\_right\_k\_tails(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak = \(k\) and the rightmost \(k\) coin flips are tails.
- \(eq\_cond\_right\_k\_heads(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak = \(k\) and the rightmost \(k\) coin flips are heads.
- \(ge(k, h, t)\): number of sequences with \(h\) heads and \(t\) tails that have a longest streak >= \(k\).
- \(prob\_lte(k, h, t)\): probability that a sequence with h heads and t tails has a longest streak <= k. The answer to our question is \(prob\_lte(5, 22, 16)\).
Implementations:
\(prob\_lte(5, 22, 16) \approx 0.55\), meaning that if there were absolutly no connection between one election and the next, the probability that the longest consecutive sequence of wins by either political party would be 5 terms or fewer is about 55%. Null hypothesis not rejected…