Computes the exact probability mass and cumulative distribution of the total number of runs in mutually independent Bernoulli trials. The trials need not have a common success probability. The supplied probabilities are treated as fixed and known; this function performs no estimation.
Value
A data frame with one row for every possible run count and columns:
runsThe possible total run counts from 1 to
length(prob).probabilityThe exact probability mass at each run count.
cumulativeThe inclusive lower cumulative probability.
Details
The calculation uses a finite-state dynamic program indexed by the number
of observations processed, the current run count, and the last binary
value. Its time complexity is quadratic and its working memory is linear
in length(prob).
References
Fu, J. C. and Koutras, M. V. (1994). Distribution theory of runs: A Markov chain approach. Journal of the American Statistical Association, 89(427), 1050–1058. doi:10.1080/01621459.1994.10476841 .
Examples
runs_distribution(c(0.15, 0.40, 0.75, 0.60))