In[1]:=

<<Statistics`DescriptiveStatistics`

<<Statistics`MultiDiscreteDistributions`

<<Statistics`ContinuousDistributions`

NCSDist[k_, d_] := NoncentralChiSquareDistribution[k, d]

ndist = NormalDistribution[0, 1]

NTail[x_] := 1 - CDF[ndist, x]

NapproxPt[n_, k_, q_, a_] := Sqrt[n] * ( n^(-1) Quantile[ChiSquareDistribution[k], 1 - a] - q)/(3/4)

CSTPow[k_, d_, a_] := 1 - CDF[NCSDist[k, d], Quantile[ChiSquareDistribution[k], 1 - a]] 

MultN[n_, p_] := MultinomialDistribution[n, p]

p = {1/4, 1/2, 1/4}

p0 = {1/3, 1/3, 1/3}

q = Sum[(p[[j]] - p0[[j]])^2/p0[[j]], {j, 1, Length[p]}] 

CSStatist[n_Integer, p0_, p_] := {x = Random[MultN[n, p]] ; Q = Sum[(x[[j]] - n * p0[[j]])^2/(n * p0[[j]]), {j, 1, Length[p0]}]} <br />

CS = Flatten[Table[CSStatist[100, p0, p], {k, 1, 5000}]] ; 

nn = 5000 ;

zz = Sort[CS] ;

hh = Table[k, {k, 1, nn}] * (1/nn) ;//N

J1 = Table[{zz[[i]], hh[[i]]}, {i, 1, nn}] ;

ListPlot[J1]

Delta[x_] := 0/;x<0

Delta[x_] := 1/;x≥0

DE[x_] := Table[{Delta[zz[[i]] - x]}, {i, 1, nn}]

EDF[nn_, x_] := 1. - Apply[Plus, DE[x]] * (1/nn)//N

P10 = Plot[EDF[nn, x], {x, 0, 40}, PlotStyle {Thickness[1/100], RGBColor[0., 1., 0.196], Dashing[{}]}] 

NCSDist[k_, d_] := NoncentralChiSquareDistribution[k, d]

ndist = NormalDistribution[0, 1]

NTail[x_] := 1 - CDF[ndist, x]

NapproxPt[n_, k_, q_, a_] := Sqrt[n] * ( n^(-1) Quantile[ChiSquareDistribution[k], 1 - a] - q)/(3/4)

CSTPow[k_, d_, x_] := CDF[NCSDist[k, d], x]

P2 = Plot[CSTPow[2, 100/8, x], {x, 0, 40}] 

Show[P10, P2]

1 - EDF[nn, 5.991]

1 - EDF[nn, 9.21]

Mean[CS]

Variance[CS]

LocationReport[CS]

DispersionReport[CS]

Out[5]=

NormalDistribution[0, 1]

Out[10]=

{1/4, 1/2, 1/4}

Out[11]=

{1/3, 1/3, 1/3}

Out[12]=

1/8

[Graphics:HTMLFiles/ChiSquarePowerNCCSapproxMC_42.gif]

Out[19]=

⁃Graphics⁃

[Graphics:HTMLFiles/ChiSquarePowerNCCSapproxMC_44.gif]

Out[24]=

⁃Graphics⁃

Out[26]=

NormalDistribution[0, 1]

[Graphics:HTMLFiles/ChiSquarePowerNCCSapproxMC_47.gif]

Out[30]=

⁃Graphics⁃

[Graphics:HTMLFiles/ChiSquarePowerNCCSapproxMC_49.gif]

Out[31]=

⁃Graphics⁃

Out[32]=

{0.892}

Out[33]=

{0.736}

Out[34]=

18163/1250

Out[35]=

352512873/6248750

Out[36]=

{Mean18163/1250, HarmonicMean17602962323206483126970821300328672232689561266 ... 17296313587206988834747199381749288140020945781369553304096338951678933474831, Median14}

Out[37]=

{Variance352512873/6248750, StandardDeviation (3 39168097/9998^(1/2))/25, Sa ... viation18655713/3125000, MedianDeviation261/50, QuartileDeviation261/50}


Created by Mathematica  (October 21, 2005) Valid XHTML 1.1!