'***************************************************
'* Statistical distributions *
'* ----------------------------------------------- *
'* This program allows computing several dis- *
'* tributions: *
'* 1. binomial distribution *
'* 2. Poisson distribution *
'* 3. normal distribution *
'* 4. normal distribution (2 variables) *
'* 5. chi-square distribution *
'* 6. Student T distribution *
'* ----------------------------------------------- *
'* REFERENCE: "Mathematiques et statistiques By H. *
'* Haut, PSI Editions, France, 1981" *
'* [BIBLI 13]. *
'* ----------------------------------------------- *
'* SAMPLE RUN: *
'* *
'* Statistical distributions *
'* *
'* Tutorial *
'* *
'* 1. Input distribution number:" *
'* *
'* 1: binomial distribution" *
'* 2: Poisson distribution" *
'* 3: normal distribution" *
'* 4: normal distribution (2 variables)" *
'* 5: chi-square distribution *
'* 6: Student T distribution" *
'* *
'* 2. Define the parameters of chosen distribution *
'* *
'* 3. Input value of random variable" *
'* *
'* *
'* Input distribution number (1 to 6): 3 *
'* *
'* Normal distribution *
'* *
'* MU=mean *
'* S =standard deviation *
'* X =value of random variable *
'* *
'* MU = 2 *
'* S = 3 *
'* X = 5 *
'* *
'* Probability of random variable = X: .0806569 *
'* Probability of random variable <= X: .8413447 *
'* Probability of random variable >= X: .1586552 *
'* *
'***************************************************
DEFINT I-N
DEFDBL A-H, O-Z
DIM B(4) 'used by normal distribution
CLS
PRINT " Statistical distributions"
PRINT
PRINT " Tutorial"
PRINT
PRINT " 1. Input distribution number:"
PRINT
PRINT " 1: binomial distribution"
PRINT " 2: Poisson distribution"
PRINT " 3: normal distribution"
PRINT " 4: normal distribution (2 variables)"
PRINT " 5: chi-square distribution"
PRINT " 6: Student T distribution"
PRINT
PRINT " 2. Define the parameters of chosen distribution"
PRINT
PRINT " 3. Input value of random variable"
PRINT
PRINT
INPUT " Input distribution number (1 to 6): ", ich
CLS
IF ich < 1 OR ich > 6 THEN
PRINT " Error: Invalid choice!"
END
END IF
'call appropriate subroutine
ON ich GOTO 100, 200, 300, 400, 500, 600
100 PRINT
PRINT " Binomial distribution:"
PRINT
PRINT " P=probability of success"
PRINT " N=number of trials"
PRINT " X=value of random variable"
PRINT
INPUT " P = ", p
INPUT " N = ", n
INPUT " X = ", x
GOTO 700
200 PRINT
PRINT " Poisson distribution"
PRINT
PRINT " MU=mean"
PRINT " X =value of random variable"
PRINT
INPUT " MU = ", xm
INPUT " X = ", x
GOTO 700
300 PRINT
PRINT " Normal distribution"
PRINT
PRINT " MU=mean"
PRINT " S =standard deviation"
PRINT " X =value of random variable"
PRINT
INPUT " MU = ", xm
INPUT " S = ", s
INPUT " X = ", x
GOTO 700
400 PRINT
PRINT " Normal distribution (2 variables)"
PRINT
PRINT " MX=mean of X"
PRINT " MY=mean of Y"
PRINT " SX=standard deviation of X"
PRINT " SY=standard deviation of Y"
PRINT " RO=correlation coefficient"
PRINT " X =value of 1st random variable"
PRINT " Y =value of 2nd random variable"
PRINT
INPUT " MX = ", xm
INPUT " SX = ", sx
INPUT " MY = ", ym
INPUT " SY = ", sy
INPUT " RO = ", ro
INPUT " X = ", x
INPUT " Y = ", y
GOTO 700
500 PRINT
PRINT " chi-square distribution"
PRINT
PRINT " NU=number of degrees of freedom"
PRINT " X =value of random variable"
PRINT
INPUT " NU = ", nu
INPUT " X = ", x
GOTO 700
600 PRINT
PRINT " Student's T distribution"
PRINT
PRINT " NU=number of degrees of freedom"
PRINT " X =value of random variable"
PRINT
INPUT " NU = ", nu
INPUT " X = ", x
700 ON ich GOSUB 1000, 2000, 3000, 4000, 5000, 6000
'print results
PRINT
a$ = " Probability of random variable = X: "
B$ = " Probability of random variable <= X: "
c$ = " Probability of random variable >= X: "
d$ = " Probability of random variables = X,Y: "
IF ich = 4 THEN PRINT d$; fxy: END
IF ich <> 6 THEN GOTO 800
PRINT " Prob(-X<=random variable<=X) = "; bt
PRINT B$; px
PRINT c$; qx
END
800 PRINT a$; fx
PRINT B$; px
PRINT c$; qx
END
1000 'Binomial distribution subroutine
'****************************************************
'* INPUTS: *
'* p: probability of success *
'* n: number of trials *
'* x: value of random variable *
'* OUTPUTS: *
'* fx: probability of random variable = X *
'* px: probability of random variable <= X *
'* qx: probability of random variable >= X *
'****************************************************
q = 1# - p: t = p / q
n1 = n + 1
fx = q ^ n'fx=prob(0)
px = fx
IF x = 0 THEN GOTO 1200
FOR i = 1 TO x
fx = (n1 - i) * t * fx / i
px = px + fx
NEXT i
1200 qx = 1# + fx - px
RETURN
2000 'Poisson distribution subroutine
'****************************************************
'* INPUTS: *
'* xm: mean *
'* x: value of random variable *
'* OUTPUTS: *
'* fx: probability of random variable = X *
'* px: probability of random variable <= X *
'* qx: probability of random variable >= X *
'****************************************************
fx = EXP(-xm)
px = fx
IF x = 0 THEN GOTO 2100
FOR i = 1 TO x
fx = fx * xm / i
px = px + fx
NEXT i
2100 qx = 1# + fx - px
RETURN
3000 'normal distribution
'****************************************************
'* INPUTS: *
'* xm: mean *
'* s: standard deviation *
'* x: value of random variable *
'* OUTPUTS: *
'* fx: probability of random variable = X *
'* px: probability of random variable <= X *
'* qx: probability of random variable >= X *
'****************************************************
'define coefficients B(i)
B(0) = 1.330274429#
B(1) = -1.821255978#
B(2) = 1.781