diff --git a/applications/lazstats/tests/beta_test/Project1.lpi b/applications/lazstats/tests/beta_test/Project1.lpi
new file mode 100644
index 000000000..525242287
--- /dev/null
+++ b/applications/lazstats/tests/beta_test/Project1.lpi
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/beta_test/Project1.pas b/applications/lazstats/tests/beta_test/Project1.pas
new file mode 100644
index 000000000..873389083
--- /dev/null
+++ b/applications/lazstats/tests/beta_test/Project1.pas
@@ -0,0 +1,66 @@
+program Project1;
+
+uses
+ SysUtils,
+ spe,
+ MathUnit;
+
+
+const
+ w = 15;
+// Numerical recipes
+
+function gammln(x: double): Double;
+{ gibt den Log der vollständigen Gamma-Funktion zurück (x>0).
+ Gamma(x) = integral ( t^(x-1) * exp(-t) dt ) (von 0 bis Unendlich)
+ (Log, um Floating Point Underflow zu vermeiden). }
+const
+ stp = 2.50662827465;
+var
+ xx,tmp,ser : extended;
+begin
+ if x<=0 then
+ raise Exception.Create('Argument für GammaLn ist negativ.');
+ if (x>1) then begin
+ xx := x - 1.0;
+ tmp := xx + 5.5;
+ tmp := (xx+0.5) * ln(tmp) - tmp;
+ ser := 1.0 + 76.18009173 /(xx+1.0) - 86.50532033/(xx+2.0)
+ + 24.01409822 /(xx+3.0) - 1.231739516/(xx+4.0)
+ + 0.120858003E-2/(xx+5.0) - 0.536382E-5/(xx+6.0);
+ result := tmp + ln(stp*ser);
+ end else
+ if (x<1) then
+ result := GammaLn(x+1.0) - ln(x)
+ else
+ if (x=1) then
+ result := 0.0;
+end;
+
+function Beta(a,b: Double) : Double;
+begin
+ Result := exp(gammln(a) + gammln(b) - gammln(a+b));
+end;
+
+procedure Test(a, b: Double);
+var
+ y_lazStats, y_numlib, y_numrecip: Double;
+begin
+ y_numlib := spe.beta(a, b);
+ y_lazstats := mathunit.beta(a, b);
+ y_numrecip := beta(a, b);
+ WriteLn(a:w:5, b:w:5, y_lazstats:w:5, y_numlib:w:5, y_numrecip:w:5);
+end;
+
+begin
+ WriteLn('Beta function');
+ WriteLn;
+ WriteLn('a':w, 'b':w, 'y(lazstats)':w, 'y(numlib)':w, 'y(Num.Recip)':w);
+ Test(0.5, 0.5);
+ Test(1.1, 2.3);
+ Test(2.3, 1.1);
+ Test(2.9, 0.1);
+ Test(5.1, 2.5);
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/betai_test/Project1.lpi b/applications/lazstats/tests/betai_test/Project1.lpi
new file mode 100644
index 000000000..525242287
--- /dev/null
+++ b/applications/lazstats/tests/betai_test/Project1.lpi
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/betai_test/Project1.pas b/applications/lazstats/tests/betai_test/Project1.pas
new file mode 100644
index 000000000..b78c4fe57
--- /dev/null
+++ b/applications/lazstats/tests/betai_test/Project1.pas
@@ -0,0 +1,107 @@
+program Project1;
+
+uses
+ SysUtils,
+ spe,
+ MathUnit;
+
+// Numerical recipes
+
+function BetaCf(a,b,x: Double) : Double;
+{ Kettenbruch-Entwicklung der unvollständigen Beta-Funktion }
+const
+ ItMax = 100;
+ EPS = 1E-9;
+var
+ tem, em, d : Double;
+ qap, qam, qab : Double;
+ bz, bpp, BP, bm : Double;
+ az, app, am, aold, ap : Double;
+ m : integer;
+begin
+ am := 1.0;
+ bm := 1.0;
+ az := 1.0;
+ qab := a+b;
+ qap := a+1.0;
+ qam := a-1.0;
+ bz := 1.0 - qab*x/qap;
+ for m:=1 to ItMax do begin
+ em := m;
+ tem := em+em;
+ d := em*(b-m)*x/((qam+tem)*(a+tem));
+ ap := az + d*am;
+ BP := bz + d*bm;
+ d := -(a+em)*(qab+em)*x/((a+tem)*(qap+tem));
+ app := ap + d*az;
+ bpp := BP + d*bz;
+ aOld:= az;
+ am := ap/bpp;
+ bm := BP/bpp;
+ az := app/bpp;
+ bz := 1.0;
+ if abs(az-aOld) < EPS*abs(az) then begin
+ result := az;
+ Exit;
+ end;
+ end;
+ raise Exception.Create('Kettenbruchentwicklung der unvollst.Beta-Funktion divergiert.');
+ // a oder b zu groß, oder ItMax zu klein
+end;
+
+function BetaI(a,b,x: Double): Double;
+{ berechnet die Unvollständige Beta-Funktion Ix(a,b) = Bx(a,b)/B(a,b),
+ /x a-1 b-1
+ wobei Bx(a,b) = | t * (1-t) dt
+ /0
+}
+var
+ bt : Double;
+begin
+ if (x<0.0) then
+ raise EMathError.Create('Argument der unvollst.Beta-Funktion ist <0.');
+ if (x>1.0) then
+ raise EMathError.Create('Argument der unvollst.Beta-Funktion ist >1.');
+ if (x=0.0) or (x=1.0) then
+ bt := 0.0
+ else
+ bt := exp(GammaLn(a+b) - GammaLn(a) - GammaLn(b) + a*ln(x) + b*ln(1.0-x));
+ if x < (a+1.0)/(a+b+2.0)
+ then result := bt * BetaCf(a,b,x)/a
+ else result := 1.0 - bt*BetaCf(b,a,1.0-x)/b;
+end;
+
+
+const
+ xmin = 0.0;
+ xmax = 1.0;
+ dx = 0.2;
+
+procedure Test(a, b: Double);
+var
+ i: Integer;
+ x, y_lazStats, y_numlib, y_numrecip: Double;
+begin
+ WriteLn('a = ', a:0:3, ' b = ', b:0:3);
+ WriteLn;
+ WriteLn('x':20, 'y(lazstats)':20, 'y(numlib)':20, 'y(Num.Recip)':20);
+ x := xmin;
+ while (x <= xmax) do begin
+ y_numlib := spe.betai(a, b, x);
+ y_lazstats := mathunit.betai(a, b, x);
+ y_numrecip := betai(a, b, x);
+
+ WriteLn(x:20:5, y_lazstats:20:5, y_numlib:20:5, y_numrecip:20:5);
+ x := x + dx;
+ end;
+end;
+
+begin
+ WriteLn('incomplete beta function');
+ WriteLn;
+ Test(0.5, 0.5);
+ Test(1.0, 2.0);
+ Test(2.0, 1.0);
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/gammaln_test/Project1.lpi b/applications/lazstats/tests/gammaln_test/Project1.lpi
new file mode 100644
index 000000000..525242287
--- /dev/null
+++ b/applications/lazstats/tests/gammaln_test/Project1.lpi
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/gammaln_test/Project1.pas b/applications/lazstats/tests/gammaln_test/Project1.pas
new file mode 100644
index 000000000..f12cabe67
--- /dev/null
+++ b/applications/lazstats/tests/gammaln_test/Project1.pas
@@ -0,0 +1,64 @@
+program Project1;
+
+uses
+ SysUtils,
+ spe,
+ MathUnit;
+
+// Numerical recipes
+function GammaLn(x: double): Double;
+{ gibt den Log der vollständigen Gamma-Funktion zurück (x>0).
+ Gamma(x) = integral ( t^(x-1) * exp(-t) dt ) (von 0 bis Unendlich)
+ (Log, um Floating Point Underflow zu vermeiden). }
+const
+ stp = 2.50662827465;
+var
+ xx,tmp,ser : extended;
+begin
+ if x<=0 then
+ raise Exception.Create('Argument für GammaLn ist negativ.');
+ if (x > 1) then begin
+ xx := x - 1.0;
+ tmp := xx + 5.5;
+ tmp := (xx+0.5) * ln(tmp) - tmp;
+ ser := 1.0 + 76.18009173 /(xx+1.0) - 86.50532033/(xx+2.0)
+ + 24.01409822 /(xx+3.0) - 1.231739516/(xx+4.0)
+ + 0.120858003E-2/(xx+5.0) - 0.536382E-5/(xx+6.0);
+ result := tmp + ln(stp*ser);
+ end else
+ if (x < 1) then
+ result := GammaLn(x+1.0) - ln(x)
+ else
+ if (x=1) then
+ result := 0.0;
+end;
+
+const
+ xmin = 1e-3;
+ xmax = 5.0;
+
+procedure Test;
+var
+ i: Integer;
+ x, y_lazStats, y_numlib, y_numrecip: Double;
+begin
+ WriteLn('x':20, 'y(lazstats)':20, 'y(numlib)':20, 'y(Num.Recipies)':20);
+ x := xmin;
+ while (x <= xmax) do begin
+ y_numlib := 1.0 - spelga(x);
+ y_lazstats := MathUnit.gammaln(x);
+ y_numrecip := gammaln(x);
+
+ WriteLn(x:20:6, y_lazstats:20:5, y_numlib:20:5, y_numrecip:20:5);
+ x := x*1.25
+// x := x + dx;
+ end;
+end;
+
+begin
+ WriteLn('GammaLn function');
+ WriteLn;
+ Test;
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/generate_dists/Distributions.lpi b/applications/lazstats/tests/generate_dists/Distributions.lpi
new file mode 100644
index 000000000..665bb08ba
--- /dev/null
+++ b/applications/lazstats/tests/generate_dists/Distributions.lpi
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/generate_dists/Distributions.pas b/applications/lazstats/tests/generate_dists/Distributions.pas
new file mode 100644
index 000000000..a800cc0ee
--- /dev/null
+++ b/applications/lazstats/tests/generate_dists/Distributions.pas
@@ -0,0 +1,25 @@
+program Distributions;
+
+uses
+ SysUtils, Math;
+
+const
+ MEAN = 56;
+ STDDEV = 12;
+ N = 5000;
+var
+ F: TextFile;
+ i: Integer;
+ x: Double;
+begin
+ AssignFile(F, '../../data/dists.csv');
+ Rewrite(F);
+ WriteLn(F, 'Index,Group,Value');
+ for i := 0 to N-1 do begin
+ x := RandG(MEAN, STDDEV);
+ WriteLn(F, i, ',', i div 5, ',', x:0:6);
+ end;
+ CloseFile(F);
+
+end.
+
diff --git a/applications/lazstats/tests/generate_normalDist/NormalDist.lpi b/applications/lazstats/tests/generate_normalDist/NormalDist.lpi
new file mode 100644
index 000000000..c540f8bb1
--- /dev/null
+++ b/applications/lazstats/tests/generate_normalDist/NormalDist.lpi
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/generate_normalDist/NormalDist.pas b/applications/lazstats/tests/generate_normalDist/NormalDist.pas
new file mode 100644
index 000000000..b301b3fb9
--- /dev/null
+++ b/applications/lazstats/tests/generate_normalDist/NormalDist.pas
@@ -0,0 +1,24 @@
+program NormalDist;
+
+uses
+ SysUtils, Math;
+
+const
+ MEAN = 56;
+ STDDEV = 12;
+ N = 5; //200;
+var
+ F: TextFile;
+ i: Integer;
+ x: Double;
+begin
+ AssignFile(F, '../../data/normal_dist_5.csv');
+ Rewrite(F);
+ WriteLn(F, 'Index,Value');
+ for i := 1 to N do begin
+ x := RandG(MEAN, STDDEV);
+ WriteLn(F, i, ',', x:0:6);
+ end;
+ CloseFile(F);
+end.
+
diff --git a/applications/lazstats/tests/matrix_test/MatrixTest.lpi b/applications/lazstats/tests/matrix_test/MatrixTest.lpi
new file mode 100644
index 000000000..590603608
--- /dev/null
+++ b/applications/lazstats/tests/matrix_test/MatrixTest.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/matrix_test/MatrixTest.lpr b/applications/lazstats/tests/matrix_test/MatrixTest.lpr
new file mode 100644
index 000000000..1e3446aca
--- /dev/null
+++ b/applications/lazstats/tests/matrix_test/MatrixTest.lpr
@@ -0,0 +1,51 @@
+program MatrixTest;
+
+uses
+ MatrixUnit;
+
+var
+ A: TDblMatrix;
+ B: TDblMatrix;
+
+procedure WriteMatrix(A: TDblMatrix; AName: String);
+var
+ n, m, i, j: Integer;
+begin
+ WriteLn(AName, ' = ');
+ MatSize(A, n,m);
+ for i := 0 to n-1 do
+ begin
+ for j := 0 to m-1 do
+ Write(A[i, j]:10:3);
+ WriteLn;
+ end;
+ WriteLn;
+end;
+
+begin
+ SetLength(A, 3, 3);
+ A[0, 0] := 1.0; A[0, 1] := 3.0; A[0, 2] := 4.0;
+ A[1, 0] := -1.0; A[1, 1] := 2.0; A[1, 2] := -3.0;
+ A[2, 0] := 0.0; A[2, 1] := -1.0; A[2, 2] := 1.0;
+ WriteMatrix(A, 'A');
+
+ SetLength(B, 3, 3);
+ B[0, 0] := -1.0; B[0, 1] := -3.0; B[0, 2] := 1.0;
+ B[1, 0] := +1.0; B[1, 1] := 2.0; B[1, 2] := -3.0;
+ B[2, 0] := 0.0; B[2, 1] := -2.0; B[2, 2] := 2.0;
+ WriteMatrix(B, 'B');
+
+ WriteMatrix(A*B, 'A*B');
+
+ WriteMatrix(MatInverse(A), 'inv(A)');
+
+ WriteMatrix(A*MatInverse(A), 'A*inv(A)');
+
+ WriteLn('det(A) = ');
+ WriteLn(MatDeterminant(A):10:3);
+
+ WriteLn;
+ WriteLn('Press ENTER to quit...');
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpi b/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpi
new file mode 100644
index 000000000..d8150ee87
--- /dev/null
+++ b/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpr b/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpr
new file mode 100644
index 000000000..8a3692f8f
--- /dev/null
+++ b/applications/lazstats/tests/mean_var_stdev_test/BasicStats_test.lpr
@@ -0,0 +1,26 @@
+program BasicStats_test;
+
+uses
+ MatrixUnit;
+
+var
+ v: TDblVector;
+ mu, variance, sig: Double;
+begin
+ SetLength(v, 5);
+ v[0] := 1.2;
+ v[1] := -4.3;
+ v[2] := 5.9;
+ v[3] := -9.6;
+ v[4] := 5.3;
+
+ VecMeanVarStdDev(v, mu, variance, sig);
+
+ WriteLn('Mean: ', mu:10:3);
+ WriteLn('Variance: ', variance:10:3);
+ WriteLn('Std.Dev.: ', sig:10:3);
+
+ ReadLn;
+
+end.
+
diff --git a/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpi b/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpi
new file mode 100644
index 000000000..984eb83c2
--- /dev/null
+++ b/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpr b/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpr
new file mode 100644
index 000000000..13226c06e
--- /dev/null
+++ b/applications/lazstats/tests/multiple_regression_test/multiple_regression.lpr
@@ -0,0 +1,100 @@
+program multiple_regression;
+
+uses
+ SysUtils, Classes,
+ Globals, MatrixUnit, RegressionUnit;
+
+var
+ L: TStrings;
+ xCols: IntDyneVec = nil;
+ yCol: Integer;
+ xData: TDblMatrix = nil;
+ yData: TDblVector = nil;
+ i, j: Integer;
+ sa: TStringArray = nil;
+ RegressionRes: TMultipleRegressionResults;
+ Labels: StrDyneVec = nil;
+
+const
+ W = 20;
+ D = 3;
+
+procedure WriteMatrix(A: TDblMatrix; RowLabels, ColLabels: StrDyneVec);
+ var
+ i,j: Integer;
+ n, m: Integer;
+ begin
+ MatSize(A, n,m);
+
+ Write('':W);
+ for j := 0 to High(ColLabels) do
+ Write(ColLabels[j]:W);
+ WriteLn;
+
+ for i := 0 to n-1 do
+ begin
+ Write(RowLabels[i]:W);
+ for j := 0 to m-1 do
+ Write(A[i,j]:W:D);
+ WriteLn;
+ end;
+ end;
+
+begin
+ DefaultFormatSettings.DecimalSeparator := '.';
+ SetLength(xCols, 2);
+ xCols[0] := 0;
+ xCols[1] := 1;
+
+ yCol := 5;
+
+ SetLength(Labels, Length(xCols) + 1);
+ Labels[High(Labels)] := 'Intercept';
+
+ L := TStringList.Create;
+ try
+ L.LoadFromFile('..\..\data\cansas.tab');
+
+ sa := L[0].Split(#9);
+ for j := 0 to High(xCols) do
+ Labels[j] := sa[xCols[j]];
+
+ SetLength(xData, L.Count-1, 2);
+ SetLength(yData, L.Count-1);
+ for i:=1 to L.Count-1 do
+ begin
+ sa := L[i].Split(#9);
+ for j := 0 to High(xCols) do
+ xData[i-1, xCols[j]] := StrToFloat(sa[xCols[j]]);
+ yData[i-1] := StrToFloat(sa[yCol]);
+ end;
+
+ Write('Index':10);
+ for j := 0 to High(xCols) do
+ Write(Labels[j]:10);
+ WriteLn(sa[yCol]:10);
+
+ //WriteLn('Index':10, sa[0]:10, sa[1]:10, sa[yCol]:10);
+ for i := 0 to High(yData) do
+ begin
+ Write(i:10);
+ for j := 0 to High(xCols) do
+ Write(xdata[i, j]:10:3);
+ WriteLn(yData[i]:10:3);
+ end;
+ WriteLn;
+ finally
+ L.Free;
+ end;
+
+ MultipleRegression(xData, yData, 0.95, RegressionRes);
+
+ for i := 0 to High(Labels) do
+ WriteLn('B[' + Labels[i] + '] =':20, RegressionRes.Coeffs[i]:W:D);
+ WriteLn;
+
+ WriteLn('Variance-Covariance Matrix');
+ WriteMatrix(RegressionRes.VarCovar, Labels, Labels);
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/normalDist/NormalDist_Test.lpi b/applications/lazstats/tests/normalDist/NormalDist_Test.lpi
new file mode 100644
index 000000000..bb05278d9
--- /dev/null
+++ b/applications/lazstats/tests/normalDist/NormalDist_Test.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/normalDist/NormalDist_Test.pas b/applications/lazstats/tests/normalDist/NormalDist_Test.pas
new file mode 100644
index 000000000..f0eca0b11
--- /dev/null
+++ b/applications/lazstats/tests/normalDist/NormalDist_Test.pas
@@ -0,0 +1,26 @@
+program NormalDist_Test;
+
+uses
+ MathUnit;
+
+const
+ dx = 0.2;
+ Range = 3.0;
+
+var
+ i: Integer;
+ x, p, z: Double;
+begin
+ WriteLn('x':20, 'p':20, 'z':20);
+
+ x := -Range;
+ while x <= Range do begin
+ p := NormalDist(x);
+ z := InverseNormaldist(p);
+ WriteLn(x:20:5, p:20:5, z:20:5);
+ x := x + dx;
+ end;
+
+ Readln;
+end.
+
diff --git a/applications/lazstats/tests/poisson_test/project1.lpi b/applications/lazstats/tests/poisson_test/project1.lpi
new file mode 100644
index 000000000..30bd5bce1
--- /dev/null
+++ b/applications/lazstats/tests/poisson_test/project1.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/poisson_test/project1.lpr b/applications/lazstats/tests/poisson_test/project1.lpr
new file mode 100644
index 000000000..928ca7f3a
--- /dev/null
+++ b/applications/lazstats/tests/poisson_test/project1.lpr
@@ -0,0 +1,50 @@
+program project1;
+
+uses
+ Math,
+ MathUnit;
+
+function Factorial(x: integer): longint; //integer;
+var
+ decx: longint; // integer;
+ product: longint; //integer;
+begin
+ decx := x;
+ product := 1;
+ while (decx > 0) do
+ begin
+ product := decx * product;
+ decx := decx - 1;
+ end;
+ result := product;
+end;
+
+function PoissonPDF_old(x: integer; a: double): Double;
+begin
+ if (x < 0) then
+ Result := 0.0
+ else
+ Result := exp(-a) * power(a, x) / factorial(x);
+end;
+
+procedure Test(a: Double; delta: Integer);
+var
+ i, n: Integer;
+begin
+ WriteLn('a = ', a:0:5);
+ WriteLn;
+ WriteLn(' n Poisson PoissonPDF_old ');
+ WriteLn('---------- ------------------- -------------------');
+ for i := 0 to 20 do begin
+ n := i * delta;
+ WriteLn(n:10, PoissonPDF(n, a):20:5, PoissonPDF_old(n, a):20:5);
+ end;
+ WriteLn;
+end;
+
+begin
+ Test(9, 1);
+ ReadLn;
+
+end.
+
diff --git a/applications/lazstats/tests/probf_test/Project1.lpi b/applications/lazstats/tests/probf_test/Project1.lpi
new file mode 100644
index 000000000..525242287
--- /dev/null
+++ b/applications/lazstats/tests/probf_test/Project1.lpi
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/probf_test/Project1.pas b/applications/lazstats/tests/probf_test/Project1.pas
new file mode 100644
index 000000000..78d85b0eb
--- /dev/null
+++ b/applications/lazstats/tests/probf_test/Project1.pas
@@ -0,0 +1,68 @@
+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.
+
diff --git a/applications/lazstats/tests/quicksort_test/project1.lpi b/applications/lazstats/tests/quicksort_test/project1.lpi
new file mode 100644
index 000000000..30bd5bce1
--- /dev/null
+++ b/applications/lazstats/tests/quicksort_test/project1.lpi
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/quicksort_test/project1.lpr b/applications/lazstats/tests/quicksort_test/project1.lpr
new file mode 100644
index 000000000..82ddd2d4e
--- /dev/null
+++ b/applications/lazstats/tests/quicksort_test/project1.lpr
@@ -0,0 +1,89 @@
+program project1;
+
+uses
+ math;
+
+type
+ DblDyneVec = array of double;
+
+ procedure Exchange(var a, b: Double);
+var
+ tmp: Double;
+begin
+ tmp := a;
+ a := b;
+ b := tmp;
+end;
+
+
+procedure QuickSortOn(X: DblDyneVec; Y: DblDyneVec = nil; Z: DblDyneVec = nil);
+
+ procedure DoQuickSort(L, R: Integer);
+ var
+ I,J: Integer;
+ P: Integer;
+ begin
+ repeat
+ I := L;
+ J := R;
+ P := (L + R) div 2;
+ repeat
+ while CompareValue(X[P], X[I]) > 0 do inc(I);
+ while CompareValue(X[P], X[J]) < 0 do dec(J);
+ if I <= J then begin
+ if I <> J then begin
+ Exchange(X[I], X[J]);
+ if Y <> nil then
+ Exchange(Y[I], Y[J]);
+ if Z <> nil then
+ Exchange(Z[I], Z[J]);
+ end;
+
+ if P = I then
+ P := J
+ else if P = J then
+ P := I;
+
+ inc(I);
+ dec(J);
+ end;
+ until I > J;
+
+ if L < J then
+ DoQuickSort(L, J);
+
+ L := I;
+ until I >= R;
+ end;
+
+begin
+ DoQuickSort(0, High(X));
+end;
+
+
+var
+ x: DblDyneVec;
+ y: DblDyneVec;
+ i: Integer;
+begin
+ SetLength(x, 10);
+ SetLength(y, 10);
+
+ for i := 0 to High(x) do
+ begin
+ x[i] := Random(100);
+ y[i] := i;
+ end;
+
+ for i := 0 to High(x) do
+ WriteLn('i: x=', x[i]:0:0, ' y=', y[i]:0:0);
+ WriteLn;
+
+ QuickSortOn(X, Y);
+
+ for i := 0 to High(x) do
+ WriteLn(i, ': x=', x[i]:0:0, ' y=', y[i]:0:0);
+
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/tdist_test/Project1.lpi b/applications/lazstats/tests/tdist_test/Project1.lpi
new file mode 100644
index 000000000..525242287
--- /dev/null
+++ b/applications/lazstats/tests/tdist_test/Project1.lpi
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/tdist_test/Project1.pas b/applications/lazstats/tests/tdist_test/Project1.pas
new file mode 100644
index 000000000..7c8197ada
--- /dev/null
+++ b/applications/lazstats/tests/tdist_test/Project1.pas
@@ -0,0 +1,49 @@
+program Project1;
+
+uses
+ spe,
+ MathUnit;
+
+const
+ xmin = 0.0;
+ xmax = 3.0;
+ dx = 0.5;
+ DF = 10;
+
+procedure Test(s: Integer);
+var
+ i: Integer;
+ x, y_lazStats, y_numlib: Double;
+ ok: string;
+begin
+ WriteLn('Student''s t distribution with ', DF, ' degrees of freedom (', s, '-sided)');
+ WriteLn;
+ WriteLn('x':15, 'y(lazstats)':15, 'y(numlib)':15, 'OK':15);
+ x := xmin;
+ while (x <= xmax) do begin
+ if x < 0 then
+ y_numlib := 1.0 - spe.tDist(-x, DF, s)
+ else
+ y_numlib := spe.tDist(x, DF, s);
+
+ if x < 0 then
+ y_lazstats := 1.0 - mathunit.tDist(-x, DF, s=1)
+ else
+ y_lazstats := mathunit.tDist(x, DF, s=1);
+
+ if abs(y_lazstats - y_numlib) < 1E-6 then
+ ok := 'OK'
+ else
+ ok := 'ERROR';
+
+ WriteLn(x:15:5, y_lazstats:15:5, y_numlib:15:5, ok:15);
+ x := x + dx;
+ end;
+end;
+
+begin
+ Test(1);
+ Test(2);
+ ReadLn;
+end.
+
diff --git a/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.lpi b/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.lpi
new file mode 100644
index 000000000..28f9c857b
--- /dev/null
+++ b/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.lpi
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.pas b/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.pas
new file mode 100644
index 000000000..e5d85d70f
--- /dev/null
+++ b/applications/lazstats/tests/test_file_linear_regression_2vars/Project1.pas
@@ -0,0 +1,43 @@
+program Project1;
+
+{$mode objfpc}{$H+}
+
+uses
+ Math, SysUtils;
+
+const
+ v1Min = 1.0;
+ v1Max = 3.0;
+ dv1 = 0.5;
+ v2Min = 1.0;
+ v2Max = 5.0;
+ dv2 = 0.5;
+ a = 1.0;
+ b = -2.0;
+ c = 100;
+ EPS = 1E-3;
+ REL_ERROR = 0.02;
+var
+ v1, v2, res, dres: Double;
+ F: TextFile;
+begin
+ AssignFile(F, 'linear_regression_2vars.csv');
+ Rewrite(F);
+ WriteLn(F, 'Var1,Var2,Result,Weights');
+ v1 := v1Min;
+ while v1 <= v1Max + EPS do
+ begin
+ v2 := v2min;
+ while v2 <= v2Max + EPS do
+ begin
+ res := a * v1 + b * v2 + c;
+ dres := res * REL_ERROR;
+ res := res + RandG(0, dres);
+ WriteLn(F, v1:0:3, ',', v2:0:3, ',', res:0:3, ',', dres:0:3);
+ v2 := v2 + dv2;
+ end;
+ v1 := v1 + dv1;
+ end;
+ CloseFile(F);
+end.
+
diff --git a/applications/lazstats/tests/test_file_linear_regression_2vars/linear_regression_2vars.csv b/applications/lazstats/tests/test_file_linear_regression_2vars/linear_regression_2vars.csv
new file mode 100644
index 000000000..ac7b5852b
--- /dev/null
+++ b/applications/lazstats/tests/test_file_linear_regression_2vars/linear_regression_2vars.csv
@@ -0,0 +1,46 @@
+Var1,Var2,Result,Weights
+1.000,1.000,101.303,1.980
+1.000,1.500,98.948,1.960
+1.000,2.000,97.581,1.940
+1.000,2.500,96.294,1.920
+1.000,3.000,92.779,1.900
+1.000,3.500,96.929,1.880
+1.000,4.000,91.985,1.860
+1.000,4.500,87.666,1.840
+1.000,5.000,91.985,1.820
+1.500,1.000,104.830,1.990
+1.500,1.500,100.972,1.970
+1.500,2.000,96.430,1.950
+1.500,2.500,95.186,1.930
+1.500,3.000,95.242,1.910
+1.500,3.500,95.213,1.890
+1.500,4.000,94.267,1.870
+1.500,4.500,93.557,1.850
+1.500,5.000,86.453,1.830
+2.000,1.000,102.153,2.000
+2.000,1.500,97.784,1.980
+2.000,2.000,101.588,1.960
+2.000,2.500,94.775,1.940
+2.000,3.000,96.103,1.920
+2.000,3.500,90.236,1.900
+2.000,4.000,92.888,1.880
+2.000,4.500,94.597,1.860
+2.000,5.000,91.581,1.840
+2.500,1.000,100.905,2.010
+2.500,1.500,100.197,1.990
+2.500,2.000,99.556,1.970
+2.500,2.500,100.463,1.950
+2.500,3.000,100.175,1.930
+2.500,3.500,92.495,1.910
+2.500,4.000,94.235,1.890
+2.500,4.500,94.055,1.870
+2.500,5.000,94.926,1.850
+3.000,1.000,102.017,2.020
+3.000,1.500,97.621,2.000
+3.000,2.000,97.911,1.980
+3.000,2.500,94.880,1.960
+3.000,3.000,94.850,1.940
+3.000,3.500,96.151,1.920
+3.000,4.000,93.255,1.900
+3.000,4.500,92.598,1.880
+3.000,5.000,90.753,1.860