libs that i found on the net
example of counting Pearson Correlation and binom probability
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
unit uMyMath; interface uses System.SysUtils, System.Classes, Math; type TMyMath = class(TDataModule) public class function CorrelPearson(x, y: TArray<double>): double; class function Factorial(aNumber: Integer): extended; class function BinomProbability(k, n: Integer; p: double): extended; class function BinominalKoeff(k, n: Integer): extended; class function AlphaCronbah(avCorr:Double; n: Integer): extended; end; implementation {%CLASSGROUP 'Vcl.Controls.TControl'} {$R *.dfm} class function TMyMath.AlphaCronbah(avCorr:Double; n: Integer): extended; var d1, d2, d3:double; begin d1 := avCorr * n; d2 := 1 + (n-1) * avCorr; result := d1 / d2; end; class function TMyMath.BinominalKoeff(k, n: Integer): extended; var d1, d2, d3: extended; begin d1 := Factorial(n); d2 := Factorial(n - k); d3 := Factorial(k); Result := d1 / (d2 * d3); end; class function TMyMath.BinomProbability(k, n: Integer; p: double): extended; var bk: Double; p1, p2: Extended; begin bk := BinominalKoeff(k, n); p1 := Power(p, k); p2 := Power(1 - p, n - k); Result := bk * p1 * p2; end; class function TMyMath.CorrelPearson(x, y: TArray<double>): double; var d1, d2, d3, d4: double; i: Integer; begin d1 := 0.00; d2 := 0.00; d3 := 0.00; d4 := 0.00; for i := Low(x) to High(x) do begin d1 := d1+(x[i]-mean(x))*(y[i]-mean(y)); d2 := d2+Power((x[i]-mean(x)),2); d3 := d3+Power((y[i]-mean(y)),2); end; d4 := Sqrt(d2 * d3); Result := d1 / d4; end; class function TMyMath.Factorial(aNumber: Integer): extended; var i: Integer; begin if aNumber < 0 then raise Exception.Create('The factorial function is not defined for negative integers.'); Result := 1; for i := 1 to aNumber do Result := Result * i; end; end. |