crit-chi2 and prob-chi2

Q&A's, tips, howto's
Locked
johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

crit-chi2 and prob-chi2

Post by johu »

I am newLISP user in Japan.
I am trying to translate the reference manual of newLISP into Japanese now.
http://cid-23a9a25e1aec3626.skydrive.li ... ual-C.html
Then, I tried the function of crit-chi2 and prob-chi2.
> (crit-chi2 0.99 1)

ERR: invalid parameter: 0.0 in function crit-chi2
> (crit-chi2 0.99 2)
9.21034045
> (gammai 1 (div (crit-chi2 0.99 2) 2))
0.9900000004
> (prob-chi2 (crit-chi2 0.99 2) 2)
0.009999999611
> (crit-chi2 0.99 3)
9.210340052
> (gammai 1.5 (div (crit-chi2 0.99 3) 2))
0.9733788431
> (gammai 1.5 (div 11.345 2))
0.9900006159
> (prob-chi2 (crit-chi2 0.99 3) 3)
0.0100000016
> (sub 1.0 (gammai 1 (div (crit-chi2 0.99 3) 2)))
0.0100000016
> (crit-chi2 0.99 4)
13.27670443
> (gammai 2 (div (crit-chi2 0.99 4) 2))
0.9900000013
> (prob-chi2 (crit-chi2 0.99 4) 4)
0.009999998736
> (prob-chi2 (crit-chi2 0.99 4) 5)
0.009999998736
>
The Chi-Squared Distribution Table
http://mips.stanford.edu/public/classes ... table.html

I am not good at statistics.
Are these true or nil?
Please give advice to me.

And I'm sorry, if my English usage was wrong.

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: crit-chi2 and prob-chi2

Post by johu »

My writing might have been bad. Or my explanation might have been insufficient.
My platform is Win32 and Puppy Linux.
The result is the same as both.
Then, I saw the source(nl-math.c), and tried to change probChi2 and critChi2.

Code: Select all

double probChi2(double chi2, int df)
{
return(1.0 - gammap(df/2.0, chi2/2.0));
}

double critChi2(double p, int df)
{
    :
    {
    if (gammap(df/2.0, chisqval/2.0) < p) minchisq = chisqval;
    :
    }
return chisqval;
}
When changing like this and compiling, the degrees of freedom 1 doesn't make an error of cirt-chi2.
And the return value when degree of freedom is an odd number is also corresponding to the Chi-Squared Distribution Table.

I think that there is a possibility of unquestionable according to the compiler.
But, if the error happens by (crit-chi2 0.99 1), I will recommend changing.

Thank you for reading to the last minute.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: crit-chi2 and prob-chi2

Post by Lutz »

Thanks for the report. The chi2 values calculated for odd degrees of freedom are too low. There should be approximately in the middle of values for the two adjacent even degrees of freedom. Note that 'pro-chi2' currently is taking (1.0 - p) numbers for the probability. This will be changed, to take p.

ps: corrected files can be found here: http://www.newlisp.org/downloads/development/latest/

pps: the calculation of Fisher's Chi2 in 'bayes-query' was never affected by this
Last edited by Lutz on Wed Feb 10, 2010 9:56 pm, edited 1 time in total.

Ryon
Posts: 248
Joined: Thu Sep 26, 2002 12:57 am

Re: crit-chi2 and prob-chi2

Post by Ryon »

Thanks for taking on the English - Japanese translation, johu! Your English is fine. It's Chi-Squared that some of us (like me) don't understand.

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: crit-chi2 and prob-chi2

Post by johu »

Thank for the comment, Ryon.
I am one of some, too.

And
Thank for putting out newLISP to the world, Lutz.
I am enjoying newLISP, and it is useful for me.

Locked