home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / MCAD254.ZIP / STAT / CUMEDIST.MCD < prev    next >
Encoding:
Text File  |  1988-11-26  |  3.1 KB  |  127 lines

  1. .MCD 20000 0
  2. .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
  3. .CMD FORMAT  rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
  4. .CMD SET ORIGIN 0
  5. .CMD SET TOL 0.001000
  6. .CMD MARGIN 0
  7. .CMD LINELENGTH 78
  8. .CMD SET PRNCOLWIDTH 8
  9. .CMD SET PRNPRECISION 4
  10. .TXT 0 41 1 39 
  11. a1,38,49,37
  12. Copyright (c) 1988 by MathSoft, Inc.
  13. .TXT 1 40 1 49 
  14. a1,48,78,47
  15. /EQUATIONS FOR CUMULATIVE DISTRIBUTION OF DATA
  16. .TXT 1 -60 1 34 
  17. a1,33,59,32
  18. CUMULATIVE DISTRIBUTION OF DATA
  19. .TXT 2 -21 3 81 
  20. a3,80,78,188
  21. This application constructs an approximation to the cumulative distribution of 
  22. a set of data points using MathCAD's histogram function.                       
  23.                            
  24. .TXT 2 80 1 46 
  25. a1,45,78,44
  26. Establish the interval covered by each bin.
  27. .EQN 1 -80 1 20 
  28. V~READPRN(CDIST)
  29. .TXT 0 22 1 46 
  30. a1,45,56,44
  31. <-- enter file from which data will be read
  32. .EQN 1 64 1 12 
  33. U~max(V)
  34. .EQN 0 18 1 12 
  35. L~min(V)
  36. .EQN 1 -104 1 11 
  37. NBIN~30
  38. .TXT 0 11 2 23 
  39. a2,22,61,38
  40. <-- number of bins 
  41.     in histogram
  42. .EQN 0 58 1 9 
  43. T=?
  44. .EQN 0 24 3 11 
  45. H~(U-L)/NBIN
  46. .EQN 1 -59 11 35 
  47. T&0&C[J{1,1,9,30,l}@U&L&BINS[J
  48. .EQN 2 -34 1 10 
  49. NORM~1
  50. .TXT 0 11 4 23 
  51. a4,22,20,84
  52. <-- set to 1 if the  
  53.     result should be 
  54.     normalized, set 
  55.     to 0 otherwise
  56. .TXT 1 69 1 39 
  57. a1,38,78,37
  58. Create an array containing the bins.
  59. .EQN 2 18 1 28 
  60. I~ORIGIN;NBIN+ORIGIN
  61. .EQN 2 0 2 28 
  62. BINS[I~L+(I-ORIGIN)*H
  63. .TXT 1 -98 1 26 
  64. a1,25,78,24
  65. sample characteristics:
  66. .EQN 1 6 1 19 
  67. length(V)={19027}?
  68. .TXT 0 74 2 76 
  69. a2,75,78,112
  70. Create an array containing the number of data values falling within each 
  71. interval specified in the BINS array.
  72. .EQN 1 -72 1 19 
  73. mean(V)=?
  74. .EQN 1 2 1 17 
  75. sd(V)=?
  76. .EQN 0 27 1 14 
  77. L={18995}?
  78. .EQN 0 29 1 13 
  79. U=?
  80. .EQN 1 38 1 18 
  81. P~hist(BINS,V)
  82. .TXT 1 -103 1 15 
  83. a1,14,76,13
  84. [Ctrl][PgDn]
  85. .TXT 0 79 1 15 
  86. a1,14,78,13
  87. [Ctrl][PgDn]
  88. .TXT 2 0 1 77 
  89. a1,76,78,75
  90. Create an array containing the cumulative distribution corresponding to P.
  91. .EQN 2 20 1 26 
  92. J~ORIGIN+1;last(P)
  93. .TXT 2 -98 5 79 
  94. a5,78,76,377
  95. The function C plotted above is actually a step function, with as many steps 
  96. as there are bins for the histogram function.  The plot appears as a smooth 
  97. curve because the values of C are plotted using plot type l (line).  You can 
  98. define a smoothed cumulative distribution by using MathCAD's linterp 
  99. function with the normalized step function C (set NORM equal to 1 above):
  100. .EQN 0 82 2 13 
  101. C[ORIGIN~0
  102. .EQN 0 19 2 16 
  103. C[J~C[(J-1)+P[J
  104. .EQN 0 22 2 19 
  105. C[NBIN~length(V)
  106. .TXT 3 -45 2 78 
  107. a2,77,78,96
  108. Prepare an index variable for plotting the above array, then normalize the 
  109. array if necessary.
  110. .EQN 2 22 3 26 
  111. C~C/if(NORM,length(V),1)
  112. .EQN 1 31 1 12 
  113. T~max(C)
  114. .EQN 1 -110 1 33 
  115. CUMEDIST(x)~linterp(BINS,C,x)
  116. .TXT 2 -21 2 79 
  117. a2,78,76,151
  118. Now you can estimate the fraction of data values less than any given number. 
  119. For example, the fraction of data values less than 1.05 is approximately
  120. .EQN 0 107 4 33 
  121. sd(V)~stdev(V)*\(length(V)/(length(V)-1))
  122. .TXT 2 -29 1 29 
  123. a1,28,78,27
  124. Sample standard deviation:
  125. .EQN 1 -52 1 25 
  126. CUMEDIST(1.05)={18994}?
  127.