home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 21.8 Statistics
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
-
- function combo(nNumber,nTaken)
- LOCAL nLogn:=factorial(nNumber),nLogt:=factorial(nTaken)
- LOCAL nDiff:=factorial(nNumber-nTaken)
- return int(exp(nLogn-(nLogt+nDiff))+.5)
-
-
- function perms(nNumber,nTaken)
- LOCAL nLogn:=factorial(nNumber),nLogt:=factorial(nTaken)
- return int(exp(nLogn-nLogt)+.5)
-
-
- STATIC function factorial(nX)
- LOCAL appx:=1,jj
- if nX <=0
- appx:=0
- else
- for jj=1 to 10
- appx:=appx*jj
- if nX = jj
- return log(appx)
- endif
- next
- /* Sterling approximation for large integers */
- appx := log(6.283186)/2+log(nX)*(nX+.5)-nX+1/(nX*12)
- endif
- return appx
-
-
- function mean(aGroups)
- LOCAL nSum:=0,nSize:=len(aGroups),jj
- for jj=1 to nSize
- nSum =+ aGroups[jj]
- next
- return if(nSize=0,0,nSum/nSize)
-
-
- function median(aGroups)
- LOCAL nSize:=len(aGroups),nMid, nMedian
- LOCAL lOdd:= (nSize/2<>int(nSize/2))
- asort(aGroups,1,nSize)
- if lOdd
- nMedian := aGroups( int(nSize/2)+1 )
- else
- nMid := int(nSize/2)
- nMedian := (aGroups(nMid)+aGroups(nMid+1))/2
- endif
- return nMedian
-
-
- function variance(aGroups)
- LOCAL nSum:=0,nSum_Square:=0,jj,nSize:=len(aGroups)
- for jj=1 to nSize
- nSum += aGroups[jj]
- nSum_Square += (aGroups[jj]**2)
- next
- return nSum_square/nSize-(nSum/nSize)**2
-
-
- // end of file CHP2108.PRG
-