Files
wp_xxyyzz 21484fc4bd LazStats: Add tests.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7925 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2020-12-05 19:03:07 +00:00

69 lines
1.5 KiB
ObjectPascal

program Project1;
uses
spe,
MathUnit;
const
xmax = 3.0;
dx = 0.5;
// values calculated by Excel (FDIST(x,df1,df2))
VALUES_10_20: array[0..6] of Double = (
0, 0.129839626, 0.524499532, 0.789053537, 0.910217285, 0.961096364, 0.982490459
);
VALUES_20_4: array[0..6] of Double = (
0, 0.13334765, 0.430681554, 0.622552784, 0.736037189, 0.806299776, 0.852248272
);
procedure Test(DF1, DF2: Integer);
var
i: Integer;
x, y_lazStats, y_numlib, y_excel: Double;
ok: string;
excel: Boolean;
begin
excel := ((DF1 = 20) and (DF2 = 4)) or ((DF1 = 10) and (DF2 = 20));
WriteLn('F distribution with ', DF1, ' and ', DF2, ' degrees of freedom');
WriteLn('---------------------------------------------------------------');
Write('x':15, 'y(lazstats)':15, 'y(numlib)':15);
if excel then Write('y(Excel)':15);
WriteLn('OK':15);
x := 0.0;
i := 0;
while (x <= xmax) do begin
y_numlib := FDist(x, DF1, DF2);
y_lazstats := ProbF(x, DF1, DF2);
if (DF1 = 20) and (DF2 = 4) then
y_Excel := 1.0 - VALUES_20_4[i]
else
if (DF1 = 10) and (DF2 = 20) then
y_Excel := 1.0 - VALUES_10_20[i]
else
y_Excel := 999.999;
if abs(y_lazstats - y_numlib) < 1E-6 then
ok := 'OK'
else
ok := 'ERROR';
Write(x:15:5, y_lazstats:15:5, y_numlib:15:5);
if excel then Write(y_Excel:15:5);
WriteLn(ok:15);
x := x + dx;
inc(i);
end;
WriteLn;
end;
begin
Test(20, 4);
Test(10, 20);
ReadLn;
end.