-------------------------------------------------------------------------------
help for nruns                                                (SJ6-4: st0044_1)
-------------------------------------------------------------------------------

Number of runs compared with random shuffles

nruns varname [if] [in] [ , nreps(#) saving(filename [, replace]) ]

Description

nruns counts runs in a sequence of values given by varname, which may be 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.

nruns 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. Options {p 4 8 2}nreps() indicates the number of shuffles to be simulated. The default is 10000. {p 4 8 2}saving() indicates that results, meaning variables containing values, number of runs, frequencies and probabilities, should be saved to the specified file. Examples {p 4 8 2}. nruns sequence Saved values {col 5}r(pless) {col 18}probability of less runs than observed {col 5}r(psame) {col 18}probability of same number of runs as observed {col 5}r(pmore) {col 18}probability of more runs than observed Authors {p 4 4 2}Nicholas J. Cox, Durham University, UK{break} n.j.cox@durham.ac.uk {p 4 4 2}Nigel C. Smeeton, King's College London, UK{break} nigel.smeeton@kcl.ac.uk Acknowledgments {p 4 4 2}Kit Baum and William Gould made valuable suggestions on speeding up the Mata code. References {p 4 8 2}Smeeton, N. and Cox, N.J. 2003. Do-it-yourself shuffling and the number of runs under randomness. Stata Journal 3: 270-277. {p 4 8 2}Sprent, P. and Smeeton, N.C. in press. Applied Nonparametric Statistical Methods (4th edition; see section 7.6.2). Boca Raton, FL: