Kapitel 21
Kombinatorik
> restart:
> 5!;
> binomial(12,10);
> binomial(a+3,a);
> expand(%);
> with(combinat);
Warning, the protected name Chi has been redefined and unprotected
> multinomial(12,5,5,2);
> 12! / (5! * 5! *2!);
> choose( [a,b,b,c]), numbcomb( [a,b,b,c]);
> choose( [a,b,b,c],2), numbcomb( [a,b,b,c], 2);
> randcomb( [a,b,b,c],2);
> permute([a,b,b,c]), numbperm([a,b,b,c]);
> permute([a,b,b,c],2), numbperm([a,b,b,c],2);
> randperm([a,b,b,c]);
> cproc:=cartprod( [[a,b,c],[x,y],[1,2]]):
> l:=[]: while not cproc[finished] do l:=[op(l),cproc[nextvalue]()]: od: l;
> partition(6), numbpart(6);
> composition(6,2), numbcomp(6,2);
Werkzeuge zur beschreibenden Statistik
> restart:with(stats): with(describe):
> data:=[ 2,3,4,Weight(5,4),missing,Weight(1..4,3) ];
> mean(data), (2+3+4+5*4+(1+4)/2*3)/10;
> importdata("c:\\kofler\\cd_neu_d\\R6\\Examples\\part3\\statdata.dat");
> importdata("c:\\kofler\\cd_neu_d\\R6\\Examples\\part3\\statdata.dat",3);
> with(transform):
Warning, the protected name apply has been redefined and unprotected
> tst:=[Weight(1..3,4), 3..4, Weight(4..7,4), 8];
> statvalue(tst);
> classmark(tst), statvalue(classmark(tst));
> frequency(tst), cumulativefrequency(tst);
> apply[sin](tst);
> multiapply[(x,y)->x*y]([[1,2,3], [4,5,6]]);
> scaleweight[1/count(tst)](tst);
> statsort( [6,missing,3,Weight(4..5,2)] );
> split[3]([1,2,3,4,5,6]);
> split[4]([1,2,3,4,5,6]);
> tallyinto( [1,2,2,2,3,4,5,6,6], [1..3,3..4,4..7]);
> tst:=[seq(rand(100)(), n=1..100)];
> bins:=[seq(10*n..10*n+10 ,n=0..9)];
> tallyinto(tst,bins);
> frequency(%);
Datenanalyse
> restart:with(stats): with(describe);
> tst:= [1,2,3,Weight(4..6,2),Weight(missing,2)]:
> count(tst), countmissing(tst);
> range(tst);
> mean(tst);
> quadraticmean(tst);
> standarddeviation(tst), variance(tst);
> quantile[3/4](tst), quartile[3](tst),percentile[75](tst);
> tst:=[1,2,3,4],[2,4,5,6]:
> linearcorrelation(tst ); evalf(%);
> covariance(tst); evalf(%);
Grafische Darstellung
> restart:
> with(stats): with(statplots): with(transform):
> with(random): with(describe): with(plots):
Warning, the protected name apply has been redefined and unprotected
Warning, the name poisson has been redefined
Warning, the name changecoords has been redefined
> f:=normald[5,1]: data:=[f(100)]:
> tallyinto(data, [seq(n*0.5..(n+1)*0.5,n=1..20)]):
> histdata:=scaleweight[1./count(%)](%);
> p1:=histogram(histdata,color=green):
> fpdf:=statevalf[pdf,f]:
> p2:=plot(fpdf(x), x=0.5..10):
> display( [p1, p2] );
> matrixplot( [[1,2,3], [3,4,5]], heights=histogram, axes=framed, gap=0.2, style=patch, shading=none, ambientlight=[0.5,0.5,0.5], light=[45,45,0.5, 0.5, 0.5]);
> datax:=[normald[5,1](100)]:
> datay:=[normald[7,2](100)]:
> scatterplot(datax,datay,color=navy);
> scatterplot(datax,datay,format=quantile);
> scatterplot(datax);
> scatterplot(datax,format=jittered);
> scatterplot([1, 2$5, 3$3,4$10, 5, 6$4],format=stacked);
> boxplot(datax);
> boxplot(datax,format=notched,shift=5,width=2);
> p1:=scatterplot(datax, datay):
> p2:=xyexchange(boxplot(datax,shift=18,width=1)):
> p3:=boxplot(datay,format=notched,shift=8,width=0.5):
> display( [p1,p2,p3] , view=[0..9,0..19]);
>
> yscale := (scl,x)-> xyexchange(xscale(scl,xyexchange(x))):
> tallyinto(datay, [seq(n..n+1, n=-2..18)]):
> histdata:=scaleweight[1./count(%)](%):
> p1:=histogram(histdata):
> p2:=yshift(0.3,yscale(0.05,scatterplot(datay,format=jittered))):
> display([p1,p2], axes=boxed);
Diskrete und stetige Verteilungen
> restart:with(stats): with(statevalf):
> f1:=statevalf[pdf,normald[0,1]]:
> f2:=statevalf[cdf,normald[0,1]]:
> f3:=statevalf[icdf,normald[0,1]]:
> f1(1), f2(1), f3(0.841);
> f3(f2(3));
> plot({f1(x), f2(x)}, x=-4..4);
> plot(f3(x),x=0..1, -3..3);
> statevalf[icdf,normald[90000,20000]](0.8);
> f1:=statevalf[pdf,exponential[1]]:
> plot(f1(x), x=0..4);
> f1:=statevalf[pdf,lognormal]:
> plot(f1(x), x=0..4);
> f1:=statevalf[pf,poisson[5]]:
> seq(f1(n), n=1..10);
> plot(f1(floor(x)), x=1..10,numpoints=1000);
Zufallszahlen
> restart:
> with(stats): with(random): with(statplots): with(plots): with(statevalf):
Warning, the name poisson has been redefined
Warning, the name changecoords has been redefined
> normald[10,1](3);
> f:=normald[10,1](generator[20]):
> f(), f(), f();
> yscale := (scl,x)-> xyexchange(xscale(scl,xyexchange(x))):
> f:=normald[5,2]:
> p1:=plot( statevalf[pdf,f](x), x=-2..12):
> p2:=yshift(0.2,yscale(0.03,scatterplot( [f(300)],format=jittered ))):
> display([p1,p2]);
> f:=beta[5,2]:
> p1:=plot( statevalf[pdf,f](x), x=0..1):
> p2:=yshift(2.6,yscale( 0.2,scatterplot([f(300)],format=jittered ))):
> display([p1,p2]);
>