newLISP Fan Club

Forum => newLISP in the real world => Topic started by: johu on February 08, 2010, 12:57:57 AM

Title: crit-chi2 and prob-chi2
Post by: johu on February 08, 2010, 12:57:57 AM
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

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



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.
Title: Re: crit-chi2 and prob-chi2
Post by: johu on February 10, 2010, 12:49:52 AM
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.
Title: Re: crit-chi2 and prob-chi2
Post by: Lutz on February 10, 2010, 04:40:48 AM
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
Title: Re: crit-chi2 and prob-chi2
Post by: Ryon on February 10, 2010, 08:32:13 AM
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.
Title: Re: crit-chi2 and prob-chi2
Post by: johu on February 11, 2010, 01:46:59 AM
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.