How to manually create a Z-table

2.6k Views Asked by At

Z-tables are commonly found online. However, I am writing a precision program for this, and so I would like to find out how to calculate my own percentage values.

1

There are 1 best solutions below

11
On BEST ANSWER

Z-tables are just values of the CDF $$ F(x)=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{x} e^{-y^{2}/2}dy $$ at various points $x$. If you want to generate a Z-table, pick some $x$ points and evaluate that integral (using a numerical method of your choice).

As mentioned in the comments to your question, MATLAB (and other numerical software) already do this for you. Probably best not to reinvent the wheel.


Addendum: As @Ian mentioned, we should truncate the integral since it is on an unbounded domain. That is, we should look to compute instead

$$ F(x)\approx\frac{1}{\sqrt{2\pi}}\int_{w(x)}^{x}e^{-y^{2}/2}dy. $$ The question is thus, how do we pick $w(x)$? Let's say that you are only interested in computing the integral up to $\epsilon$ accuracy. Therefore, it might be reasonable to pick $w(x)$ such that $$ F(w(x))=\frac{1}{2}\text{erfc}(-w(x)/\sqrt{2})\leq\epsilon. $$ A well-known bound for the erf function is $$ \text{erfc}(x)\leq e^{-x^{2}}. $$ Plugging this into the above, $$ F(w(x))\leq\frac{1}{2}e^{-w(x)^{2}/2} $$ and thus it follows that $$ w(x)\leq-\sqrt{-2\log(2\epsilon)}. $$

For example, if $\epsilon=10^{-6}$, $w(x)\leq-5.1230$ (approximately). This makes sense, as 5-sigma events should not make much of a contribution in computation.

This bound is very conservative, however, and you could/should come up with a tighter one, or one that takes into account relative instead of absolute error (also mentioned in comments).