
Quality Control : Binomial distribution
The binomial distribution is one that describes finite experiments with finite (discrete) outcomes. Ike
rolling a die for 20.000 times. Each time there are only 6 possible results. Each experiment is autonomous.
There is no history and there are no effects on later experiments.
At Dutch Match we have no application for the binomial distribution, but our competitors do! And that's good
for us!
Binomial : the source
Below is the source code for the program that calculates the data for graphing binomial distributions:
MODULE binomial;
IMPORT Arguments, InOut, MathLib, NumConv, RealConv;
VAR p, f : REAL;
n, x : CARDINAL;
buffer : Arguments.ArgTable;
count : SHORTCARD;
PROCEDURE fact (n : CARDINAL) : REAL;
VAR m : REAL;
BEGIN
IF (n = 0) OR (n = 1) THEN RETURN 1.0 END;
m := 1.0;
WHILE n > 1 DO
m := m * FLOAT (n);
DEC (n)
END;
RETURN m
END fact;
PROCEDURE over (n, m : CARDINAL) : REAL;
VAR result : REAL;
BEGIN
result := fact (n) / (fact (m) * fact (n - m));
RETURN result
END over;
PROCEDURE power (p : REAL; q : CARDINAL) : REAL;
VAR result : REAL;
BEGIN
result := 1.0;
WHILE q > 0 DO
result := result * p;
DEC (q)
END;
RETURN result
END power;
PROCEDURE Binomial (p : REAL; n, x : CARDINAL) : REAL;
VAR q, r : REAL;
BEGIN
q := 1.0 - p;
r := over (n, x);
RETURN r * power (p, (x)) * power (q, (n-x))
END Binomial;
PROCEDURE Init;
VAR ok : BOOLEAN;
BEGIN
Arguments.GetArgs (count, buffer);
IF count # 3 THEN
InOut.WriteString ("Syntax : binomial n mu");
InOut.WriteLn;
HALT
END;
NumConv.Str2Num (n, 10, buffer^[1]^, ok);
IF NOT ok THEN
InOut.WriteString (buffer^[1]^);
InOut.WriteString (" contains invalid tokens. Aborting.");
InOut.WriteLn;
HALT
END;
p := RealConv.Str2Real (buffer^[2]^, ok);
IF NOT ok THEN
InOut.WriteString (buffer^[2]^);
InOut.WriteString (" contains invalid tokens. Aborting.");
InOut.WriteLn;
HALT
END
END Init;
BEGIN
Init;
x := 1;
REPEAT
InOut.WriteCard (x, 8);
InOut.Write (11C);
f := Binomial (p, n, x);
InOut.WriteReal (f, 20, 10);
InOut.WriteLn;
x := x + 1
UNTIL x > n;
END binomial.
The program takes two arguments: classes and probability per chance like so:
jan@Beryllium:~/modula/sampl$ binomial 8 0.166
1 0.3727007806
2 0.2596392632
3 0.1033575982
4 0.0257154666
5 0.0040947408
6 0.0004075102
7 0.0000231746
8 0.0000005766
jan@Beryllium:~/modula/sampl$ binomial 8 0.166 >file
resulting in the following graph:

Additional graphs of binomial distributions
Some thoughts
As you can see in the bottom graph, some of the binomial distributions resemble the normal distribution. In effect, the gaussian distribution is the most versatile and it fits most datasets.
Page created on 15 September 2009 and
Page equipped with FroogleBuster technology