DEFINITION MODULE StatLib;
(*------------------------------------------------------------------------*)
(* Modul fuer einige Statistikfunktionen. *)
(* Modul for some statistical functions. *)
(*------------------------------------------------------------------------*)
(* Implementation : Michael Riedl *)
(* Licence : GNU Lesser General Public License (LGPL) *)
(*------------------------------------------------------------------------*)
(* $Id: StatLib.def,v 1.4 2015/10/09 07:34:32 mriedl Exp $ *)
PROCEDURE CDF(x : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* Kummulative Verteilungsfunktion d. Standartverteilungsfunktion *)
(* Cumulative Distribution Function *)
(* *)
(* Calculates the probability integral *)
(* *)
(* $cdf(x) = {1 \over {2\pi}} \int_{-\inf}^x exp{-\half x^2} dx$ *)
(* *)
(* of the standard normal distribution *)
(*----------------------------------------------------------------*)
PROCEDURE InvProbInt(p : LONGREAL;
genau : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* InvProbInt = Inverses Wahrscheinlichekitsintegal *)
(* Berechnet aus dem normierte Wahrscheinlichkeitsintegral *)
(* *)
(* \Phi(x) = {1 \over \sqrt{2\pi} *)
(* \int_{-\inf}^x exp{-\half x^2} *)
(* *)
(* dasjenige x_p, f"ur das \Phi(x_p) = p *)
(* *)
(* Die Genauigkeit der Routine duerft bei ca. 4-5 Stellen liegen *)
(* *)
(* Auch : Quantil der Standartnormalverteilung (typische Werte) *)
(* *)
(* 0.750 0.67449 | 0.800 0.84162 | 0.900 1.28155 | 0.950 1.64485 *)
(* 0.975 1.95996 | 0.990 2.32635 | 0.995 2.57583 | 0.999 3.09023 *)
(* *)
(* https://en.wikipedia.org/wiki/Quantile_function *)
(* https://de.wikipedia.org/wiki/Tabelle_Standardnormalverteilung *)
(* *)
(* This function calculates the inverse of the probability *)
(* integral for \Phi(x) (see formula above). *)
(* *)
(* This function is the invers of the CDF function given in this *)
(* module, if you plot x,CDF(x) and InvProbInt(x),x that should *)
(* be approximately the same line. This function should be exact *) (* to about 4-5 decimal digits in the worst case. *)
(*----------------------------------------------------------------*)
PROCEDURE StudentT(n : CARDINAL;
Alpha : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* Berechnet den Studentschen t-Koeffizenten f"ur n *)
(* Freiheitsgrade und statistischer Sicherheit Alpha. *)
(*----------------------------------------------------------------*)
PROCEDURE Fisher(m,n : INTEGER;
x : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* Based on ACM Algorithm 322 *)
(* *)
(* Probabilities in several variance distributions *)
(* *)
(* References: *)
(* Egon Dorrer, "Algorithm 322: F-Distribution [S14]", *)
(* Communications of the ACM, Vol 11(2), 1968, p116-117. *)
(* *)
(* Probabilities are returned as the integral of P(q)dq for q *)
(* in the range zero to X (F-ratio and chi-square) or from *)
(* -X to +X (Student's t and Normal). *)
(* *)
(* For F-ratios: *)
(* M = numerator degrees of freedom *)
(* N = denominator degrees of freedom *)
(* X = F-ratio *)
(* For Student's t (two tailed): *)
(* M = 1 *)
(* N = Degrees of freedom *)
(* X = The square of t *)
(* For normal deviates (two tailed): *)
(* M = 1 *)
(* N = 5000 *)
(* X = The square of the deviate *)
(* For chi-square: *)
(* M = Degrees of freedom *)
(* N = 5000 *)
(* X = Chi-square/M *)
(* *)
(* The returned probability will be in the range 0 to 1, unless *)
(* an error occurred, in which case -1.0 is returned. *)
(* Recoded by LW, 28-Mar-94. *)
(*----------------------------------------------------------------*)
PROCEDURE FisherM2(VAR m,n : INTEGER;
VAR x : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* VAR m,n,x wg. FORTRAN, wird nur in der Testroutine benoetigt, *)
(* nicht zu direkten Gebrauch. *)
(* Not for direct use - needed only in the Fortran test routine *)
(*----------------------------------------------------------------*)
PROCEDURE Student(df : INTEGER;
t : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* Call to Fisher with M=1, N=degrees of freedom, x=t**2 *)
(*----------------------------------------------------------------*)
PROCEDURE InvNorm(P : LONGREAL) : LONGREAL;
(*----------------------------------------------------------------*)
(* Inverse normal cumulative distribution function. *)
(* Relative error less than 1.15��10���9 in the interval (0,0.97575) *)
(* *)
(* Derived from FORTRAN IV code of Ren-Raw Chen, rutgers business *)
(* school, based on an algorith of Peter John Acklam *)
(* *)
(* For details see: *)
(* *)
(* http://home.online.no/~pjacklam/notes/invnorm *)
(* *)
(*----------------------------------------------------------------*)
PROCEDURE Wilcoxon(VAR X,Y : ARRAY OF LONGREAL;
nx,ny : CARDINAL;
Alpha : LONGREAL;
VAR NInv : CARDINAL;
VAR Uxy,Ua : LONGREAL;
VAR iFehl : CARDINAL) : BOOLEAN;
(*----------------------------------------------------------------*)
(* Wilcoxon - Test. (Status Beta) *)
(* *)
(* Dient der Pruefung der Hypothese, ob zwei Stichproben X und Y *)
(* vom Umfang nx bzw. ny zum Signifikanzniveau Alpha ein und *)
(* derselben Grundgesamtheit entstammen. Ist die der Fall, gibt *)
(* die Routine TRUE zurueck, ansonsten FALSE. *)
(* Vorgaben fuer die kritischen Werte sind fuer ny+ny < 50 *)
(* und Alpha = 0,10 | 0.05 | 0.02 | 0.01 hinterlegt. *)
(* *)
(* Lit. : Bronstein, I.N.; Semendjaev, K.A.; 'Taschenbuch der *)
(* Mathematik', Teubner, Leipzig (DDR), 1985. *)
(* *)
(* X : erste Stichprobe mit nx Elementen *)
(* Y : zweite Stichprobe mit ny Elementen *)
(* Alpha : statistischer Sicherheit *)
(* NInv : Anzahl der Inversionen *)
(* Uxy : ABS(((nx*ny / 2) - Anzahl der Inversionen) *)
(* Ua : kritischer Wert (aus Tabelle oder berechnet) *)
(* iFehl = 1 : Kein Vorgabewert fuer den kritischen Wert fuer *)
(* gewaehltes Alpha *)
(* 2 : Berechneter kritischer Wert fuer kleine Proben- *)
(* groesse da kein Vorgabewert vorhanden. *)
(* 98 : Speicherallokationsfehler. *)
(* 99 : Interner Fehler - sollte nicht vorkommen *)
(* *)
(* Fuer IFehl # 0 wird Errors.Fehlerflag entsprechend gesetzt. *)
(*----------------------------------------------------------------*)
END StatLib.