> "By hitting return you will load a program capable of exploring the Ch-Squared test's validity.":

with(stats):
with(stats[statplots]):
Convert:=proc(data)
local hap,hap1,d,j1,j2,j3,mean;
hap:=[];
hap1:=[];
d:=[];
for j1 from 1 to nops(data)
do
hap:=[op(hap),data[j1][2]];
od;
mean := nops(data)*describe[mean](hap);
for j2 from 1 to nops(data)
do
hap1:=[op(hap1), hap[j2]/mean];
od;
for j3 from 1 to nops(data)
do
d:=[op(d), [data[j3][1],hap1[j3]]];
od;
d;
end:
Bargraph:=proc(data,xmin,xmax,k)
local sorteddata,dx,graphicslist,f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`):
fi:
f:=proc(k,sorteddata,xmin,dx,xmax)
local i,j,currentupperlim,leng,index,counter,result,finallist,q,numb,
linelist:
linelist:=[]: finallist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/leng]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
plot(linelist,style=LINE);
end:
f(k,sorteddata,xmin,dx,xmax):
end:Areabargraph:=proc(data,xmin,xmax,k)
local sorteddata, dx, lines,graphicslist, f:
sorteddata:=[]:
dx:=(xmax-xmin)/k:
lines:=[]:
graphicslist:=[]:
sorteddata:=sort(data):
if ((op(1,sorteddata)<xmin) or (op(nops(sorteddata),sorteddata)>xmax))
then
lprint(`Note: some data values lie outside the user-defined interval.`)
fi:
f:=proc(k,sorteddata,xmin,dx,xmax,lines::evaln)
local i,j,currentupperlim,leng,index,counter,result,
finallist,q,numb,linelist:
finallist:=[]:
linelist:=[]:
index:=1:
leng:=nops(sorteddata):
currentupperlim:=xmin+dx:
result:=[]:
for q from 1 to leng do
if ((op(q,sorteddata)>=xmin) and (op(q,sorteddata)<=xmax))
then finallist:=[op(finallist),op(q,sorteddata)]
fi:
od:
numb:=nops(finallist):
for i from 1 to k do
counter:=0:
while ((index<=numb) and (op(index,finallist)<=currentupperlim)) do
counter:=counter+1:
index:=index+1:
od:
result:=[op(result),counter]:
currentupperlim:=currentupperlim+dx:
od:
for j from 1 to k do
linelist:=[op(linelist),[xmin + (j-1)*dx,0]]:
linelist:=[op(linelist),[xmin + (j-1)*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,op(j,result)/(leng*dx)]]:
linelist:=[op(linelist),[xmin + j*dx,0]]:
od:
lines:=linelist:
end:
f(k,sorteddata,xmin,dx,xmax,lines):
plot(lines,style=LINE);
end:

Analysis:=proc(L)
local m,v,sd,k,S,i,j,l;
m:=0;
v:=0;
sd:=0;
for k from 1 to nops(L)
do
m:=m+L[k];
od;
m:=evalf(m/nops(L));
for i from 1 to nops(L)
do
v:=v+(L[i]-m)^2;
od;
v:=evalf(v/nops(L));
sd:=evalf(sqrt(v));
[m,v,sd];
end:

Histogram:=proc(d,n)
local list1,j1,j2,A,ml,mh,sl,sh,Al,Ah,L;
L:=list1;
Al:=Analysis(d);
ml:=Al[1];
sl:=Al[3];
lprint("the Mean is",ml);
lprint("the Standard deviation is",sl);
lprint("A histogram looks like");
Areabargraph(d,min(op(d))-.5,max(op(d))+.5,n );
end:



PreChiTest:=proc(E,F)
local r,s,i,m;
m:=nops(E)-1;
r:=0;
for i from 1 to nops(E)
do
r:=r+((E[i]-F[i])^2)/E[i];
od;
evalf(r);
end:


SeeIt:=proc(n)
local i,a,N1,N2,N3,N4;
N1:=0;
N2:=0;
N3:=0;
N4:=0;
for i from 1 to n
do
a:=stats[random,discreteuniform[1,4]](1);
if a=1 then
N1:=N1+1;
fi;
if a=2 then
N2:=N2+1;
fi;
if a=3 then
N3:=N3+1;
fi;
if a=4 then
N4:=N4+1;
fi;
od;
PreChiTest(
[evalf(n*.25),evalf(n*.25),evalf(n*.25),evalf(n*.25)],
[N1,N2,N3,N4]);

end:

SeeItAll:=proc(n,m,k)
local i,S;
S:=[];
for i from 1 to m
do
S:=[op(S),SeeIt(n)];
od;
S;

A1:=plot(stats[statevalf,pdf,chisquare[3]](x),x=0..15,color=blue):

A2:=Histogram(S,k);

display(A1,A2);

end:

Warning, the name transform has been redefined

Warning, `A1` is implicitly declared local to procedure `SeeItAll`

Warning, `A2` is implicitly declared local to procedure `SeeItAll`

> SeeItAll(100,5000,13);

"the Mean is", 3.022608000

"the Standard deviation is", 2.475035722

"A histogram looks like"

[Maple Plot]