> "By hitting return you will load a hopefully useful histogram program":

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:

"Here is program that will help you analyze how you expect streaks to behave. Hit return to load it.":


with(stats):
with(stats[statplots]):
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:
Spikegraph:=proc(distributionlist,xmin,xmax,show)
local num,linelist,j,i,templist:
templist:=[]:
if ((distributionlist[1][1]<xmin) or
(distributionlist[nops(distributionlist)][1]>xmax)
) then
lprint(`Note: some data values lie outside the user-defined interval.`)
fi:
for i from 1 to nops(distributionlist) do
if not((distributionlist[i][1]<xmin) or (distributionlist[i][1]>xmax)) then
templist:=[op(templist),
[distributionlist[i][1],
distributionlist[i][2]
]
]:
fi:
od:
num:=nops(templist):
linelist:=[]:
for j from 1 to num do
linelist:=[op(linelist),[templist[j][1],0]]:
linelist:=[op(linelist),[templist[j][1],templist[j][2]]]:
linelist:=[op(linelist),[templist[j][1],0]]:
od:
if show then plot(linelist,style=LINE) fi;
end:
SpikeData:=proc(data)
local sorteddata,i,olist,plist,current,j,temp,distributionlist:
olist:=sort(convert(convert(data,set),list)):
sorteddata:=sort(data):
plist:=[seq(0,j=1..nops(olist))]: current:=1:
for i from 1 to nops(data) do
if op(i,sorteddata)=op(current,olist)
then
temp:=op(current,plist):
plist:=subsop(current=temp+1,plist):
else
current:=current+1:
temp:=op(current,plist):
plist:=subsop(current=temp+1,plist)
fi:
od:
plist:=map(proc(x,data) evalf(x/nops(data)) end,plist,data):
distributionlist:=zip(proc(x,y) [x,y] end,olist,plist):
distributionlist:
end:




Maxrun:=proc(n,p)
local list,k,R,t:
R:=[];t:=1;
list:=[stats[random, empirical[p/100,(100-p)/100]](n)];
for k from 2 to n
do
if
list[k] = list[k-1]
then
t:=t+1;
fi;
if list[k] <> list[k-1]
then
R:=[op(R),t];
t:=1;
fi;
od;
R;
end:

Streak:=proc(n,p,m,V)
local list,k,R,t:
list:=[];
for k from 1 to m
do
list:=[op(list),max(op(Maxrun(n,p)))];
od;
lprint("Letting heads occur with a",p,"percent chance,");
lprint("the avergae maxiamal legnth run of heads in",m);
lprint("randomly choosen lists of legnth",n,"has been found to be");
lprint(evalf(describe[mean](list)));
lprint("with the following histogram");

Histogram(list,12);

end:

"This program is not desrcibed be low. It gives the eact epected value and a simulated value together ":


Streaky:=proc(n,p,V)
local list,k,R,t:
R:=[];t:=1;
list:=[stats[random, empirical[p/100,(100-p)/100]](n)];
for k from 2 to n
do
if
list[k] = list[k-1] and list[k]=1
then
t:=t+1;
fi;
if list[k] <> list[k-1] or list[k]=2
then
R:=[op(R),t]
fi;
if
list[k] <> list[k-1]
then
t:=1;
fi;
od;
lprint("the actual expect value is about",
evalf(((log[100/p](n*(1-p/100)))+.577/ln(100/p)-0.5)));
if V = true then
lprint(max(op(R)));
fi;
if V = false
then
lprint(R);
fi;
end:

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

Warning, these names have been redefined: boxplot, histogram, scatterplot, xscale, xshift, xyexchange, xzexchange, yscale, yshift, yzexchange, zscale, zshift

Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform

Warning, these names have been redefined: boxplot, histogram, scatterplot, xscale, xshift, xyexchange, xzexchange, yscale, yshift, yzexchange, zscale, zshift

> Streak(200,50,5000,true);

"Letting heads occur with a", 50, "percent chance,"

"the avergae maxiamal legnth run of heads in", 5000

"randomly choosen lists of legnth", 200, "has been found to be"

7.950400000

"with the following histogram"

"the Mean is", 7.950400000

"the Standard deviation is", 1.821521258

"A histogram looks like"

>