(HP-65) Binomial distribution with large input support
01-05-2020, 06:37 PM (This post was last modified: 01-05-2020 06:49 PM by Dave Britten.)
Post: #1
 Dave Britten Senior Member Posts: 1,411 Joined: Dec 2013
(HP-65) Binomial distribution with large input support
This program calculates the binomial probability mass function, or cumulative binomial probabilities, with support for large (>69) numbers of trials. To do this, it uses Nemes' formula to approximate ln(x!) rather than calculating x! directly and overflowing.

Recommended Key Labels

A: CALC
E: ln(x!)

Usage

There weren't enough steps left for a fancy user interface, so inputs must first be stored directly into R1-R4 before running the program. Store these values:

R1: n - number of trials
R2: p - percentage of success on a single trial
R3: xmin - minimum number of successes
R4: xmax - maximum number of successes

Then press A to calculate the probability mass/cumulative probability. If xmin=xmax, the program calculates the probability mass for that value of x. If xmax>xmin, then the program calculates cumulative probability for the specified range of x values. If xmin>xmax, or xmax>n, you'll get an error.

Note that Nemes' formula is an approximation, which means this program produces approximate results. Accuracy improves with larger inputs, but the worst-case scenario appears to be about 4 digits of accuracy (e.g. n=2, p=0.5, xmin=0, xmax=2 yields about 100.037%). So it's no worse than a slide rule!

Probability mass is calculated in constant time - about 10 seconds - and a cumulative probability with xmax-xmin=10 takes about 30 seconds. Execution time in seconds can be estimated using 10 + 2(xmax - xmin).

Also, you can press E to calculate ln(x!).

Example

If you roll a fair six-sided die 4000 times, what are the odds that you will get any given result between 662 and 672 times? (The mean of this distribution is 666.67.)

4000 STO 1
6 g 1/x STO 2
662 STO 3
672 STO 4
A: 0.1844

There is approximately an 18.44% chance that any specific result will be rolled between 662 and 672 times.

Code:
RCL 1   34 01 E       15 RCL 3   34 03 STO 8   33 08 E       15 -       51 RCL 1   34 01 RCL 3   34 03 -       51 E       15 -       51 RCL 3   34 03 RCL 2   34 02 f       31 LN      07 STO 5   33 05 *       71 +       61 RCL 1   34 01 RCL 3   34 03 -       51 1       01 RCL 2   34 02 -       51 f       31 LN      07 STO 6   33 06 *       71 +       61 f-1     32 LN      07 STO 7   33 07 LSTx    35 00 LBL     23 1       01 RCL 8   34 08 RCL 4   34 04 g x=y   35 23 RCL 7   34 07 RTN     24 g RDown 35 08 RCL 1   34 01 g x><y  35 07 -       51 RCL 8   34 08 1       01 +       61 STO 8   33 08 /       81 f       31 LN      07 +       61 RCL 5   34 05 +       61 RCL 6   34 06 -       51 f-1     32 LN      07 STO     33 +       61 7       07 g LSTx  35 00 GTO     22 1       01 LBL     23 E       15 1       01 +       61 STO 7   33 07 1       01 2       02 *       71 .       83 1       01 RCL 7   34 07 /       81 -       51 g       35 1/x     04 RCL 7   34 07 +       61 f       31 LN      07 1       01 -       51 RCL 7   34 07 *       71 2       02 g       35 PI      02 *       71 RCL 7   34 07 /       81 f       31 LN      07 2       02 /       81 +       61 RTN     24
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)