Re: Wald-Wolfowitz runs test
- To: mathgroup at smc.vnet.net
- Subject: [mg53905] Re: Wald-Wolfowitz runs test
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Wed, 2 Feb 2005 18:10:48 -0500 (EST)
- References: <ctaill$ee8$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Csukas Attila wrote:
> Greetings to all
>
> I would like to ask a little help. Is it possible to do the
> Wald-Wolfowitz runs test on the Mathematica?
> If so, what is the way to do it.
>
> Any help is appreciated.
>
> Thanks in advance.
>
> Csukas
(* sample data *)
x = Table[Random[Integer],{n = 25}]
{0,0,0,1,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,1,1,1,0,0}
(* number of 1s & 0s, number of runs *)
{{n1 = Tr@x, n0 = n - n1}, r = Length@Split@x}
{{11, 14}, 13}
(* mean & s.d. of the sampling distribution of r *)
N@{m = 1 + 2*n0*n1/n, sd = Sqrt[(m-1)(m-2)/(n-1)]}
{13.32, 2.41059}
(* sampling distribution of r *)
f[r_,n0_,n1_] := If[EvenQ@r,
With[{k = r/2 - 1},2*Binomial[n0-1,k ]*Binomial[n1-1,k ]],
With[{k = (r-1)/2}, Binomial[n0-1,k ]*Binomial[n1-1,k-1] +
(**) Binomial[n0-1,k-1]*Binomial[n1-1,k ]]];
rf = Table[{r,f[r,n0,n1]},{r,2,2Min[n0,n1]+Boole[n0!=n1]}]
{{2,2}, {3,23}, {4,260}, {5,1365}, {6,7020}, {7,22230}, {8,68640},
{9,145860}, {10,300300}, {11,450450}, {12,648648}, {13,702702},
{14,720720}, {15,566280}, {16,411840}, {17,231660}, {18,115830},
{19,45045}, {20,14300}, {21,3575}, {22,572}, {23,78}}
(* divisor to convert the frequencies to probabilities *)
{#, # === Tr@rf[[All,2]]}&@Binomial[n,n1]
{4457400, True}