Re: P-value from chi-square value: source code




Ian Smith wrote:
> "Reef Fish" <Large_Nassau_Grouper@xxxxxxxxx> wrote in message
news:<1113074906.743917.66500@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
> > DZ wrote:
> > > P.S. The p-value is 1-chi_cdf(ChiSquare, df)
> >
> > If so, why do you need any ChiSquare software, let along coding it?
> > Why wouldn't any standard normal software suffice?
> > >
> > > DZ wrote:
> > > > Dhruv <bhaveshrb@xxxxxxxxx> wrote:
> > > >> Ian Smith wrote:
> > > >>> "Dhruv" <bhaveshrb@xxxxxxxxx> wrote
> > > >>> > Could anyone send me a link to the source code in C++ for
> > > >>> > calculating the P-value from a chi-square value.
> > > >>> You are looking for code to evaluate the upper tail
probability
> > of a
> > > >>> chi-squared distribution.
> > > >>> http://odin.mdacc.tmc.edu/anonftp/#DCDFLIB
> > > >>
> > > >> I actually tried the code and am having some problems with it.
I
> > am
> > > >> sort of a newbie to programming and though I have managed to
write
> > > >> some good code, I am unable to figure out the problem at
present.
> > > >> What I need basically is a function which takes in Chi-square
> > value
> > > >> and returns the P-value. Please help me on this.
> > > >
> > > > You need to compile the library and use the function "cdfchi" ,
> > > > passing parameters as addresses, for example:
> > > >
> > > > double chi_cdf (double ChiSquare, double df) {
> > > > double q, p, bound;
> > > > int which=1, status;
> > > > cdfchi(&which, &p, &q, &ChiSquare, &df, &status, &bound);
> > > > return p;
> > > > }
> >
> > And Ian Smith gave two links and said,
> >
> > IS> both have C code which will do it and there is nothing better
out
> > IS> there that I know of.
> >
> > Nothing better? Use either or both those links and let us know
> > that the p-values (1-tail will do) for observed 1 df Chisquare
> > values of 1, 10, and 100, to at least 8 significant figures,
> > and then I'll tell you how many better ones there are. :-)
> >
> > -- Bob.
>
My point was merey my counterpoint to your "there is noting better out
there"
even thought you did have the qualifying disclaimer "that I know of".

> For Gnumeric, the figures (rounded to 15 figures) you requested were
> 3.17310507862914E-01, 1.56540225800255E-03 & 1.52397060483210E-23
> I believe the 3rd one should be 1.52397060483211E-23

For this pedantic numeric exercise, the p-value of 100 (1 d.f.) is

1.523970604832105213139466865031986167270080665559139211560717 E-23

because I asked for only 60 significant figures of the 100 max. It
took my 14-year old laptop less than 1 sec to get this (and the
software
ET (Electronic Tables) is one of the reason I kept the laptop. :-)

1.52397060483210E-23
1.52397060483211E-23
You're correct that the 11 should be the rounded value.

As for your software,
http://members.aol.com/iandjmsmith/EXAMPLES.HTM (my own software, it
gave
a result incorrect in the last two significant figures:

1.5239706048321013 E-23
1.523970604832105213139466865031986167270080665559139211560717 E-23

which suggests that those were your double-precision noise.


> However, I do not think an algorithm for a chi-squared distribution
> for 1 degree of freedom (i.e. a simple transformation of the normal)
> is of much interest.

That was one point I made on DZ's post, before challenging you on the
"nothing better out there" conjecture.

For double-precision arithmetic, those software you named are probably
as good any of dozens of others using double-precision with EXACT
formulas for calculating the tail probabilities. Many of them are
interpretive languages, such as S, S+, and so on, so that there is
no NEED to do any CODING, expecially using primitive codes like C,
C+, C++ , etc.


> In my opinion, most statistical software available is pretty poor.

Here you have to be careful about what do you mean by "most" and
"pretty
poor". There is no need to knock any software or tout your own -- all
you have to do is to say what PRECISION it'll guarantee to deliver and
let others decide whether it's good, good enough, or poor.


> It would be nice when people recommend software if they included some
> details of why. Admittedly, my explanation was perhaps too brief, but
> at least I do know the software. I have looked at several software
> packages in a variety of languages and I stick by what I said before.
> There is nothing better out there that I know of.

See my preceding comments. In my opinion, the software ET beats your
software (in precision, flexibility, and versatility) as a modern jet
beats a turtle in a 100 yard dash. :-)

For Special functions, it has beta, incomplete beta, and incomplete
gamma.
It has all the trigonometric functions
For continuous densities, it has the usual, in addition to
Weibull, noncentral chi-square, double-noncentral t, double noncentral
F,
and others.

Last but not least, it's' NOT MY software, and I have absolutely
nothing
to do with it. :-) I was kindly given the copy by the author of the
software when I was studying the accuracy of various exact and
approximate
numbercal algorithms for probability functions.

I don't know if its still commercially available.

-- Bob
>
> If you wish to get a better idea of the accuracy of these methods try
> the Chi-squared calculator at
> http://members.aol.com/iandjmsmith/EXAMPLES.HTM (my own software is
> not in C or I would have recommended it) or download Gnumeric and
give
> it a go!
>
> Ian Smith

.