>
with(stats):
with(plots):
"By hitting return you will load a hopefully useful histogram making program allowing to easily analyze data given as a list of experimentally determined values.":
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,ml-max(abs(ml-min(op(d))),abs(ml-max(op(d)))),
ml+max(abs(ml-min(op(d))),abs(ml-max(op(d)))),n);
end:
Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform
Warning, these names have been redefined: anova, describe, fit, importdata, random, statevalf, statplots, transform
>
Bernu:=proc(n,p,m,q)
local L,L1,T,V,i,H,p1,p2,V1,i1,H1,p3;
H:=[];
H1:=[];
V:=0;
V1:=0;
L:=[random[empirical[(1-p),p]](n)];
for i from 1 to n
do
H:=[op(H),L[i]-1];
V:=V+H[i];
od;
p1:=evalf(V/n);
L1:=[random[empirical[(1-q),q]](m)];
for i1 from 1 to m
do
H1:=[op(H1),L1[i1]-1];
V1:=V1+H1[i1];
od;
p2:=evalf(V1/m);
p3:=evalf((V+V1)/(n+m));
[H,H1,V+V1,
evalf((p1-p2)/(sqrt(
p3*(1-p3)*(1/n+1/m)
))
)];
end:
Pairs:=proc(k,L)
local i,B,K;
B:=[];
for i from 1 to k
do
K:=Bernu(op(L));
if
K[3]<>0
then
B:=[op(B),K[4]];
fi;
od;
B;
end:
Nor:=plot((1/(sqrt(2*Pi)))*exp(-x^2/(2)),x =-3..3,color=blue):
>
randomize();
R:=rand();
randomize(R);
x1:=11;
n1:=17;
x2:=14;
n2:=15;
p1:=x1/n1;
p2:=x2/n2;
p3:=evalf((x1+x2)/(n1+n2));
evalf((p1-p2)/(sqrt(
p3*(1-p3)*((1/n1)+(1/n2))
))
);
> Bernu(n1,p3,n2,p3);
>
P:=Pairs(50,[n1,p3,n2,p3]);
P1:=Histogram(P,5):
display(P1,Nor);
"the Mean is", .2711093614e-1
"the Standard deviation is", .9494526084
"A histogram looks like"
>
P:=Pairs(1000,[n1,p3,n2,p3]);
P1:=Histogram(P,9):
display(P1,Nor);
"the Mean is", -.5770591162e-1
"the Standard deviation is", 1.031006119
"A histogram looks like"
>