Re: Chi squared -> p-value - Any formula??



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-year@xxxxxxxxxxxx
Hitting reply will work for a few months only - later set it manually.

http://chessdb.sourceforge.net/ - a Free open-source Chess Database
.



Relevant Pages

  • Re: Chi squared -> p-value - Any formula??
    ... The claimed accuracy of the approximation for the standard normal cdf (< ... I tested it to p-values down to 0.0001 ... The normal cdf gives a one-tailed p-value, but the chi-square ccdf is ...
    (sci.stat.math)
  • Re: Fishers Exact Test and Chi-square
    ... 'best' value to calculate but chi-square is ... Chi-square approximation isn't great because the chi-square ... distribution is continuous but the cell counts are discrete. ... There can be no single exact distribution because the probabilities ...
    (sci.stat.consult)
  • Re: Fishers Exact Test and Chi-square
    ... 'best' value to calculate but chi-square is ... Chi-square approximation isn't great because the chi-square ... distribution is continuous but the cell counts are discrete. ... This is why conditional tests can be exact. ...
    (sci.stat.consult)
  • Re: Weighted sum of squared normals question
    ... Ray Koopman wrote: ... the idea of a chi-square approximation is very ... are those of the Statistics Department or of Purdue University. ...
    (sci.stat.math)
  • Re: When to use Fisher?
    ... Why not always use Fisher? ... based on an approximation of discretely distributed chi-square values ... to avoid the chi-square test when the numbers in the contingency table ...
    (sci.stat.math)