!********************************************************* !* Program to demonstrate Chi-square Statistic * !* ----------------------------------------------------- * !* Reference: BASIC Scientific Subroutines, Vol. II * !* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * !* * !* F90 version by J-P Moreau, Paris * !* (www.jpmoreau.fr) * !* ----------------------------------------------------- * !* SAMPLE RUN: * !* * !* CHI-SQUARE CUMULATIVE DISTRIBUTION APPROXIMATION * !* * !* P(X) X2 REAL X2 * !* ----------------------------- * !* 0.05 124.5347 124.3 * !* 0.10 118.6326 118.5 * !* 0.15 114.5999 * !* 0.20 111.4342 * !* 0.25 108.7913 109.1 * !* 0.30 106.5055 * !* 0.35 104.4821 * !* 0.40 102.6610 * !* 0.45 101.0018 * !* 0.50 99.1944 99.3 * !* 0.55 97.6863 * !* 0.60 96.0812 * !* 0.65 94.3595 * !* 0.70 92.4934 * !* 0.75 90.4428 90.1 * !* 0.80 88.1446 * !* 0.85 85.4893 * !* 0.90 82.2522 82.4 * !* 0.95 77.7867 77.9 * !* 1.00 0.0000 * !* ----------------------------- * !* * !********************************************************* PROGRAM CHISQA real*8 x,y integer i,m; character*5 x1(20) do i = 1, 20 x1(i) = ' ' end do x1(1) = '124.3'; x1(2) = '118.5'; x1(5) = '109.1'; x1(10) = ' 99.3'; x1(15) = ' 90.1'; x1(18) = ' 82.4'; x1(19) = ' 77.9'; print *,'CHI-SQUARE CUMULATIVE DISTRIBUTION APPROXIMATION' print *,' P(X) X2 REAL X2 ' print *,'-----------------------------' m = 100; i = 0 y = 0.05 do while (y < 1.01) i = i + 1 call Chi_Square(m,x,y) write(*,25) y,x,x1(i) y = y + 0.05 end do print *,'-----------------------------' stop 25 format(F5.2,' ',F8.4,' ',A5) end !***************************************************** !* Chi-square cumulative distribution approximation * !* Good for m > 100. * !* Reference: Statistics Manual, Crow, Maxfield and * !* Davis (Dover, 1960). * !* The input value is y, the probability, the output * !* value is the corresponding Chi-square statistic. * !***************************************************** subroutine Chi_Square(m,x,y) !Labels: 100, 200, 210 real*8 x,y,z x = y !Guard against zero discontinuity if (x <= 0) x = dexp(-100.d0) if (x > 0.5) goto 100 x = -dlog(x) !Regressed table correction z = -0.803 + 1.312 * x - 0.2118 * x * x + 0.016 * x * x * x goto 200 100 x = 1.0 - x; !Guard against zero discontinuity if (x <= 0) goto 210 x = -dlog(x) z = 0.803 - 1.312 * x + 0.2118 * x * x - 0.016 * x * x * x 200 x = 2.0 / (9.0 * m) x = 1.0 - x + z * dsqrt(x) 210 x = m * x * x * x return end ! End of file chisqa.f90