(35S) Statistical Distributions Functions

10252015, 12:19 AM
(This post was last modified: 06152017 01:33 PM by Gene.)
Post: #1




(35S) Statistical Distributions Functions
I need programs of Statistical Distributions: t Student, F Snedecor and Chi Square. The Hp 67 Statistical Pakage was excellent, but I am not able to translate them to HP 35s. Does somebody could help me in this task?


10252015, 01:29 PM
Post: #2




RE: HP 35s Statistical Distributions Functions
The HP 35s has two features that are missing in the HP67:
Thus I wouldn't recommend to translate these HP67 programs directly to the HP 35s. I just had a quick look at ChiSquare Distribution for the HP67 and it uses a series approximation to evaluate the cumulative distribution. With the HP 35s you can use numeric integration instead. Just have a look at the program Normal and Inverse–Normal Distributions in the user's guide (pp 1611). You can replace the subroutine F that calculates the integrand for the normal distribution. It calculates the "upper tail" area but that is easy to change. Since integration and solver can't be mixed a Newtoniteration is used to calculate the inverse. The calculation of the derivative is just evaluating the probability density function due to the fundamental theorem of calculus. Let us know if you struggle to translate the formulas of the probability density functions to programs. Using an algebraic equation might be easier but will be probably slower. HTH Thomas 

10262015, 03:03 PM
Post: #3




RE: HP 35s Statistical Distributions Functions
(10252015 12:19 AM)PedroLeiva Wrote: I need programs of Statistical Distributions: t Student, F Snedecor and Chi Square. The Hp 67 Statistical Pakage was excellent, but I am not able to translate them to HP 35s. Does somebody could help me in this task? Might I suggest... NCS35TB Stat Pac For the HP35s Calculator ... by Namir Shamas at NCSSTATPAC BEST! SlideRule 

10262015, 04:41 PM
(This post was last modified: 03282016 02:11 PM by PedroLeiva.)
Post: #4




RE: HP 35s Statistical Distributions Functions
Thank you very much for your recommendation, but Namir programs are not what I need. In Appendix A, there are detailed calculations based on estimates of the inverse probability of each 4 statistical functions. I also need to calculate probability according to a value of each function.
HP 67 Statistical Distributions programs (Normal, Chi Square, "F" and "t" Student) are perfect for this purpose. 

10262015, 08:30 PM
(This post was last modified: 10262015 08:34 PM by Dieter.)
Post: #5




RE: HP 35s Statistical Distributions Functions
(10262015 04:41 PM)PedroLeiva Wrote: Thank you very much for your recommendation, but Namir programs are not what I need. In Appendix A, there are detailed calculations based on estimates of the inverse probability of each 4 statistical functions. I also need to calculate probability according to a value of each function. OK – what exactly do you need? The CDFs for Normal, Student, Chi² and Fisher's F distribution? Also their quantile (inverse) functions? What accuracy is required? BTW, the 34s does all this. I provided some code for these four quantile functions which are evaluated with mostly 30+ digit accuracy. This is possible due to CDFs that are (mostly) equally accurate. These CDFs in turn are calculated using incomplete Beta and Gamma functions, coded by Pauli. (10262015 04:41 PM)PedroLeiva Wrote: HP 67 Statistical Distributions programs (Normal, Chi Square, "F" and "t" Student) a perfect for this purpose. Could you provide a pointer to this package? How accurate are the results? Do these programs also calculate the inverse (quantile) functions? If you really appreciate these HP67 programs so much it should be easy to translate them for the 35s. Dieter 

10262015, 08:39 PM
(This post was last modified: 10282015 12:09 AM by Thomas Klemm.)
Post: #6




RE: HP 35s Statistical Distributions Functions
Here's a program for the Student's tdistribution:
Code: T001 LBL T ; Student's t You have to initialize the program with the degrees of freedom: XEQ T ENTER K? 7 R/S To calculate the PDF use the program P: XEQ P ENTER X? 1.6 R/S 0.110665 PDF[StudentTDistribution[7],1.6] To calculate the CDF use the program C: XEQ C ENTER X? 1.5 R/S 0.911351 CDF[StudentTDistribution[7],1.5] For the next program set the accuracy to a reasonable value: 1E6 STO E To calculate the Inverse CDF use the program I: XEQ I ENTER X? 0.99 R/S 2.997951 HTH Thomas 

10262015, 09:25 PM
(This post was last modified: 10262015 09:27 PM by Dieter.)
Post: #7




RE: HP 35s Statistical Distributions Functions
(10262015 08:39 PM)Thomas Klemm Wrote: Here's a program for the Student's tdistribution: Hint: the Normal, Student, Chi² and Fisher quantiles will converge faster if the Halley method (instead of simple Newton) is used. This is easy here since the second derivative simply is the PDF times a factor. Another tweak that can provide better convergence (especially in the Chi² and F case) is solving ln(CDF/p)=0 instead of CDF–p=0. Both methods are used in the WP34s quantile functions. Dieter 

10262015, 09:28 PM
Post: #8




RE: HP 35s Statistical Distributions Functions
For the Chisquared distribution you just have to calculate a different PDF:
The factor \(\frac{1}{2^{\frac{k}{2}}\Gamma\left(\frac{k}{2}\right)}\) has to be calculated only once as long as the degrees of freedom k doesn't change. This can be done similar to program T. The value of the distribution has to be calculated in program D. The other programs don't change. For the Fdistribution you have to calculate: with parameters \(d_1\) and \(d_2\). To calculate the beta function we can use: Together with the program for the Student's tdistribution it should be possible to create the missing programs. Cheers Thomas 

10262015, 10:29 PM
Post: #9




RE: HP 35s Statistical Distributions Functions
[attachment=2697][attachment=2697][attachment=2697][attachment=2697]
(10262015 08:30 PM)Dieter Wrote:(10262015 04:41 PM)PedroLeiva Wrote: Thank you very much for your recommendation, but Namir programs are not what I need. In Appendix A, there are detailed calculations based on estimates of the inverse probability of each 4 statistical functions. I also need to calculate probability according to a value of each function. Attached are three HP 67 programs, with descriptions and formulas, some examples or test cases, and the program itself (keystrokes sequence). I need exactly what they allow to calculate, and with the same precision. I am not a specialist in mathematics; I simply use a lot of statistic and want to become independent of the function tables. 

10262015, 11:04 PM
Post: #10




RE: HP 35s Statistical Distributions Functions
(10262015 10:29 PM)PedroLeiva Wrote: Attached are three HP 67 programs, with descriptions and formulas, some examples or test cases, and the program itself (keystrokes sequence). I need exactly what they allow to calculate, and with the same precision. So you only need the PDFs and CDFs – that's simple and straightforwand on the 35s. Actually the implementation is easier as the 35s features a Gamma function. (10262015 10:29 PM)PedroLeiva Wrote: I am not a specialist in mathematics; I simply use a lot of statistic and want to become independent of the function tables. Get a 34s. ;) Dieter 

10272015, 11:59 AM
Post: #11




RE: HP 35s Statistical Distributions Functions
(10262015 09:28 PM)Thomas Klemm Wrote: For the Chisquared distribution you just have to calculate a different PDF: Thomas, with time and patience I will try to program my HP 35s with the suggestions that you just gave me. Thank you 

10272015, 02:29 PM
Post: #12




RE: HP 35s Statistical Distributions Functions
(10262015 08:39 PM)Thomas Klemm Wrote: Here's a program for the Student's tdistribution: Thomas, two questions. What is the sequence of keys to enter STEP C006. To run the label I, the question is A ?, rather X?, right? 

10272015, 04:48 PM
Post: #13




RE: HP 35s Statistical Distributions Functions
(10272015 02:29 PM)PedroLeiva Wrote: What is the sequence of keys to enter STEP C006. Code: C006 ∫FN d T ; integrate pdf That's ∫ followed by T. [ ↰ ] [EQN] [ 9 ] Quote:To run the label I, the question is A ?, rather X?, right? Input is area (that's why A) and the result is \(x\) so that \(\int_{\infty}^x pdf(t)\,dt = A\). You may rename it to something different of course. Just don't use variables that are already used in the program. Thus X might be confusing. Cheers Thomas 

10272015, 05:22 PM
Post: #14




RE: HP 35s Statistical Distributions Functions
(10272015 04:48 PM)Thomas Klemm Wrote:Something is not working well. When I run the routine I (XEQ I ENTER), with a 1E6 E value in register E, the program do not stop integration!(10272015 02:29 PM)PedroLeiva Wrote: What is the sequence of keys to enter STEP C006. 

10272015, 07:32 PM
Post: #15




RE: HP 35s Statistical Distributions Functions
(10272015 05:22 PM)PedroLeiva Wrote: Something is not working well. When I run the routine I (XEQ I ENTER), with a 1E6 E value in register E, the program do not stop integration! The 1E–6 error threshold in E is irrelevant for the integration routine. The 35s "Integrate" function stops if the result is correct to display precision. You probably have set your 35s to ALL display mode, or maybe FIX 9 or SCI 9, so the 35s calculates the integral until is thinks it has all (!) 12 digits (resp. 9) correct. This will take some time. Solution: simply set something like FIX 4 or FIX 6 (you may add this step to the program right before the Integrate command), so you get 4 resp. 6 correct decimals. BTW, at the moment I am looking at an 35s implementation of the HP67 routines. Dieter 

10272015, 10:25 PM
(This post was last modified: 10272015 10:28 PM by Dieter.)
Post: #16




RE: HP 35s Statistical Distributions Functions
(10272015 07:32 PM)Dieter Wrote: BTW, at the moment I am looking at an 35s implementation of the HP67 routines. OK, here is a first experimental version of the Chi² algorithm used in the HP67 Stat Pac. PDF and CDF are calculated simultaneously, and both are returned in Y and X. Here is the code: Code: C001 LBL C Usage (results as shown in FIX 9 mode): Code: [XEQ] C [ENTER] J=? As usual, comments, suggestions and error reports are welcome. ;) Since the main computation routine (C013 ff.) returns both the PDF and the CDF, adding a function that determines the inverse (quantile) is rather simple. I tried an approach using a secondorder (Halley) method and it worked well for me. This required about 30 additional lines of code. Dieter 

10272015, 10:29 PM
Post: #17




RE: HP 35s Statistical Distributions Functions
(10272015 05:22 PM)PedroLeiva Wrote: the program do not stop integration! Let's try to pin that down. Dieter already gave a hint: the accuracy in register E and the display precision should match. But since the program I uses program C I first want to know if you get the same result for this example: XEQ T ENTER K? 7 R/S XEQ C ENTER X? 1.5 R/S 0.911351 This is just to make sure that program C works fine. If that's okay please make sure to set FIX 3 and E = 1E3 before running the next example. XEQ I ENTER X? 0.99 R/S 2.997 It should flicker about four times INTEGRATING and then display the result. If the integration doesn't stop then please add an R/S command between lines I007 and I008 and report both the value displayed and the contents of register X (use VIEW X). Just use R/S to run the next round of the loop for a couple of times. Hopefully this helps to find the problem. Cheers Thomas PS: Thanks for posting the HP67 programs. It's always interesting to learn something new. For instance I didn't know about the formula used to calculate the CDF of the Student's tdistribution. But then I must admit that I'm not familiar with statistics. Still I'm curious how they came up with that formula. 

10272015, 11:41 PM
(This post was last modified: 10272015 11:45 PM by PedroLeiva.)
Post: #18




RE: HP 35s Statistical Distributions Functions
(10272015 10:29 PM)Thomas Klemm Wrote:For routing T the value after R/S is 0.385(10272015 05:22 PM)PedroLeiva Wrote: the program do not stop integration! For routing C the value is the same as yours, 0.911351 The program did not stop integration again. After R/S adition the figures are: 1° time: x=0.878, y=3.782 E2; variable X= 1.273 2° time: x=0.5, y=3.850 E7; variable X= 0.001 # times: the same as 2° time 

10272015, 11:48 PM
Post: #19




RE: HP 35s Statistical Distributions Functions
(10272015 07:32 PM)Dieter Wrote:Thank you for your interest Dieter. I am ussing FIX 3, but the problem persist(10272015 05:22 PM)PedroLeiva Wrote: Something is not working well. When I run the routine I (XEQ I ENTER), with a 1E6 E value in register E, the program do not stop integration! 

10282015, 12:11 AM
Post: #20




RE: HP 35s Statistical Distributions Functions  
« Next Oldest  Next Newest »

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