ETHZ_Logo RAMSES_Logo_Right   RAMSES   RAMSES_Logo_Left Systems Ecology  
Start    search button      Modules:   A-Z   Function   Layer        QuickRefs:   DM   AuxLib   AuxLibE   SciLib   EasyMW   MW   ISIS   RMSLib

DEFINITION MODULE StatLib;

  (*******************************************************************

    Module  StatLib     (Version 0.1)

      Copyright (c) 1988-2006 by Olivier Roth and ETH Zurich.

    Purpose   Basic statistical functions and procedures.

    Remarks   --


    Programming

      o Design
        Olivier Roth              04/09/1988

      o Implementation
        Olivier Roth              04/09/1988


    ETH Zurich
    Systems Ecology
    CHN E 35.1
    Universitaetstrasse 16
    8092 Zurich
    SWITZERLAND

    URLs:
        <mailto:RAMSES@env.ethz.ch>
        <http://www.sysecol.ethz.ch>
        <http://www.sysecol.ethz.ch/SimSoftware/RAMSES>


    Last revision of definition:  04/09/1988  OR

  *******************************************************************)


  TYPE
    FunctionXProc = PROCEDURE( REAL ): REAL;
    InRangeProc   = PROCEDURE( REAL, REAL, REAL ): BOOLEAN;



  PROCEDURE MinX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* MinX returns the minimum value of the first N reals of array X. *)


  PROCEDURE MaxX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* MaxX returns the maximum value of the first N reals of array X. *)


  PROCEDURE WSumX ( VAR X: ARRAY OF REAL;
                    N    : CARDINAL;
                    FX   : FunctionXProc ): REAL;
  (* WSumX returns the weighted sum of the first N reals of array X.    *)
  (* Each value is weighted according to the function FX. For instance, *)
  (* to compute the sum of the squares of the first 10 values of X, you *)
  (* should define a function such as Square( x: REAL ): REAL; , which  *)
  (* returns the square of x. Once this is done, WSumX( X, 10, Square );*)
  (* would return the sum of squares of the first 10 values of X.       *)


  PROCEDURE SumX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SumX returns the sum of X[i] for the first N values of X. *)


  PROCEDURE SumXY ( VAR X, Y: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SumXY returns the sum of X[i]*Y[i] for the first N values of X and Y.*)


  PROCEDURE SumX2 ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SumX2 returns the sum of X[i]^2 for the first N values of X. This  *)
  (* is somewhat faster than using WSumX as shown in the example above. *)


  PROCEDURE SumX3 ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SumX3 returns the sum of X[i]^3 for the first N values of X. *)


  PROCEDURE SumX4 ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SumX4 returns the sum of X[i]^4 for the first N values of X. *)


  PROCEDURE WMeanX ( VAR X: ARRAY OF REAL;
                     N    : CARDINAL;
                     FX   : FunctionXProc ): REAL;
  (* WMeanX returns the weighted mean of the first N reals of array X. *)
  (* Each X[i] is weighted according to the function FX.               *)


  PROCEDURE MeanX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* MeanX returns the mean of the first N reals of array X. *)


  PROCEDURE VarX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* VarX returns the variance of the first N reals of array X. *)


  PROCEDURE SDevX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SDevX returns the standard deviation of the first N reals of array X.*)


  PROCEDURE SkewX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* SkewX returns the skewness of the first N reals of array X.*)


  PROCEDURE KurtX ( VAR X: ARRAY OF REAL;  N: CARDINAL ): REAL;
  (* KurtX returns the kurtosis of the first N reals of array X.*)


  PROCEDURE LinearReg ( VAR X, Y     : ARRAY OF REAL;
                        N            : CARDINAL;
                        VAR a, b, r2 : REAL         );
  (* LinearReg performs linear regression analysis on the first N    *)
  (* values of X and Y. a and b are the coefficients of the best fit *)
  (* straight line, Y= ax+b; r2 is the coefficient of determination  *)
  (* approaches zero as the data fail to fit a straight line.        *)


  PROCEDURE FuncX ( VAR X, Y: ARRAY OF REAL;
                    N       : CARDINAL;
                    FX      : FunctionXProc );
  (* FuncX takes the first N values of array X and computes   *)
  (* the corresponding Y values such that Y[i]= FX( X[i] );.  *)


  PROCEDURE CountX ( VAR X      : ARRAY OF REAL;
                     N          : CARDINAL;
                     XLow, XHigh: REAL;
                     InRangeX   : InRangeProc  ): CARDINAL;
  (* CountX returns the number of X values (X[0]..X[N-1]) that meet    *)
  (* the criteria defined by the boolean function InRangeX. See the    *)
  (* description of InRangeProc above. Although XLow and XHigh are     *)
  (* commonly used to define a continuous range, this is not necessary.*)
  (* For instance, InRangeX( x, xLow, xHigh ) may be written to yield  *)
  (* TRUE if x is greater than XHigh or less than XLow.                *)


  PROCEDURE InsertX ( VAR X  : ARRAY OF REAL;
                      N, j   : CARDINAL;
                      xValue : REAL       );
  (* InsertX is an array manipulation procedure. It first shifts     *)
  (* X[j]..X[N-1] one index higher. xValue is then assigned to X[j]. *)
  (* Notice that the overall effect is to insert xValue into X[j].   *)
  (* Remember that the lower limit of open arrays is zero, and that  *)
  (* the value parameter N is not updated (i.e. incremented by 1).   *)


  PROCEDURE DeleteX ( VAR X  : ARRAY OF REAL;
                      N, j   : CARDINAL  );
  (* DeleteX is an array manipulation procedure. It deletes X[j] by  *)
  (* assigning X[i]:= X[N+1], for i:=j to N-1. This is the opposite  *)
  (* of InsertX.                                                     *)


  PROCEDURE ClearX ( VAR X  : ARRAY OF REAL;
                     N      : CARDINAL;
                     xValue : REAL       );
  (* ClearX is an array manipulation procedure. It assigns the xValue *)
  (* to the first N values of X.                                      *)


  PROCEDURE SortX ( VAR X: ARRAY OF REAL;  N: CARDINAL );
  (* SortX sorts the first N reals of array X in ascending order. This *)
  (* is an implementation of the QuickSort algorithm.                  *)


  PROCEDURE NormDist ( z1, z2 : REAL ): REAL;
  (* NormDist returns the area under the normal distribution curve whith  *)
  (* a lower limit of z1 and an upper limit of z2. Note that NormDist     *)
  (* returns 1.0 as z1 approaches negative infinity and z2 approaches     *)
  (* positive infinity. If X is a random variable, then one would expect  *)
  (* approxiamtely 68 percent of the observed values of X to fall whithin *)
  (* plus or minus one standard deviation of the mean of X.               *)


  PROCEDURE Factorial ( N: CARDINAL ): REAL;
  (* Factorial returns N! (N factorial).  *)


  PROCEDURE Combination ( N, R : CARDINAL ): REAL;
  (* Combination returns the number of combinations of N objects *)
  (* taken R at a time.                                          *)


  PROCEDURE Permutation ( N, R : CARDINAL ): REAL;
  (* Permutation returns the number of permutations of N objects *)
  (* taken R at a time.                                          *)


END StatLib.

  Contact RAMSES@env.ethz.ch Last updated: 25-Jul-2011 [Top of page]