Seven statistical distributions

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
rawi
Posts: 13
Joined: Sat Dec 28, 2019 3:50 am

Seven statistical distributions

Post by rawi » Tue Jun 30, 2020 7:56 pm

This program computes the probabilities and the cumulated probabilities resp. the distribution function and the cumulative distribution function of seven important statistical distributions:
- Binomial distribution
- Hypergeometric distribution
- Poisson distribution
- Standard normal distribution
- Student’s t distribution
- Chi-square distribution
- Fisher’s F distribution

Application:
After calling “STATD” the following is showed: "B H P N t C F"
Each letter stands for one distribution. To get to the distribution enter the position of the letter. If you want Hypergeometric distribution (=H) enter “2”, because H is in the second position, and press R/S.
Then the program asks for the parameters of the distribution. Enter them and press R/S. Then the probability resp. the value of the density function will be returned in Y-register whereas the cumulative probability f(X<=x) resp. the cumulative density function is returned in X-register.

Examples:

1st In Lotto 6 out of 49 are winning numbers. What is the probability that if you select 6 numbers randomly that you have at most 2 from the winning numbers (which means that you do not win at all):
XEQ “STATD” -> “B H P N t C F“ - We need Hypergeometric distribution, so we press
2 R/S -> “N” - The size of the universe is 49, so:
49 R/S -> “M” – The number of elements in the universe which are winning number is 6:
6 R/S -> “n” – The size of the sample is 6 ->
6 R/S -> “x” – The maximum number of winning numbers in sample we want to know the probability is 2 -> 2 R/S
Result in X-register: 0.9814 (prob(X<=2))
Result in Y-register: 0.1324 (prob(X=2))
So the probability not to win at all is greater than 98%.

2nd In a regression analysis with n=36 data points and k=3 independent variables the t-value for independent variable X1 is 2.234. Is this significant with a level of confidence of 95%?
XEQ “STATD” -> “B H P N t C F“ - We need Student’s t-distribution, so we press
5 R/S -> “df” – The regression has n-k-1 = 36-3-1 = 32 degrees of freedom
32 R/S -> “x”
2.234 R/S
Result in X-register: 0.9837
Result in Y-register: 0.0363 (corrected figure)
We need a symmetric interval. If on the right side there are 1.63% right of 2.234 there are 1.63% left of -2.234. Therefore this is significant with (100-2*1.63)% = 96.74% which is greater than 95%. So it is significant by 95%.
I hope this explains the application of the program.

Remarks:
1. The program uses the integral function of the DM42. It works with an accuracy of 1E-5. This can be changed by changing line 6 of the program.
2. Program needs subroutines ndis, tdis, cdis and fdis.

Best
Raimund

Code: Select all

00 { 415-Byte Prgm }
01▸LBL "STATD"
02 0
03 STO 01
04 STO 05
05 STO "LLIM"
06 1ᴇ-5
07 STO "ACC"
08 SF 01
09 "B H P N t C F"
10 PROMPT
11 XEQ IND ST X
12 RCL 06
13 RCL 05
14 RTN
15▸LBL 01
16 "p"
17 PROMPT
18 STO 00
19 STO- 01
20 "n"
21 PROMPT
22 STO 02
23 STO 04
24 "x"
25 PROMPT
26 STO 03
27 STO- 04
28 1
29 STO+ 01
30▸LBL 08
31 RCL 00
32 RCL 03
33 Y↑X
34 RCL 01
35 RCL 04
36 Y↑X
37 ×
38 RCL 02
39 RCL 03
40 COMB
41 ×
42 STO+ 05
43 FS?C 01
44 STO 06
45 1
46 STO- 03
47 STO+ 04
48 RCL 03
49 X<0?
50 RTN
51 GTO 08
52▸LBL 02
53 "N"
54 PROMPT
55 STO 00
56 "M"
57 PROMPT
58 STO 01
59 "n"
60 PROMPT
61 STO 02
62 RCL 00
63 X<>Y
64 COMB
65 STO 04
66 "x"
67 PROMPT
68 STO 03
69▸LBL 09
70 RCL 01
71 RCL 03
72 COMB
73 RCL 04
74 ÷
75 RCL 00
76 RCL 01
77 -
78 RCL 02
79 RCL 03
80 -
81 COMB
82 ×
83 STO+ 05
84 FS?C 01
85 STO 06
86 1
87 STO- 03
88 RCL 03
89 X<0?
90 RTN
91 GTO 09
92▸LBL 03
93 "mue"
94 PROMPT
95 STO 00
96 "x"
97 PROMPT
98 STO 03
99▸LBL 10
100 RCL 00
101 +/-
102 E↑X
103 RCL 00
104 RCL 03
105 Y↑X
106 ×
107 RCL 03
108 N!
109 ÷
110 STO+ 05
111 FS?C 01
112 STO 06
113 1
114 STO- 03
115 RCL 03
116 X<0?
117 RTN
118 GTO 10
119▸LBL 04
120 CF 01
121 "z"
122 PROMPT
123 STO "ULIM"
124 2
125 PI
126 ×
127 SQRT
128 STO 00
129 XEQ "NDIS"
130 STO 06
131 PGMINT "NDIS"
132 INTEG "X"
133 0.5
134 +
135 STO 05
136 RTN
137▸LBL 05
138 CF 01
139 "df"
140 PROMPT
141 STO 02
142 "x"
143 PROMPT
144 STO "ULIM"
145 RCL 02
146 1
147 +
148 2
149 ÷
150 GAMMA
151 RCL 02
152 2
153 ÷
154 GAMMA
155 ÷
156 RCL 02
157 PI
158 ×
159 SQRT
160 ÷
161 STO 00
162 RCL "ULIM"
163 XEQ "TDIS"
164 STO 06
165 PGMINT "TDIS"
166 INTEG "X"
167 0.5
168 +
169 STO 05
170 RTN
171▸LBL 06
172 CF 01
173 "df"
174 PROMPT
175 STO 03
176 "x"
177 PROMPT
178 STO "ULIM"
179 XEQ "CDIS"
180 STO 06
181 PGMINT "CDIS"
182 INTEG "X"
183 STO 05
184 RTN
185▸LBL 07
186 CF 01
187 "df1"
188 PROMPT
189 STO 01
190 "df2"
191 PROMPT
192 STO 02
193 "x"
194 PROMPT
195 STO 03
196 STO "ULIM"
197 RCL 01
198 RCL 02
199 ÷
200 RCL 01
201 2
202 ÷
203 Y↑X
204 RCL 01
205 2
206 ÷
207 GAMMA
208 ÷
209 RCL 02
210 2
211 ÷
212 GAMMA
213 ÷
214 RCL 01
215 RCL 02
216 +
217 2
218 ÷
219 GAMMA
220 ×
221 STO 00
222 PGMINT "FDIS"
223 INTEG "X"
224 STO 05
225 RCL "ULIM"
226 XEQ "FDIS"
227 STO 06
228 RTN
229 END

Code: Select all

00 { 23-Byte Prgm }
01▸LBL "NDIS"
02 MVAR "X"
03 RCL "X"
04 X↑2
05 -2
06 ÷
07 E↑X
08 RCL 00
09 ÷
10 RTN
11 END

Code: Select all

00 { 47-Byte Prgm }
01▸LBL "CDIS"
02 MVAR "X"
03 RCL "X"
04 RCL 03
05 2
06 ÷
07 1
08 -
09 Y↑X
10 RCL "X"
11 +/-
12 2
13 ÷
14 E↑X
15 ×
16 2
17 RCL 03
18 2
19 ÷
20 Y↑X
21 ÷
22 RCL 03
23 2
24 ÷
25 GAMMA
26 ÷
27 RTN
28 END

Code: Select all

00 { 32-Byte Prgm }
01▸LBL "TDIS"
02 MVAR "X"
03 RCL "X"
04 X↑2
05 RCL 02
06 ÷
07 1
08 +
09 RCL 02
10 1
11 +
12 2
13 ÷
14 +/-
15 Y↑X
16 RCL 00
17 ×
18 RTN
19 END

Code: Select all

00 { 44-Byte Prgm }
01▸LBL "FDIS"
02 MVAR "X"
03 RCL "X"
04 RCL 01
05 ×
06 RCL 02
07 ÷
08 1
09 +
10 RCL 01
11 RCL 02
12 +
13 2
14 ÷
15 +/-
16 Y↑X
17 RCL "X"
18 RCL 01
19 2
20 ÷
21 1
22 -
23 Y↑X
24 ×
25 RCL 00
26 ×
27 RTN
28 END
Last edited by rawi on Sun Jul 05, 2020 8:34 pm, edited 1 time in total.

fridlmue
Posts: 14
Joined: Mon Dec 09, 2019 8:57 am
Location: Germany - Saxony

Re: Seven statistical distributions

Post by fridlmue » Thu Jul 02, 2020 7:10 pm

Thank you for sharing that useful toolkit! Would you mind sharing the .raw-file from the DM42?
HP-41cx, HP-35s, DM42

rawi
Posts: 13
Joined: Sat Dec 28, 2019 3:50 am

Re: Seven statistical distributions

Post by rawi » Thu Jul 02, 2020 7:53 pm

Thank you very much for your interest. Attached you will find the *.raw files of the main program and two subroutines. Somehow the system does not allow to attach more files. Sorry for that.

Best

Raimund
fdis.raw
(47 Bytes) Downloaded 8 times
tdis.raw
(35 Bytes) Downloaded 11 times
STATD.raw
(418 Bytes) Downloaded 10 times

rawi
Posts: 13
Joined: Sat Dec 28, 2019 3:50 am

Re: Seven statistical distributions

Post by rawi » Thu Jul 02, 2020 7:59 pm

and now the rest...
ndis.raw
(26 Bytes) Downloaded 9 times
cdis.raw
(50 Bytes) Downloaded 8 times

fridlmue
Posts: 14
Joined: Mon Dec 09, 2019 8:57 am
Location: Germany - Saxony

Re: Seven statistical distributions

Post by fridlmue » Sun Jul 05, 2020 3:03 pm

Hi Raimund,

thanks for providing the raw's.
I can follow your 1st example.
On the second one (and some other things I tried) I get a Nonexistent when following your example.
Yet, I don't know why. But on yours it works with the shared raw's?
(For sure I downloaded and loaded all of them. )

Thanks!
HP-41cx, HP-35s, DM42

rawi
Posts: 13
Joined: Sat Dec 28, 2019 3:50 am

Re: Seven statistical distributions

Post by rawi » Sun Jul 05, 2020 9:01 pm

I downloaded from the Swissmicros website the raw-files for STATD and tdis to be sure I have the same version as you have. Then I loaded them in Free42 and it worked (there was a typo concerning the output of the density function; the correct figure is .0363, sorry, I corrected it but the cumulative density function was fine). I checked it for another set of data as well: According to a statistical table the cumulated density function for t-distribution with 19 degrees of freedom and x=2.093 is 0.975. That is exactly the result I get.

The flow is as follows:
Catalog - PGM - STATD -
->"B H P N t C F"
5 R/S
-> df
19 R/S
-> x
2.093 R/S
-> 0.9750
So it seems to work.

One possibility: Do you give enough registers? Registers 00 to 06 are needed.

Post Reply