~ubuntu-branches/ubuntu/utopic/mricron/utopic

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
{ ******************************************************************
  Skewness and kurtosis
  ****************************************************************** }

unit uskew;

interface

uses
  utypes;

function Skewness(X : PVector; Lb, Ub : Integer; M, Sigma : Float) : Float;

function Kurtosis(X : PVector; Lb, Ub : Integer; M, Sigma : Float) : Float;

implementation

function Skewness(X : PVector; Lb, Ub : Integer; M, Sigma : Float) : Float;
  var
    S, T : Float;
    I    : Integer;
  begin
    S := 0.0;
    for I := Lb to Ub do
      begin
        T := (X^[I] - M) / Sigma;
        S := S + T * Sqr(T);
      end;
    Skewness := S / (Ub - Lb + 1);
  end;

function Kurtosis(X : PVector; Lb, Ub : Integer; M, Sigma : Float) : Float;
  var
    S, T : Float;
    I    : Integer;
  begin
    S := 0.0;
    for I := Lb to Ub do
      begin
        T := (X^[I] - M) / Sigma;
        S := S + Sqr(Sqr(T));
      end;
    Kurtosis := S / (Ub - Lb + 1) - 3.0;
  end;

end.