Number of runs compared with random shuffles
nrunsi value1 value2 ... valuek [ , nreps(#) saving(filename [, replace]) ]
Description
nrunsi counts runs in a specified sequence of values, either numeric or string, showing the successive occurrence of categories, such as 1 2 2 2 3 3 3 1 1 1 or A A A A B B A A. A run ends when values change from one category to another or at the end of the sequence. Thus in these examples there are four and three runs respectively.
nrunsi shuffles the sequence randomly a given number of times. It displays the simulated frequency and probability distributions under randomness of the number of runs possible with the same values and the probabilities of less than, the same number as, or more than that observed.
To ensure reproducible results, set seed beforehand.
nrunsi is an immediate command.
Options
nreps() indicates the number of shuffles to be simulated. The default is 10000.
saving() indicates that results, meaning variables containing values, number of runs, frequencies and probabilities, should be saved to the specified file.
Examples
. nrunsi 1 2 2 2 3 3 3 1 1 1
Saved values
r(pless) probability of less runs than observed r(psame) probability of same number of runs as observed r(pmore) probability of more runs than observed
Authors
Nicholas J. Cox, Durham University, UK n.j.cox@durham.ac.uk
Nigel C. Smeeton, King's College London, UK nigel.smeeton@kcl.ac.uk
Acknowledgments
Kit Baum and William Gould made valuable suggestions on speeding up the Mata code.
References
Smeeton, N. and Cox, N.J. 2003. Do-it-yourself shuffling and the number of runs under randomness. Stata Journal 3: 270-277.
Sprent, P. and Smeeton, N.C. in press. Applied Nonparametric Statistical Methods (4th edition; see section 7.6.2). Boca Raton, FL: CRC.
Also see
Online: nruns