Post Reply 
(35S) Statistical Distributions Functions
10-28-2015, 12:34 PM (This post was last modified: 10-28-2015 12:58 PM by Dieter.)
Post: #26
RE: HP 35s Statistical Distributions Functions
(10-28-2015 12:24 AM)PedroLeiva Wrote:  Dieter, the program works perfect!. Please include the function for the inverse, no mather how long it takes

OK, here is a first version with a rough initial guess. At the X=? prompt simply enter a negative value if you want to compute the quantile for that probabily. If you already have entered the previous C program, simply add lines C010 and C011 and continue with line C054.

Code:
C001  LBL C
C002  INPUT J
C003  e
C004  IP
C005  STO T
C006  ÷
C007  !
C008  STO G
C009  INPUT X
C010  x<0?
C011  GTO C054
C012  XEQ C015
C013  STOP
C014  GTO C009
C015  RCL X
C016  RCL÷ T
C017  +/-
C018  e^x
C019  LASTx
C020  +/-
C021  RCL J
C022  RCL÷ T
C023  y^x
C024  x
C025  RCL÷ G
C026  STO A
C027  RCL J
C028  STO B
C029  SGN
C030  ENTER
C031  -
C032  ENTER
C033  ENTER
C034  LASTx
C035  RCLx X
C036  RCL B
C037  RCL+ T
C038  STO B
C039  ÷
C040  +
C041  x≠y?
C042  GTO C032
C043  RCL A
C044  RCL X
C045  x=0?
C046  e^x
C047  ÷
C048  RCLx J
C049  RCL÷ T
C050  x<>y
C051  RCLx A
C052  RCL+ A
C053  RTN
C054  +/-
C055  STO P
C056  RCLx J
C057  RCL÷ T
C058  RCLx G
C059  RCL T
C060  RCL÷ J
C061  y^x
C062  Pi
C063  x
C064  STO X
C065  XEQ C015
C066  ENTER
C067  RCL÷ P
C068  LN
C069  x
C070  ENTER
C071  ENTER
C072  RCL J
C073  RCL- X
C074  RCL- T
C075  RCL÷ X
C076  RCL÷ T
C077  RCL÷ T
C078  x
C079  R↑
C080  -
C081  ÷
C082  RCL+ X
C083  x<> X
C084  RCL X
C085  STOP
C086  GTO C064

Usage: At the X=? prompt enter the negative probability for which you want the Chi² quantile. The program will then display two estimates in Y and X (the previous and the current), so that you can see the iteration converge. Pressing R/S yields the next approximation.

Code:
[XEQ] C [ENTER]             J=?

Enter degrees of freedom
    10  [R/S]               X=?

Enter negative probability
  -0,95 [R/S]               11,176989523
                            15,310270784

        [R/S]               15,310270784
                            17,970799176

        [R/S]               17,970799176
                            18,305703292

        [R/S]               18,305703292
                            18,307038039

If 18,307 is sufficiently accurate you may stop here.
Otherwise continue:

Code:
        [R/S]               18,307038039
                            18,307038054

        [R/S]               18,307038054
                            18,307038054

When the two approximations are displayed you may also enter your own guess before pressing R/S, and the approximation will continue with this value.

NB: This program is not very sophisticated, and it does not match what's inside the 34s. For instance, the latter evaluates CDFs for large x via P(x) = 1–Q(x), and also the quantile function has a much, much better initial guess. It took me quite a while to get the guess within <10% of the true value. ;-) For instance, the first guess for the case above is 18,2..., compared to the exact value 18,307...

Some time ago I wrote 35s/41C programs for the Normal distribution. They evaluate the PDF, one- and two-sided CDFs and also one- and two-sided quantiles with several tweaks to ensure best possible accuracy and efficiency. But these are about three times the size of the small Chi² progam posted above.

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 - 10-28-2015 12:34 PM



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