Post Reply 
Inverse Normal Program for HP 42s
10-23-2024, 04:47 AM (This post was last modified: 10-23-2024 04:52 AM by cylurian.)
Post: #1
Inverse Normal Program for HP 42s
I'm looking for suggestions on how to create a program for the HP42S and DM42 to calculate the inverse normal. Specifically, if I have the mean, standard deviation, and a given percentile (a probability from negative infinity to a specific x value), how can I calculate that x value?

I have the CDF and PDF programs for the normal distribution (see below). Would it be possible to use these programs to write a new program for the inverse normal calculation? Any advice or examples would be greatly appreciated! thx.

Code:

00 { 34-Byte Prgm }
01▸LBL "NCDF"
02 INPUT "μ"
03 INPUT "s"
04 INPUT "LLIM"
05 INPUT "ULIM"
06 1E-7
07 STO "ACC"
08 PGMINT "NPDF"
09 INTEG "x"
10 END

Code:
00 { 31-Byte Prgm }
01▸LBL "NPDF"
02 RCL "x"
03 RCL- "μ"
04 RCL÷ "s"
05 X↑2
06 -2
07 ÷
08 E↑X
09 RCL÷ "s"
10 2
11 PI
12 ×
13 SQRT
14 ÷
15 END
Find all posts by this user
Quote this message in a reply
10-23-2024, 07:52 AM (This post was last modified: 10-23-2024 08:04 AM by Thomas Klemm.)
Post: #2
RE: Inverse Normal Program for HP 42s
Something like this?
Code:
00 { 31-Byte Prgm }
01▸LBL "pdf"
02 RCL "x"
03 RCL- "μ"
04 RCL÷ "s"
05 X↑2
06 -2
07 ÷
08 E↑X
09 RCL÷ "s"
10 2
11 PI
12 ×
13 SQRT
14 ÷
15 END

Code:
00 { 26-Byte Prgm }
01▸LBL "cdf"
02 PGMINT "pdf"
03 INTEG "x"
04 RCL- "%ile"
05 0.5
06 +
07 END

Code:
00 { 42-Byte Prgm }
01▸LBL "cdf↑-1"
02 INPUT "μ"
03 INPUT "s"
04 INPUT "%ile"
05 RCL "μ"
06 STO "LLIM"
07 PGMSLV "cdf"
08 SOLVE "ULIM"
09 END

Example

FIX 06
0.000001
STO "ACC"

XEQ "cdf↑-1"

μ?0.000000

5 R/S

s?1.000000

2 R/S

%ile?0.500000

0.95 R/S

8.289707
Find all posts by this user
Quote this message in a reply
10-23-2024, 09:00 PM (This post was last modified: 10-23-2024 09:01 PM by cylurian.)
Post: #3
RE: Inverse Normal Program for HP 42s
This is the final version of the Inverse Normal program for the DM42, which may also be compatible with the HP 42S. When you execute the program, it will prompt you to input the mean, standard deviation, and the desired percentile from negative infinity. After entering each value, press the R/S (Run/Stop) button to proceed to the next input. The accuracy is built-in (1E-12) so you don't have to worry about entering that number. You can always change that. The entire program is contained in a single sequence. Thanks Thomas for helping me put this together. Learning more as I do these.

Code:

00 { 42-Byte Prgm }
01▸LBL "invN"
02 INPUT "μ"
03 INPUT "s"
04 INPUT "%ile"
05 RCL "μ"
06 STO "LLIM"
07 PGMSLV "cdf"
08 SOLVE "ULIM"
09 END

00 { 26-Byte Prgm }
01▸LBL "cdf"
02 1E-12
03 STO "ACC"
04 PGMINT "pdf"
05 INTEG "x"
06 RCL- "%ile"
07 0.5
08 +
09 END

00 { 31-Byte Prgm }
01▸LBL "pdf"
02 RCL "x"
03 RCL- "μ"
04 RCL÷ "s"
05 X↑2
06 -2
07 ÷
08 E↑X
09 RCL÷ "s"
10 2
11 PI
12 ×
13 SQRT
14 ÷
15 END
Find all posts by this user
Quote this message in a reply
11-20-2024, 03:44 AM (This post was last modified: 11-20-2024 07:03 AM by Thomas Klemm.)
Post: #4
RE: Inverse Normal Program for HP 42s
For percentiles close enough to 50% (say 20% - 80%) the following approximation can be used:
Code:
00 { 48-Byte Prgm }
01▸LBL "cdf↑-1"
02 INPUT "μ"
03 INPUT "s"
04 INPUT "%ile"
05 RCL "%ile"
06 0.5
07 -
08 PI
09 SQRT
10 ×
11 ASIN
12 ASIN
13 2
14 SQRT
15 ×
16 RCL× "s"
17 RCL+ "μ"
18 END

This method can also be used on calculators without solve and integrate.
Make sure that the calculator is in RAD mode.

Example

XEQ "cdf↑-1"

μ?0.000000

5 R/S

s?1.000000

2 R/S

%ile?0.500000

0.8 R/S

6.683394

Compare this to the proper value:

6.683242



For those wondering why this works:

\(
\begin{align}
\sin\left(\sin(x)\right) &= x - \frac{x^3}{3} + \frac{x^5}{10} - \frac{8 x^7}{315} + \frac{13 x^9}{2520} + \mathcal{O}\left(x^{11}\right) \\
\\
\int_0^x e^{-t^2} dt &= x - \frac{x^3}{3} + \frac{x^5}{10} - \frac{x^7}{42} + \frac{x^9}{216} + \mathcal{O}\left(x^{11}\right) \\
\end{align}
\)

They have the same degree-5 Taylor approximation.
Find all posts by this user
Quote this message in a reply
Post Reply 




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