Article 5FC0E Computing normal probabilities with a simple calculator

Computing normal probabilities with a simple calculator

by
John
from John D. Cook on (#5FC0E)

If you need to calculate (x), the CDF of a standard normal random variable, but don't have on your calculator, you can use the approximation [1]

(x) 0.5 + 0.5*tanh(0.8 x).

If you don't have a tanh function on your calculator, you can use

tanh(0.8x) = (exp(1.6x) - 1) / (exp(1.6x) + 1).

This saves a few keystrokes over computing tanh directly from its definition [2].

Example

For example, suppose we want to compute (0.42) using bc, the basic calculator on Unix systems. bc only comes with a few math functions, but it has a function e for exponential. Our calculation would look something like this.

 > bc -lq t = e(1.6*0.42); (1 + (t-1)/(t+1))/2 .66195084790657784948

The exact value of (0.42) is 0.66275....

Plots

It's hard to see the difference between (x) and the approximation above.

phi_approx.png

A plot of the approximation error shows that the error is greatest in [-2, -1] and [1, 2], but the error is especially small for x near 0 and x far from 0.

phi_approx_error.png

Related posts

[1] Anthony C. Robin. A Quick Approximation to the Normal Integral. The Mathematical Gazette, Vol. 81, No. 490 (Mar., 1997), pp. 95-96

[2] Proof: tanh(x) is defined to be (ex - e-x) / (ex + e-x). Multiply top and bottom by ex to get (e2x - 1) / (e2x + 1).

The post Computing normal probabilities with a simple calculator first appeared on John D. Cook.Sxx_vXPhYuM
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments