INTRODUCTION.
This notebook was prepared to enable you to investigate the material in the notes for November 22 - 24.  

CONTENTS.
	1) Functions to create an m-tuple of samples of size n from m normal populations with means specified by you.
	2) Functions to compute the F statistic of such a collection of samples.
	3) A program to create many such m-tuples and record the F statistics of each. 
	4) A program to graph the experimental distribution of the F statistic and compare with the theoretical distribution.
	
To use this notebook, select all the cells [ctrl+a] and then input them [shift+enter].  (Mathematica will ignore the text cells.)  Then go back and modify as desired, and re-input.

If you wish, you may reset the values in the following cell.  
Change the values of m, n and s to any values you prefer, and input the notebook (select it, then  [shift + enter]).

m=6(*Number of samples*);
n=10(*Size of a sample*);
s=1(*Standard deviation of all populations*);

1)
The function in the following cell creates a matrix with m rows, each of size n.  Each row is a sample from a different population. 
The input mm is a vector of length m, in which the ith entry is the mean of the ith population.  Note that mm[[i]] is the ith element of the list mm.
The ith sample is from a normal (mm[[i]], s) population.   

The test that we shall be examining distinguishes between cases where all the entries of mm are the same and cases when they are not.

randomyy[mm_]:= Table[RandomReal[NormalDistribution[mm[[i]],s]], {i,1, m}, {j,1,n}];

2)
The following functions compute the F statistic.  
The first function is an auxiliary function. If xx is a list, ss[xx] is the sum of the squares of the deviations of the elements of xx from their mean.

ss[xx_]:=Module[{xbar=Mean[xx]}, Plus@@Map[(#-xbar)^2&, xx]]
ssw[yy_]:=Plus@@Map[ss,yy];
ssb[yy_]:=Length[yy[[1]]]*ss[Map[Mean,yy]];
fff[yy_]:= (ssb[yy]/(Length[yy]-1))/(ssw[yy]/(Length[yy](Length[yy[[1]]]-1)))

3)
In the following cells, we create many m-tuples of samples, and record the the F statistics of each.

simulate1=Table[fff[randomyy[Table[0,{m}]]], {1000}];(* All means equal to 0.*)

simulate2=Table[fff[randomyy[ReplacePart[Table[0,{m}], 1->1]]], {1000}];(* First mean is 1, the rest are 0.*)

Table[Mod[i,2], {i,1,m}]

simulate3=Table[fff[randomyy[Table[Mod[i,2], {i,1,m}]]], {1000}]; (*Means alternate 0,1,0,1,...*)

simulate4=Table[fff[randomyy[Table[i, {i,1,m}]]], {1000}]; (*Means are 1,2,3,...*)

mmR=RandomReal[1,m]

simulateR=Table[fff[randomyy[mmR]], {1000}];(*Random means, as seen on previous line.*)

4)
And finally, here's the graphing.  The built-in Mathematica function Histogram is applied to simulate1 (appearing in blue) and simulate2 (appearing in pink).
The theoretical F-distribution corresponding to m samples of size n (i.e., the F with m-1 and m(n-1) degrees of freedom) is shown in green.

Histogram[{simulate1,simulate2}, Automatic,"ProbabilityDensity",Epilog->First@Plot[PDF[FRatioDistribution[(m-1),(m(n-1))],x],{x,0,15},PlotStyle->{Thick,Green}, PlotRange->All], ImageSize->700]

Histogram[{simulate1,simulate3}, Automatic,"ProbabilityDensity",Epilog->First@Plot[PDF[FRatioDistribution[(m-1),(m(n-1))],x],{x,0,15},PlotStyle->{Thick,Green}, PlotRange->All], ImageSize->700]

Histogram[{simulate1,simulate4}, Automatic,"ProbabilityDensity",Epilog->First@Plot[PDF[FRatioDistribution[(m-1),(m(n-1))],x],{x,0,15},PlotStyle->{Thick,Green}, PlotRange->All], ImageSize->700]

Histogram[{simulate1,simulateR}, Automatic,"ProbabilityDensity",Epilog->First@Plot[PDF[FRatioDistribution[(m-1),(m(n-1))],x],{x,0,15},PlotStyle->{Thick,Green}, PlotRange->All], ImageSize->700]