(35S) Statistical Distributions Functions

11192015, 01:00 PM
Post: #61




RE: HP 35s Statistical Distributions Functions
(11192015 09:24 AM)Gerald H Wrote: Could you, Dieter, please include a pdf file of the latest programmes in human readable form to enter on the calculator? The current programs have been developed on HP's 35s emulator so that they can be run by simply loading the posted *.ep file into the emulator. These programs have between 900 and 1000 lines of code. At the moment I do not know of a way to get them out of the emulator, i.e. all I could do is copy every single line by hand. If someone knows a way to transform an .ep emulator file into a readable listing, please let me know. On the other hand you anyway would have to enter the programs into your 35s manually, line by line. Does it really make much of a difference if this is done with a PDF listing or by stepping through the programs on the emulator? Dieter 

11192015, 01:17 PM
Post: #62




RE: HP 35s Statistical Distributions Functions
[/quote]
I'm working on a list of programming keystroke steps based on the .ep file. There are 10 labels and 926 steps, a total of 11 pages 4A landscape. Once finished, I will put these at the disposal of the Forum with the authorization of Dieter, after exhaustive revision errors. Pedro 

11192015, 05:52 PM
Post: #63




RE: HP 35s Statistical Distributions Functions
I'm amazed, Dieter, that you have developed such a large programme without having a human readable source to refer to  Congratulations!
I look forward to seeing your, PedroLeiva's, programme listing. 

11192015, 08:31 PM
(This post was last modified: 11192015 08:39 PM by Dieter.)
Post: #64




RE: HP 35s Statistical Distributions Functions
(11192015 01:17 PM)PedroLeiva Wrote: I'm working on a list of programming keystroke steps based on the .ep file. There are 10 labels and 926 steps, a total of 11 pages 4A landscape. I'd recommend you don't start before the final revision. ;) This morning the programs had 938 steps – I had added this and that, but this also allowed an error to creep in (which now has been corrected). Maybe I'll post another version in the next days. At the moment I am thinking of adding the Binomial and Poisson distribution functions. This would require just a few lines of code (less than 50 for both) since they can be calculated by means of the regularized Beta and Gamma functions. On the other hand maybe these two should better go into a second program pack for discrete distributions. Also, implementing the respective quantile functions here are a bit trickier. (11192015 01:17 PM)PedroLeiva Wrote: Once finished, I will put these at the disposal of the Forum with the authorization of Dieter, after exhaustive revision errors. Pedro Yes, extensive testing is required. I suggest you use something like Excel or OpenOffice Calc for the listings. This allows simple editing as well as some other useful features. Dieter 

11202015, 12:09 PM
Post: #65




RE: HP 35s Statistical Distributions Functions
Excellent idea. The inclusion of discrete variables complement the main statistical functions. In that sense I attach the programs I wrote for the HP 35s, including the listing of programming instructions and numerical examples. I ask pardon because the instructions are written in my native tongue, Spanish.
I learned to compress files, lets see if I did it well! Pedro 

11202015, 12:24 PM
Post: #66




RE: HP 35s Statistical Distributions Functions
Excellent work!
Good thing you avoided the EOS so the codes can be easily ported into other machines. Thanks Marcio 

11202015, 01:19 PM
(This post was last modified: 11202015 02:30 PM by Dieter.)
Post: #67




RE: HP 35s Statistical Distributions Functions
(11202015 12:09 PM)PedroLeiva Wrote: Excellent idea. The inclusion of discrete variables complement the main statistical functions. Here is a short and not at all optimized listing for the Poisson and Binomial cdfs. Simply add it to the current code. It's less than 50 steps. Code: P001 LBL P // Poisson CDF If this does not work you may have an older version of the other distributions. Especially if in some cases the correct Poisson result apprears in Y instead of X. ;) Test examples: Poisson cdf for lambda=7,3 and x=5 is 0,26404. Binomial cdf for n=20, p=0,2 and x=6 is 0,91331. (11202015 12:09 PM)PedroLeiva Wrote: In that sense I attach the programs I wrote for the HP 35s, including the listing of programming instructions and numerical examples. I ask pardon because the instructions are written in my native tongue, Spanish. As far as I can tell these programs calculate the density functions (probability mass functions), but not the cumulative densities. Two questions: First, why is it required to clear all variables (CLEAR 2), i.e. have the user lose all his data, before starting the programs? It's good practice that the program itselfs clears only the registers it requires. At the moment I even do not see a reason why any register has to be cleared at all. ?!? And second: why does the Binomial distribution calculate the combinations nCx although there is a dedicated HP35s nCr function that does this faster and with less problems (e.g. overflow)? You have to know that this function exists since you used it for the Hypergeometric distribution. ;) BTW, it seems that the program titled "Distribución Polinomial" actually calculates the multinomial distribution (es: distribución multinomial). Since I am not sure about the correct Spanish term: is there a difference between these two expressions or do they refer to the same distribution? If yes: the multinomial distribution can be calculated much easier and without using so many registers. Dieter 

11202015, 05:45 PM
Post: #68




RE: HP 35s Statistical Distributions Functions
Dieter, you are absolutely right, my programs calculate the probability for a variable value, not the cumulative probability. The instruction to delete all variables not is correct, I already have erased. Regarding the use of combinatorial calculation function, I did not use it because I decided to test my knowledge of statistics.
I loaded your labels for cumulative Binomial and Poisson function, they work perfectly well. I wonder why HP says 35s has 800 programation steps, whereas now with 982 still working well ? 

11202015, 05:47 PM
(This post was last modified: 11202015 06:47 PM by Dieter.)
Post: #69




RE: HP 35s Statistical Distributions Functions
(11202015 01:19 PM)Dieter Wrote: BTW, it seems that the program titled "Distribución Polinomial" actually calculates the multinomial distribution (es: distribución multinomial). Since I am not sure about the correct Spanish term: is there a difference between these two expressions or do they refer to the same distribution? If yes: the multinomial distribution can be calculated much easier and without using so many registers. OK, here is a version that features some advantages:
Code: M001 LBL M Here is an example using the data from your (Pedro's) PDF: Code: x1 = 2 p1 = 0,25 Hmmm... I just got another idea. Maybe this could be done with the Σ+ key using a sum of logs instead of a product... *8) Edit: Yes, this will also work: Code: M001 LBL M Program usage is the same as before. The code uses only logs of the factorial function (both "!" are followed by a "LN") so that this approach may be especially useful for calculators with lnΓ function, thus avoiding potential overflow problems. Dieter 

11202015, 08:30 PM
(This post was last modified: 11202015 08:44 PM by Dieter.)
Post: #70




RE: HP 35s Statistical Distributions Functions
(11202015 05:45 PM)PedroLeiva Wrote: I loaded your labels for cumulative Binomial and Poisson function, they work perfectly well. Just to be sure: try the Poisson example with lambda=7,3 for x=0, x=7 and x=15. You should get 0,0006755..., 0,5541... and 0,99641... (11202015 05:45 PM)PedroLeiva Wrote: I wonder why HP says 35s has 800 programation steps, whereas now with 982 still working well ? HP says the 35s can have up to 800+ data registers. These are the ones that are accessed indirectly by positive values in I or J. They are dynamically allocated (and deallocated by the CLVARx command). This memory area is very handy if you want to handle large data sets, e.g. a 20x20 matrix. As far as programs are concerned: Every labelled program can have up to 999 steps (e.g. A001...A999), which would allow for at least 26 (A...Z) x 999 = almost 26.000 steps – if there was sufficient memory, that is. So there is quite some room for more code. The whole 35s has 30 KB of memory, shared by programs, data, equations and some internal functions (e.g. Solve). Check MEM and see what's left. ;) Dieter 

11202015, 08:37 PM
Post: #71




RE: HP 35s Statistical Distributions Functions
(11202015 08:30 PM)Dieter Wrote: As far as programs are concerned: Every labelled program can have up to 999 steps (e.g. A001...A999), which allows for at least 26 (A...Z) x 999 = almost 26.000 steps. So there is sufficient room for more code. ;) Is there any way to assess this? I remember that I had like 1200+ lines of codes and they occupied nearly 1/3 of the device's memory, no equations anywhere. Marcio 

11202015, 08:54 PM
(This post was last modified: 11202015 09:32 PM by Dieter.)
Post: #72




RE: HP 35s Statistical Distributions Functions
(11202015 08:37 PM)Marcio Wrote:(11202015 08:30 PM)Dieter Wrote: As far as programs are concerned: Every labelled program can have up to 999 steps (e.g. A001...A999), which allows for at least 26 (A...Z) x 999 = almost 26.000 steps. So there is sufficient room for more code. ;) You can use the MEM command to see the remaining memory size in Bytes. N.B.: I have edited my previous post before I read your reply. The 26000 steps are a theoretical limit which would only be reached if there was sufficient memory. Since every program step requires several bytes, the max. number of steps should be substantially below 10000 steps. (11202015 08:37 PM)Marcio Wrote: I remember that I had like 1200+ lines of codes and they occupied nearly 1/3 of the device's memory, no equations anywhere. Every single program step requires at least three bytes, some use (even substantially) more. So 1200 lines times, say on average 4 Bytes/line are already nearly 5000 Bytes or 1/6 the full capacity. Especially using numbers (even a simple "1" or "15") is very memory consuming (and slow, for that matter), so that it may well be possible that a 1200 line program can use 30% of the total memory. I remember the days when the HP41 was new and how I tried to squeeze off one or two more bytes to make the program fit into the 224 byte capacity of a single magnetic card. ;) Dieter 

11202015, 11:06 PM
(This post was last modified: 11212015 01:49 PM by Dieter.)
Post: #73




RE: HP 35s Statistical Distributions Functions
(11202015 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 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 

11212015, 07:27 PM
(This post was last modified: 11272015 06:46 AM by Dieter.)
Post: #74




RE: HP 35s Statistical Distributions Functions
(11202015 11:06 PM)Dieter Wrote: 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). OK, here is a first version of the complete Poisson distribution: upper and lower CDF, PMF and – the inverse cdf (quantile). Usage is the same as with other programs of this pack. Only the quantile function returns something different: As the Poisson distribution handles a discrete random variable (x=0, 1, 2, 3, ...) the returned quantile is an integer. However, in most cases there is no exact integer for a given cumulative probability. That's why usually the quantile is defined as the smallest integer with a cdf greater than or equal to the given probability. For instance, if p=0,9 while cdf(11)=0,85 and cdf(12)=0,93 the quantile is 12. This may lead to offbyone errors in very close cases where the calculated cdf may be not exact in the last digits. That's why the following program returns three values. In x the calculated quantile is returned, and y at the same time holds the corresponding probability (cdf). Scrolling down the stack with R↓ displays the cdf for the next lower integer, i.e. for x–1. This way you can see the cdfs for the two adjacent integers that bracket the given probability. Example: mean = 7,3 and p=0,9. The program returns x=11 as well as 0,9319 = cdf(11) and 0,8788 = cdf(10). The method is quite simple and straightforward. It implements some insights of a 2013 paper by Michael Short titled "Improved Inequalities for the Poisson and Binomial Distribution and Upper Tail Quantile Functions". Actually the Poisson quantile can (almost) be calculated directly by means of Lambert's W function, but since the 35s does not offer one (unlike the 34s) I chose a different approach. Finally, here is the code: Code: P001 LBL P Poisson distribution starts here Try it and see what you get. As usual, this is supposed to work with the functions J, A, E and G included in the distributions package that was posted as an .ep file for the 35s emulator. I did not do much testing, so all error reports are welcome. Edit (20151123): added line P065/P066. However, there are still a few cases with larger mean an very small p that may return a slightly low result, e.g. m=50 and p=1E17 returns 2 instead of 4. Edit2 (20151126): this problem can be avoided by a different approach which also seems to work for the Binomial quantile. Dieter 

11262015, 11:07 PM
Post: #75




RE: HP 35s Statistical Distributions Functions
For the new example, m=50 and p=1E17 (SF 1), I don´t get the same result as you. For me is X=0, Y=1, Z=1, T=0. What is wrong? Pedro


11272015, 06:41 AM
(This post was last modified: 11272015 06:45 AM by Dieter.)
Post: #76




RE: HP 35s Statistical Distributions Functions
(11262015 11:07 PM)PedroLeiva Wrote: For the new example, m=50 and p=1E17 (SF 1), I don´t get the same result as you. For me is X=0, Y=1, Z=1, T=0. What is wrong? Pedro Make sure you added lines P065 and P066. And check if XEQ G006 points to the correct line (RCL A). But most important, there was an error in P049 which, after adding these lines, should read GTO P104. I just corrected this. Or, even better, forget about all this, wait a few days and use the complete recent version I just finished – including the Binomial quantile. It still requires some testing but I think I will post the .ep file this weekend. Dieter 

11292015, 06:50 PM
Post: #77




RE: HP 35s Statistical Distributions Functions
(11272015 06:41 AM)Dieter Wrote: Or, even better, forget about all this, wait a few days and use the complete recent version I just finished – including the Binomial quantile. Here it is. The attached file contains version 5 of the distributions package as well as a PDF with instructions for the Normal, Student, Chi² and Fisher distribution. Also included are instructions for some additional functions, while the part that handles the discrete distributions (Binomial, XEQ O and Poisson, XEQ P) is still missing. The Binomial and Poisson quantile functions use the 35s solver, so you'll see RUNNING...SOLVING....RUNNING before the result is returned. Here X holds the quantile, Y has the corresponding CDF and Z holds the CDF of x–1. This way you can check the result and see how close a continuous (real) quantile is to the adjacent integers. Note that the lower and uppers CDFs for the discrete discrtibutions do not sum up to 1 because they are P(X≤x) and P(X≥x), which means that PMF(x) is part of both sums. All this requires extensive testing, so load the .ep file into your 35s emulator and see what you get. There may and will be errors, so I'll appreciate all your error reports. Thank you in advance for all corrections and suggestions. Dieter Distributions_35s_5.zip (Size: 156.5 KB / Downloads: 41) 

« Next Oldest  Next Newest »

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