home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols200 / vol243 / chisqr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-13  |  2.5 KB  |  76 lines

  1. {PROGRAM AUTHOR: Mark Aldon Weiss   Donated to public domain}
  2.  
  3. { Statistical Reference:  Probability and Statistics by Morris H. DeGroot }
  4. { pp. 440-441.                                                            }
  5.  
  6.  
  7. CONST
  8.  
  9. MeanNumPerInterval: Byte = 5;
  10. MaxNumSamples = 1005;
  11. MaxNumIntervals = 204;
  12.  
  13.  
  14.  
  15. TYPE
  16.  
  17. NumPerInterval = Array[1..MaxNumIntervals] of Byte;
  18.   Partitioning = Array[0..MaxNumIntervals] of Real;
  19.  
  20.  
  21.  
  22. VAR
  23.  
  24.      again: Boolean;
  25.          Q: Real;
  26. SampleSize: 1..MaxNumSamples;
  27.     NumInt: 1..MaxNumIntervals;
  28.      NumDF: Byte;
  29.        i,j: Integer;
  30.       rand: Real;
  31.          N: NumPerInterval;
  32.      range: Partitioning;
  33.         ch: char;
  34.  
  35.  
  36.  
  37. BEGIN  { M A I N    P R O G R A M }
  38. Writeln;
  39. Writeln(' This program performs a chi-square test of the random number generator.');
  40. Writeln(' The relevant statistic, Q, which has approximately a chi-square dis-');
  41. Writeln(' tribution, is calculated.  The program does not have a chi-square table;');
  42. Writeln(' only the value of Q is computed and therefore you will need a table to');
  43. Writeln(' complete the test.  See Morris H. DeGroot  Probability and Statistics,');
  44. Writeln(' pp. 440-441 (table on pp. 578-579).');
  45. Writeln;
  46. Writeln(lst,#27'C'#0#11#27'N'#4#27'G'#27'W'#1#15);
  47. Writeln(lst,' Chi-Square Test of TURBO Pascal RNG'#27'W'#0#18);
  48. Writeln(lst);  Writeln(lst);
  49. again := TRUE;
  50. WHILE again DO
  51.   Begin
  52.   Q := 0;
  53.   Writeln(' It is best to take a large number of samples (up to ',MaxNumSamples,').');
  54.   Writeln(' Please make your sample size a multiple of ',MeanNumPerInterval,'.');
  55.   Write(' What do you choose for your sample size?    ');  Readln(SampleSize);
  56.   Writeln;
  57.   NumInt := SampleSize DIV MeanNumPerInterval;
  58.   NumDF := NumInt - 1;
  59.   FOR i := 0 to NumInt DO range[i] := i * (1/NumInt);
  60.   FOR i := 1 to NumInt DO N[i] := 0;
  61.   FOR i := 1 to SampleSize DO
  62.     Begin
  63.     rand := RANDOM;
  64.     For j := 1 to NumInt Do
  65.       IF NOT(rand > range[j]) AND NOT(rand < range[j-1]) THEN N[j] := N[j] + 1
  66.     End;
  67.   FOR i := 1 to NumInt DO  Q := Q + SQR( N[i] - MeanNumPerInterval );
  68.   Q := Q/MeanNumPerInterval;
  69.   Writeln(' The value of Q (',NumDF,' degrees of freedom) is ',Q:8:4);
  70.   Writeln(lst,' The value of Q (',NumDF,' degrees of freedom) is ',Q:8:4);
  71.   Writeln(lst); Writeln;
  72.   Write(' Do you want to do this again?   ');  Readln(ch);  Writeln;
  73.   IF ch IN ['y','Y'] THEN again := TRUE ELSE again := FALSE
  74.   End
  75. END.   { M A I N    P R O G R A M }
  76.