|
|
|
|
||
|
DEFINITION MODULE StatAux; (******************************************************************* Module StatAux (Version 1.0) Copyright (c) 1992-2006 by Dimitrios Gyalistras and ETH Zurich. Purpose Various statistical functions and procedures. Remarks Missing data are recognized and returned as DMConversions.UndefREAL(). Programming o Design Dimitrios Gyalistras 11/11/1992 o Implementation Dimitrios Gyalistras 11/11/1992 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: 19/12/1996 DG *******************************************************************) PROCEDURE GaussIntegr( z1, z2 : REAL ): REAL; (* Returns the integral of the Gaussian (normal N(0,1)) distribution from lower limit "z1" to upper limit "z2". Note that GaussIntegr returns 1.0 as "z1" approaches negative infinity and "z2" approaches positive infinity. *) PROCEDURE Chi2Integr( nDegFree:INTEGER; chi2:REAL ):REAL; (* Returns the integral from 0.0 to "chi2" under the Chi-Square distribution curve with "nDegFree" degrees of freedom. *) PROCEDURE SimpleChi2NormDistrTest( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; minClWidth : INTEGER; (* n values per interval, recommended ≥ 5 *) muTst : REAL; sigTst : REAL; VAR chi2 : REAL; (* the goodness-of fit statistic *) VAR nDegFree : INTEGER; (* degrees of freedom *) VAR sgnfLev : REAL); (* significance level in % *) (* Returns in "sgnfLev" the siginficance level (in %) at which the hypothesis is accepted, that the distribution of the first "nElems" elements given in "data" are normally distributed with N(muTst,sigTst). If "muTst" or "sigTst" equals DMConversions.UndefREAL(), the parameters of the Normal distribution against which the test is to be performed are determined by means of the maximum likelihood method from "data". Description of the test: 1) Hypothesis Ho: the sample stems from the distribution N(muTst,sigTst). 2) Variable chi2 measures the difference between the sample and the test distribution as follows: chi2 = Sum(elemsInClass-expectedElems)^2/(elemsInClass) This variable follows a Chi-Square(nDegFree) distribution, where nDegFree = Number of classes-2-1. 3) Under the Chi-Square(nDegFree) distribution a value > chi2 occurs with a probability pThresh = 1-sgnfLev. If pThresh is very low, then sgnfLev=1-pThresh is very high, so that "it is likely that Ho is true". Better: "Ho can not be rejected". Note, rejection is more difficult, the smaller the sample size. *) PROCEDURE RobustChi2NormDistrTest( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; muTst : REAL; sigTst : REAL ): REAL; (* Returns the mean "sgnfLev"-value from multiple calls to "SimpleChi2NormDistrTest" using "minClWidth" = [5..Min((nElems DIV 8),20)] *) (*----------------------------------------------------------------*) PROCEDURE LinStats( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; VAR nValid : INTEGER; VAR mu,sig,trd : REAL; VAR trdFVal : REAL ); (* Returns number of non-missing values, mean, standard deviation, and trend of first "nElems" elements in "data". "trdFVal" is the F-value of the test Ho:[regSlope=0] of the regression of data from a linearly increasing function. *) PROCEDURE Skewness( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; mu,sig : REAL ):REAL; (* Returns skewness (3d moment) of the first "nElems" from "data". Requires the mean and standard deviation of the data as an input. *) PROCEDURE Extrema( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; VAR min,max : REAL ); (* Returns skewness (3d moment) of the first "nElems" from "data". *) PROCEDURE Ranges( VAR data : ARRAY OF REAL; (* VAR for speed-up only *) nElems : INTEGER; VAR min, max, med, low50, up50, low80, up80, low90, up90 : REAL); (* Meaning of lowRR, upRR: "values containing RR% of all numbers in a". *) (*----------------------------------------------------------------*) PROCEDURE LinReg( VAR xx,yy: ARRAY OF REAL; nElems: INTEGER; VAR nn, xmu, ymu, sxx, syy, sxy, a ,b, cor: REAL ); (* Returns parameters of linear regression "y = a*x + b". *) (*----------------------------------------------------------------*) PROCEDURE Max(i,j: INTEGER):INTEGER; PROCEDURE Min(i,j: INTEGER):INTEGER; PROCEDURE MuSigI( VAR data: ARRAY OF INTEGER; nElems: INTEGER; VAR mu,sig: REAL ); (*----------------------------------------------------------------*) PROCEDURE RunMean(nRMElems,nElems: INTEGER; VAR data: ARRAY OF REAL); (*----------------------------------------------------------------*) PROCEDURE QuickSortXY ( VAR a: ARRAY OF REAL; VAR b, c: ARRAY OF INTEGER; n: CARDINAL ); PROCEDURE Histogram( nElems : INTEGER; VAR data : ARRAY OF REAL; (* VAR for speed up only *) minFirstClass : REAL; VAR maxLastClass : REAL; (* will be adjusted if too large to fit histogram *) classWidth : REAL; VAR nBelowFirstClass : INTEGER; VAR nAboveLastClass : INTEGER; VAR histogram : ARRAY OF INTEGER ); (* Returns histogram of the first nElems in data. The first class starts at minFirstClass. Values falling on a class border are attributed to the higher class. *) PROCEDURE BuildClasses( nElems : INTEGER; VAR attr : ARRAY OF REAL; (* VAR for speed up only *) VAR data : ARRAY OF REAL; (* VAR for speed up only *) classWidth : REAL; threshhold : REAL; VAR nClasses : INTEGER; VAR nInClass, nCumul : ARRAY OF INTEGER; VAR minOfClass, maxOfClass, meanOfClass : ARRAY OF REAL; VAR nBelowThresh : INTEGER; VAR nInClassBelowThresh, nCumulBelowThresh : ARRAY OF INTEGER; VAR nAboveThresh : INTEGER; VAR nInClassAboveThresh, nCumulAboveThresh : ARRAY OF INTEGER ); (* Classifies i-th element of "data" according to i-th element found in "attr". Expects "attr" to have all elements >= 0.0 and to be sorted ascendingly! *) END StatAux.
|
||
|
|
|