Included libraries (probability and statistics)

Some librares are included in the Library folder of Decimal BASIC.
In BASIC's "Open File" menu, select "Library" as the "File Type" and select the Library folder. The LIB files will be displayed.
When using a library, add a MERGE statement to the end of the program specifying the library file name.
When you write a MERGE statement, it adds the specified library to the program and translates it.
Note. The library name is the file name, so be careful when using it on operating systems such as Linux, which distinguish between upper or lower case in alphabetic characters in file names.


DiscDist.LIB

DiscDist.LIB deals with discrete probability distributions (binomial distribution, hypergeometric distribution, Poisson distribution, negative binomial distribution).

Binomial distribution
The external function Binom(n, p, x) is the probability Pr(X=x) that the value of a random variable X that follows a binomial distribution B(n,p) is x, That is, Binom(n,p,x)=nCrpx(1-p)n-x
By calculating using logarithms, we are able to perform detailed calculations even in decimal and binary modes.
BinomLCum(n, p, x) is the lower cumulative probability of the binomial distribution, i.e., the probability Pr(X≦x) that the value of a random variable X following the binomial distribution B(n,p) is less than or equal to x.
BinomUCum(n, p, x) is the upper cumulative probability of the binomial distribution, i.e., the probability Pr(x≦X) that the value of a random variable X following the binomial distribution B(n,p) is greater than or equal to x.
BinomLBound(n, p, a) is the largest integer k such that Pr(X<k)≦a when X follows the binomial distribution B(n,p).
BinomUBound(n, p, a) is the smallest integer k such that Pr(X>k)≦a when X follows the binomial distribution B(n,p).

Example: Probability that the number of times the first roll will be 900 or less when you throw the dice 6,000 times.
As shown on line 10, when using a function in the library, write an EXTERNAL FUNCTION declaration.
Then, write the MERGE statement specifying the library at the end of the program ( outside program unit or module).

10 DECLARE EXTERNAL FUNCTION BinomLCum
20 LET n=6000
30 LET p=1/6
40 LET X=900
50 PRINT x, BinomLCum(n,p,x)
60 END
70 MERGE "DiscDist.LIB"

Hypergeometric distribution

HyperGeom(NN,M,n,x)  The probability that the number of defective products is x when n products are extracted from NN products containing M defective products.
HyperGeomLCum(NN,M,n,x)  When k products are extracted from N products containing M defective products, there is a probability Pr(X≦x) that the number of defective products X is less than or equal to x.
HyperGeomUCum(NN,M,n,x)  When k products are extracted from N products containing M defective products, there is a probability Pr(x≦X) that the number of defective products X is greater than or equal to x.
HyperGeomLBound(NN, M, n, a)   The largest integer k such that Pr(X<k)≦a when X follows the hypergeometric distribution HyperGeom(NN,M,n).
HyperGeomUBound(NN, M, n, a)   The smallest integer k such that Pr(k<X)≦a when X follows the hypergeometric distribution HyperGeom(NN,M,n).

Poisson distribution
Poisson(Lambda, x) Probability of the Poisson distribution
PoissonLCum(lambda, x) Lower cumulative probability of Poisson distribution
PoissonUCum(lambda, x) Upper cumulative probability of Poisson distribution
PoissonLBound(lambda, a) The largest integer k such that Pr(X<k)≦a when X follows the Poisson distribution Po(lambda)
PoissonUBound(lambda, a) The smallest integer k such that Pr(k<X)≦a when X follows the Poisson distribution Po(lambda)

Negative binomial distribution
NegBinom(r,p,x) Negative binomial distribution (number of failures to succeed r times when iterating over independent events with probability p)
NegBinomLCum(r,p,x) Probability that the value of the negative binomial distribution is less than or equal to x Pr(X≦x)
NegBinomUCum(r,p,x) Probability that the value of the negative binomial distribution is greater than or equal to x Pr(x≦X)
NegBinomLBound(r, p, a) The largest integer k such that Pr(X<k)≦a when X follows the negative binomial distribution NegBinom(r,p)
NegBinomUBound(r, p, a) The smallest integer k such that Pr(k<X)≦a when X follows the negative binomial distribution NegBinom(r,p)


PROBDIST.LIB

PROBDIST.LIB is a library of various cumulative probability distributions

NormalLCum(z) Lower cumulative probability of standard normal distribution
NormalUCum(z) Upper cumulative probability of standard normal distribution
InvNormalUCum(p) The probability that the value of a standard normally distributed random variable is greater than or equal to z is p
tLCum(df, t) Probability that the value of a random variable following the t distribution of degrees of freedom df is less than or equal to t
tUCum(df, t) Probability that the value of a random variable following the t distribution of degrees of freedom df is greater than or equal to t
InvtUCum(df, p) The probability that the value of a random variable following the t distribution of degrees of freedom df is greater than or equal to z is p
Chi2LCum(df, chi2) Probability that the value of a random variable following the χ-squared distribution of degrees of freedom df is less than or equal to chi2
Chi2UCum(df, chi2) Probability that the value of a random variable following the χ-squared distribution of degrees of freedom df is greater than or equal to chi2
InvChi2UCum(df, p) The probability that the value of a random variable following the χ-squared distribution of degrees of freedom df is greater than or equal to z is p
FUCum(df1, df2, f) Upper cumulative probability of the F distribution with degrees of freedom df1, df2
FLCum(df1, df2, f) Lower cumulative probability of the F distribution with degrees of freedom df1, df2
InvFUCum(df1, df2, p) The probability that the value of a random variable following the F distribution with degrees of freedom df1, df2 is greater than or equal to z is p

Gamma(x) Gamma function
Beta(x, y) Beta function


RANDOM.LIB

RANDOM.LIB is a library of various random numbers.

RNDNormal(m,s) A random number that follows a normal distribution N(m,s^2)
RNDPoisson(m) Random number with Poisson distribution (mean m)
RNDHyperGeom(N,d,m) A random number that follows a hypergeometric distribution (when d out of N are per number, when m are non-recovering)
RNDPascal(k,p) negative binomial distribution (Pascal distribution) (number of failures until k successful independent trials with probability p)
RNDchi2(n) Random number with chi-square distribution (chi-square distribution)
RNDt(n) A random number that follows the t distribution t(n)
RNDGeom(p) A random number that follows a geometric distribution


BAck