'**************************************************** '* Program to demonstrate the chi-square subroutine * '* ------------------------------------------------ * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].* '* ------------------------------------------------ * '* SAMPLE RUN: * '* How many degrees of freedom: 100 * '* What is the range (X1,X2): * '* X1: 50 * '* X2: 150 * '* What is the table step size: 5 * '* * '* X Chi-Square PDF * '* ------------------------ * '* 50 0.00000 * '* 55 0.00003 * '* 60 0.00018 * '* 65 0.00076 * '* 70 0.00237 * '* 75 0.00571 * '* 80 0.01107 * '* 85 0.01772 * '* 90 0.02393 * '* 95 0.02779 * '* 100 0.02816 * '* 105 0.02525 * '* 110 0.02025 * '* 115 0.01468 * '* 120 0.00970 * '* 125 0.00588 * '* 130 0.00330 * '* 135 0.00172 * '* 140 0.00084 * '* 145 0.00038 * '* 150 0.00017 * '* * '**************************************************** DEFINT I-N DEFDBL A-H, O-Z CLS PRINT INPUT " How many degrees of freedom: ", m PRINT " What is the range (X1,X2):" INPUT " X1: ", x1 INPUT " X2: ", x2 INPUT " What is the table step size: ", x3 CLS PRINT PRINT " X Chi-Square PDF " PRINT " -------------------------" FOR x = x1 TO x2 STEP x3 GOSUB 2000 PRINT USING " ### #.#####"; x; y NEXT END '*************************************************** '* Series approximation subroutine LN(X!) * '* Accuracy better then 6 places for x>=3 * '* Accuracy better than 12 places for x>10 * '* Advantage is that very large values of the * '* argument can be used without fear of over flow. * '* x is the input, y is the output. * '* ----------------------------------------------- * '* Reference: CRC Math Tables. * '*************************************************** 1000 x1 = 1# / (x * x) y = (x + .5#) * LOG(x) - x * (1# - x1 / 12# + x1 * x1 / 360# - x1 * x1 * x1 / 1260# + x1 * x1 * x1 * x1 / 1680#) y = y + .918938533205# RETURN '****************************************************** '* Chi-square function subroutine. This program takes * '* a given degree of freedom, m and value, x, and * '* calculates the chi-square density distribution * '* function value, y. * '* -------------------------------------------------- * '* Reference: Texas Instruments SR-51 owners Manual, * '* 1974. * '* -------------------------------------------------- * '* Subroutine used: LN(X!). * '****************************************************** 2000 'Save X xm1 = x 'Perform calculation x = m / 2 - 1# 'Call LN(X!) subroutine GOSUB 1000 x = xm1 c = -x / 2 + (m / 2 - 1) * LOG(x) - (m / 2) * LOG(2) - y y = EXP(c) RETURN 'End of file chi-sqr.bas