Re: Chi squared -> p-value - Any formula??
- From: Ray Koopman <koopman@xxxxxx>
- Date: Mon, 30 Jul 2007 13:44:22 -0700
On Jul 29, 2:10 am, "Dave (from the UK)" <see-my-signat...@see-
below.com> wrote:
Ray Koopman wrote:
My favorite simple approximation for the standard normal cdf is
1/(1 + Exp[-.496937z*Sqrt[z^2 + 10.28]]),
for which the absolute error is < 1.58*10^-4.
The corresponding approximation for the complementary cdf (i.e.,
the upper tail area) of a chi-square variable with 1 d.f. is
2/(1 + Exp[.496937*Sqrt[x(x + 10.28)]).
Thanks for that Ray - it was most helpful.
The claimed accuracy of the approximation for the standard normal cdf (<
1.58*10^-4) is somewhat better than that of the approximation Ken gave,
and is also simpler to type, so I decided to try your approximation.
I did some checks of your formula in Mathematica and found largest
*absolute* error of the p-value is 0.0003147. (I tested that for
chi-squared values in the range 0 to 40 in steps of 0.00001)
For chi-squared in the range 0 to 6.63489 (p-values 1.0 down to 0.01),
the maximum fractional error in the p-values was 2.91%.
Extending its range somewhat more, with chi-squared to 10.827566
(p-values of 1.0 down to 0.001) gave an error in the p-values of <= 9.18
%, which is good enough for me.
Just for completeness, I tested it to p-values down to 0.0001
(chi-squared up to 15.136705) at which point the error in p-values is
quite large (16.9%), but realistically for me, I'm only really
interested in p-values down to 0.005 or so, where the error is 4.56% or
less.
So far I've only tested a Mathematica approximation, but assuming Tcl's
maths functions are not broken, it should give similar results in Tcl.
BTW, the reason for using Tcl is that I have a program that was
originally written in that. Its not an ideal language for maths stuff,
but the main program is a chess database, not a maths package.
--
Dave (from the UK)
Please note my email address changes periodically to avoid spam.
It is always of the form: month-y...@xxxxxxxxxxxx
Hitting reply will work for a few months only - later set it manually.
http://chessdb.sourceforge.net/- a Free open-source Chess Database
The normal cdf gives a one-tailed p-value, but the chi-square ccdf is
equivalent to a two-tailed normal p-value, so the error will also be
twice as large. To see the error curves in Mathematica:
Plot[1/(1 + Exp[-.496937z*Sqrt[z^2 + 10.28]]) - .5 Erfc[-z/Sqrt[2]],
{z,-4.5,4.5}];
Plot[2/(1 + Exp[.496937*Sqrt[x(x + 10.28)]]) - Erfc[Sqrt[x/2]],
{x,0,20}];
.
- References:
- Chi squared -> p-value - Any formula??
- From: Dave (from the UK)
- Re: Chi squared -> p-value - Any formula??
- From: Ray Koopman
- Re: Chi squared -> p-value - Any formula??
- From: Dave (from the UK)
- Chi squared -> p-value - Any formula??
- Prev by Date: Re: Is constructing a contingency table from odds ratio's (including 95%CI) possible
- Next by Date: Re: Is constructing a contingency table from odds ratio's (including 95%CI) possible
- Previous by thread: Re: Chi squared -> p-value - Any formula??
- Next by thread: Re: Chi squared -> p-value - Any formula??
- Index(es):