2
$\begingroup$

I have a very long sequence (in the tens of thousands) of binary outcomes from some data-generating process. I believe that these outcomes are iid Bernoulli trials with p = 0.5, equivalent to flipping a fair coin. From this sequence I construct a table of frequencies for runs of heads of various lengths, all the lengths that appear, and likewise for tails.

  1. It seems intuitively that there should be an expected value for the number of runs of each length, given the total length of the sequence . How might I calculate that expected value?
  2. It seems intuitively that either a surplus or a deficit of the number of runs of each specified length would, if sufficiently large, suggest rejection of the fair coin hypothesis. How might I take the totality, or profile, of such deviations for all the different run lengths to test the hypothesis that the entirety of the sequence was generated by independent Bernoulli trials, as described above.
$\endgroup$

1 Answer 1

1
$\begingroup$

The runs test of randomness is one of the standard tests of randomness. I would suggest looking at The wikipedia page for the test and if you want to use it there's an implementation of the test in R here. The resources in the wikipedia page offer a lot of information about the issue. In particular NCSS analysis of runs is extensive.

$\endgroup$
1
  • $\begingroup$ Thanks for your thoughts! My understanding is that the Wald–Wolfowitz runs test summarizes the total number of runs as a single number, which is normally distributed with a specific mean and variance under the hypothesis of independence. I'm asking about distinct frequency counts for each of many run lengths, where I think that under independence the unlikelyness of the ensemble is roughly the product unlikelyness of the observed frequency for each run length. I expect this to be more sensitive to misspecification. $\endgroup$
    – andrewH
    Commented Jan 27, 2019 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.