crit-chi2 and prob-chi2

Started by johu, February 08, 2010, 12:57:57 AM

Previous topic - Next topic

johu

I am newLISP user in Japan.

I am trying to translate the reference manual of newLISP into Japanese now.

http://cid-23a9a25e1aec3626.skydrive.live.com/self.aspx/%E5%85%AC%E9%96%8B/newlisp%5E_manual-C.html">//http://cid-23a9a25e1aec3626.skydrive.live.com/self.aspx/%e5%85%ac%e9%96%8b/newlisp%5E_manual-C.html

Then, I tried the function of crit-chi2 and prob-chi2.


Quote
> (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/stats_data_analysis/principles/chi_table.html">//http://mips.stanford.edu/public/classes/stats_data_analysis/principles/chi_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

#1
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.



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

#2
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/">http://www.newlisp.org/downloads/development/latest/



pps: the calculation of Fisher's Chi2 in 'bayes-query' was never affected by this

Ryon

#3
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.
\"Give me a Kaypro 64 and a dial tone, and I can do anything!\"

johu

#4
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.