(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
|
|||
|
|||
(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 |
|||
06-25-2022, 08:42 PM
(This post was last modified: 06-25-2022 08:59 PM by Thomas Klemm.)
Post: #2
|
|||
|
|||
RE: (HP-65) Binomial distribution with large input support
As a rule of thumb the binomial distribution can be approximated by the normal distribution if both \(np > 5\) and \(nq > 5\).
This is given in the example since: \( \begin{align} 4000 \cdot \frac{1}{6} &\approx 666.6667 > 5 \\ 4000 \cdot \frac{5}{6} &\approx 3333.3333 > 5 \\ \end{align} \) We can calculate mean \(\mu\) and standard deviation \(\sigma\) with: \( \begin{align} \mu &= n \cdot p \\ \sigma &= \sqrt{n \cdot p \cdot q} \\ &= \sqrt{n \cdot p \cdot (1 - p)} \\ \end{align} \) 4000 ENTER 6 1/x × STO 0 666.66667 1 LSTx - × \(\sqrt{x}\) STO 1 23.570226 The following program for the HP-15C can be used to integrate the pdf of the normal distribution: Code: 001 { 42 21 11 } f LBL A In order to get the best approximation we subtract 0.5 from \(x\) or add 0.5 to \(x\). FIX 5 661.5 RCL - 0 RCL ÷ 1 -0.21920 672.5 RCL - 0 RCL ÷ 1 0.24749 \(\int_y^x\) A 0.46244 Now we just have to compensate for the missing factor \(\frac{1}{\sqrt{2 \pi}}\) in the pdf: 2 \(\pi\) × \(\sqrt{x}\) ÷ 0.18449 I haven't checked but I assume that there are already programs for the HP-65 that deal with the normal distribution. |
|||
06-26-2022, 08:30 AM
Post: #3
|
|||
|
|||
RE: (HP-65) Binomial distribution with large input support
From HP-65 STAT PAC 1, pp. 26-27:
Quote:NORMAL DISTRIBUTION Calculations Upper Limit 672 ENTER .5 + 4000 ENTER 6 ÷ - LST x 5 × 6 ÷ \(\sqrt{x}\) ÷ 2.47487372-01 A 3.869098599-01 B 4.022655818-01 Lower Limit 662 ENTER .5 - 4000 ENTER 6 ÷ - LST x 5 × 6 ÷ \(\sqrt{x}\) ÷ -2.192031036-01 A 3.894719103-01 B 5.867540454-01 Difference From this value we can subtract the result of the upper limit: .4022655818 - 1.844884636-01 Comparison We can compare this with the result from: Sum[PDF[BinomialDistribution[4000, 1/6], k],{k,662,672}] 0.1844441329465701303644228283076550814475904333448317000634794690... Programs These programs can be loaded directly into this HP-65 Microcode Emulator. The first program has to be loaded and started once with A to load the constants. The second program can then be used to calculate \(f(x)\) and \(Q(x)\). STAT 1-10A 1 Code: PROG STAT 1-10A 2 Code: PROG |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)