Post Reply 
(35S) Statistical Distributions Functions
11-20-2015, 11:06 PM (This post was last modified: 11-21-2015 01:49 PM by Dieter.)
Post: #73
RE: HP 35s Statistical Distributions Functions
(11-20-2015 05:45 PM)PedroLeiva Wrote:  I loaded your labels for cumulative Binomial and Poisson function, they work perfectly well.

I have reworked this a bit so that now the same values as with the other distributions are returned. This includes the upper CDF (which in these cases is not just 1 minus the lower CDF) as well as the PDF (or PMF - probability mass function -, to be more precise).

Code:
P001 LBL P    // Poisson CDF
P002 XEQ J012 // initialize (O=1, T=2 etc.)
P003 INPUT L  // prompt for parameter lambda
P004 x<=0?
P005 GTO P003 // accept only positive lambda
P006 INPUT X
P007 x<0?
P008 GTO P006 // reject negative x
P009 RCL+ O
P010 STO A
P011 RCL L
P012 STO Y
P013 XEQ G006  // Call regularized Gamma. Check: this points to RCL A RCL+T...
P014 RCL L     // calculate PDF/PMF
P015 RCL X
P016 y^x
P017 RCL X
P018 !
P019 ÷
P020 RCL L
P021 +/-
P022 e^x
P023 x
P024 STO C
P025 +         // upper CDF = 1 - lower CDF + PMF
P026 x<> C
P027 STO D
P028 x<>y
P029 RCL C
P030 x<>y
P031 ENTER
P032 CLx
P033 STO A
P034 STO B
P035 R↓
P036 STOP
P037 GTO P006

O001 LBL 0     // Binomial CDF - LBL B is already in use ;-)
O002 -14       // prompt for n and initialize
O003 XEQ J001
O004 INPUT P
O005 RCL O
O006 RCL P
O007 x<y?
O008 x<=0?
O009 GTO O004  // reject if p<=0 or p>=1
O010 INPUT X
O011 x<0?
O012 GTO O010  // reject negative x
O013 RCL N
O014 RCL X
O015 x<y?
O016 GTO O023  // regular case: x < n
O017 RCL N     // handle x=n separately
O018 STO X
O019 RCL O     // return cdf = 1
O020 ENTER
O021 CLx       // and 1-cdf = 0
O022 GTO O032
O023 RCL+ O
O024 STO A
O025 RCL N
O026 RCL- X
O027 STO B
O028 RCL P
O029 STO Y
O030 XEQ I016   // Call regularized Beta. Check: this points to RCL A  RCL B  XEQ B010
O031 STO C
O032 R↓
O033 RCL N      // calculate PDF/PMF
O034 RCL X
O035 nCr
O036 RCL P
O037 RCL X
O038 y^x
O039 x
O040 RCL O
O041 RCL- P
O042 RCL N
O043 RCL- X
O044 y^x
O045 x
O046 STO D
O047 STO+ C    // upper CDF = 1 - lower CDF + PMF
O048 x<>y
O049 RCL C
O050 x<>y
O051 ENTER
O052 CLx
O053 STO A
O054 STO B
O055 R↓
O056 STOP
O057 GTO O010

These versions return:

in Z: the Poisson resp. Binomial PDF, i.e. P(X=x)
in Y: the Poisson resp. Binomial upper CDF, i.e. P(X≥x)
in X: the Poisson resp. Binomial lower CDF, i.e. P(X≤x)

This matches the returned values for the Chi² and F distribution. Like in these cases, the upper CDF and the PDF are returned in registers C and D as well.

Looks like the user instructions need an update. ;-)

At the moment I don't think I'll add the Poisson and Binomial quantile functions – that's a rather complex story.

Edit: it looks like the Poisson quantile is not that complicated. At least an experimental version seems to run without major problems. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 35s Statistical Distributions Functions - Dieter - 11-20-2015 11:06 PM



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