~ubuntu-branches/ubuntu/oneiric/mricron/oneiric

« back to all changes in this revision

Viewing changes to fpmath/uibtdist.pas

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-29 22:07:43 UTC
  • Revision ID: james.westby@ubuntu.com-20100729220743-q621ts2zj806gu0n
Tags: upstream-0.20100725.1~dfsg.1
ImportĀ upstreamĀ versionĀ 0.20100725.1~dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ ******************************************************************
 
2
  Probability functions related to the incomplete Beta function
 
3
  ****************************************************************** }
 
4
 
 
5
unit uibtdist;
 
6
 
 
7
interface
 
8
 
 
9
uses
 
10
  utypes, umath, uibeta;
 
11
 
 
12
function FBeta(A, B, X : Float) : Float;
 
13
{ Cumulative probability for Beta distrib. with param. A and B }
 
14
 
 
15
function FBinom(N : Integer; P : Float; K : Integer) : Float;
 
16
{ Cumulative probability for binomial distrib. }
 
17
 
 
18
function FStudent(Nu : Integer; X : Float) : Float;
 
19
{ Cumulative probability for Student distrib. with Nu d.o.f. }
 
20
 
 
21
function PStudent(Nu : Integer; X : Float) : Float;
 
22
{ Prob(|t| > X) for Student distrib. with Nu d.o.f. }
 
23
 
 
24
function FSnedecor(Nu1, Nu2 : Integer; X : Float) : Float;
 
25
{ Cumulative prob. for Fisher-Snedecor distrib. with Nu1 and Nu2 d.o.f. }
 
26
 
 
27
function PSnedecor(Nu1, Nu2 : Integer; X : Float) : Float;
 
28
{ Prob(F > X) for Fisher-Snedecor distrib. with Nu1 and Nu2 d.o.f. }
 
29
 
 
30
implementation
 
31
 
 
32
function FBeta(A, B, X : Float) : Float;
 
33
begin
 
34
  FBeta := IBeta(A, B, X);
 
35
end;
 
36
 
 
37
function FBinom(N : Integer; P : Float; K : Integer) : Float;
 
38
begin
 
39
  if (P < 0.0) or (P > 1.0) or (N <= 0) or (N < K) then
 
40
    FBinom := DefaultVal(FDomain, 0.0)
 
41
  else if K = 0 then
 
42
    FBinom := DefaultVal(FOk, Power(1.0 - P, N))
 
43
  else if K = N then
 
44
    FBinom := DefaultVal(FOk, 1.0)
 
45
  else
 
46
    FBinom := 1.0 - IBeta(K + 1, N - K, P);
 
47
end;
 
48
 
 
49
function FStudent(Nu : Integer; X : Float) : Float;
 
50
var
 
51
  F : Float;
 
52
begin
 
53
  if Nu < 1 then
 
54
    FStudent := DefaultVal(FDomain, 0.0)
 
55
  else if X = 0 then
 
56
    FStudent := DefaultVal(FOk, 0.5)
 
57
  else
 
58
    begin
 
59
      F := 0.5 * IBeta(0.5 * Nu, 0.5, Nu / (Nu + X * X));
 
60
      if X < 0.0 then FStudent := F else FStudent := 1.0 - F;
 
61
    end;
 
62
end;
 
63
 
 
64
function PStudent(Nu : Integer; X : Float) : Float;
 
65
begin
 
66
  if Nu < 1 then
 
67
    PStudent := DefaultVal(FDomain, 0.0)
 
68
  else
 
69
    PStudent := IBeta(0.5 * Nu, 0.5, Nu / (Nu + X * X));
 
70
end;
 
71
 
 
72
function FSnedecor(Nu1, Nu2 : Integer; X : Float) : Float;
 
73
begin
 
74
  if (Nu1 < 1) or (Nu2 < 1) or (X <= 0) then
 
75
    FSnedecor := DefaultVal(FDomain, 0.0)
 
76
  else
 
77
    FSnedecor := 1.0 - IBeta(0.5 * Nu2, 0.5 * Nu1, Nu2 / (Nu2 + Nu1 * X));
 
78
end;
 
79
 
 
80
function PSnedecor(Nu1, Nu2 : Integer; X : Float) : Float;
 
81
begin
 
82
  if (Nu1 < 1) or (Nu2 < 1) or (X <= 0) then
 
83
    PSnedecor := DefaultVal(FDomain, 0.0)
 
84
  else
 
85
    PSnedecor := IBeta(0.5 * Nu2, 0.5 * Nu1, Nu2 / (Nu2 + Nu1 * X));
 
86
end;
 
87
 
 
88
end.
 
 
b'\\ No newline at end of file'