# How do I statistically model events to account for arrival times?

I've got a problem where I need to probabilistically score different possible sequences of events, and I think I'm missing something about how to properly model them. Here's the example: Say someone flips a fair coin once per second for a whole day. I didn't seen the coin flips, but am given a two possible sequences. One has ~50% heads, but they all occur up front (the first half of the flips are all heads, then the remainder are all tails). The second sequence is also ~50% heads, but they occur in a more random seeming way, distributed throughout the day. In what sense, if any, is the second sequence more likely?

At the sequence level, all sequences have equal likelihood. I can also look at a binomial distribution in number of heads, but they would score equally well against that metric too. I could also look at the event arrival times, in terms of the number of flips between heads, perhaps looking at it as a Poisson with an exponential distribution describing the time between changes. I believe this ends up scoring the same too though. An ad-hoc thing would be to break it into time segments and score them separately - that would expose that it's very unlikely to get zero heads in 12 hours of flipping, but I don't like the ad-hoc nature of it, where I need to pick a time window interval.

What's the right way to do this?

One way you can model this is by counting the total number of "changes" from heads to tails (Binomial, and approximately normal with a large number of flips). Notice at each flip, there is an (independent) 1/2 probability that there will be a change in the sequence.

This approach will correctly combine groups of "regular" sequences you would get through a day, but will also pick out the highly unusual case of no changes in a large number of flips.

• Good idea. Any ideas how I could extend this concept to a case where the coin is unfair, with a very small probability of heads? In such a case, the number of transitions may be always the same (or very close), but the number of tails between successive heads is of interest. I still want to capture the notion that having all the heads bunched up is less probable. – Mastiff Jul 17 '17 at 23:16
• If the coin is slightly unfair, then the same idea should work, but the distribution of the total number of "changes" is, to my knowledge, not as easy to write in closed form. It can be simulated, however, given any number of flips and weight of the coin. If the probability of heads very small, then the flips should resemble mostly tails bunched together, with very few if any heads. Then any sequence with a significant number of total heads (let alone heads being bunched together) will be very unlikely. – Kevin Jul 17 '17 at 23:45

You definitely want to model the question with a binomial distribution. You have a fixed number of trials (once every second per day, or 86,400 trials a day), you have two possible outcomes (heads or tails), the probability of each result is constant (always 50% heads and 50% tails), and the results do no affect each other (flipping 2400 heads in a row doesn't mean more chance of flipping tails next time round). Poisson would not be the correct distribution here.

(For simplicity, I'm going to assume that the number of heads flipped is exactly 50%, since working with factorials of ~86,400 isn't a fun experience).

You're correct in your statement that two sequences have the same probability. The sequence HHHHTTTT has the same chance as HHTHTTHT. However, there is only one sequence where all of the heads occur first. In this example of 8 trials with 4 successes, there are 70 different sequences to arrange four heads and four tails, so that leaves 68 'seemingly random' sequences if you eliminate HHHHTTTT and TTTTHHHH.

It appears that the reason you can't find a good way to statistically model this is because you don't have a mathematical criteria. I would say something like, "if the same side is flipped more than 25 times in a row, the distribution is not seemingly random". In 86,400 trials, there are 86,376 chances for 25 flips in a row to be heads. Using 0.5^25 * 86376 gives us 0.257% chance of getting 25 heads in a row at some point. Multiplying by 2 to account for tails gives us 0.515% chance. You could change the '25' to whatever you wish.

Since the probability of HHHH...HHHH then TTTT...TTTT is 0.5^86400 (1.019E-26009, or 0.0000...[26004 more zeroes]...1019), you can see that this probability is vastly different to 0.515%. I believe that overlooking the amount of combinations that appear random was the missing piece here.