home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP21.EXE / CHP2108.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  1.5 KB  |  71 lines

  1. /*
  2.    Listing 21.8  Statistics
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11.  
  12. function combo(nNumber,nTaken)
  13. LOCAL nLogn:=factorial(nNumber),nLogt:=factorial(nTaken)
  14. LOCAL nDiff:=factorial(nNumber-nTaken)
  15. return int(exp(nLogn-(nLogt+nDiff))+.5)
  16.  
  17.  
  18. function perms(nNumber,nTaken)
  19. LOCAL nLogn:=factorial(nNumber),nLogt:=factorial(nTaken)
  20. return int(exp(nLogn-nLogt)+.5)
  21.  
  22.  
  23. STATIC function factorial(nX)
  24. LOCAL appx:=1,jj
  25. if nX <=0
  26.    appx:=0
  27. else
  28.    for jj=1 to 10
  29.       appx:=appx*jj
  30.       if nX = jj
  31.          return log(appx)
  32.       endif
  33.    next
  34.    /* Sterling approximation for large integers */
  35.    appx := log(6.283186)/2+log(nX)*(nX+.5)-nX+1/(nX*12)
  36. endif
  37. return appx
  38.  
  39.  
  40. function mean(aGroups)
  41. LOCAL nSum:=0,nSize:=len(aGroups),jj
  42. for jj=1 to nSize
  43.    nSum =+ aGroups[jj]
  44. next
  45. return if(nSize=0,0,nSum/nSize)
  46.  
  47.  
  48. function median(aGroups)
  49. LOCAL nSize:=len(aGroups),nMid, nMedian
  50. LOCAL lOdd:= (nSize/2<>int(nSize/2))
  51. asort(aGroups,1,nSize)
  52. if lOdd
  53.    nMedian := aGroups( int(nSize/2)+1 )
  54. else
  55.    nMid    := int(nSize/2)
  56.    nMedian := (aGroups(nMid)+aGroups(nMid+1))/2
  57. endif
  58. return nMedian
  59.  
  60.  
  61. function variance(aGroups)
  62. LOCAL nSum:=0,nSum_Square:=0,jj,nSize:=len(aGroups)
  63. for jj=1 to nSize
  64.    nSum += aGroups[jj]
  65.    nSum_Square += (aGroups[jj]**2)
  66. next
  67. return nSum_square/nSize-(nSum/nSize)**2
  68.  
  69.  
  70. // end of file CHP2108.PRG
  71.