Knut Krueger
2010-Jul-21 10:52 UTC
[R] Chi-square distribution probability density function:
Hi to all I found an formular of an ** ***p-Value Calculator for the Chi-Square test* *http://www.danielsoper.com/statcalc/calc11.aspx* *with the formula* *http://www.danielsoper.com/statkb/topic11.aspx* *what's the gamma function of this formula in r?* *df=5* *ch2=25.50878* *the following code does not give the result <0.001 for the values above * *p= ((0.5^(df/2))/gamma(df))*(ch2^((df/2)-1))* (2.718281828459^(-ch2/2)) or is there any other error? Regards Knut *** [[alternative HTML version deleted]]
David Winsemius
2010-Jul-21 12:02 UTC
[R] Chi-square distribution probability density function:
On Jul 21, 2010, at 6:52 AM, Knut Krueger wrote:> Hi to all I found > an formular of an ** > ***p-Value Calculator for the Chi-Square test* > *http://www.danielsoper.com/statcalc/calc11.aspx* > *with the formula* > *http://www.danielsoper.com/statkb/topic11.aspx* > *what's the gamma function of this formula in r?* > *df=5* > *ch2=25.50878* > *the following code does not give the result <0.001 for the values > above * > *p= ((0.5^(df/2))/gamma(df))*(ch2^((df/2)-1))* (2.718281828459^(- > ch2/2)) > or is there any other error?Check your implementation of that formula. You made an error in the gamma argument. See also: ?Chisquare ?gamma -- David Winsemius, MD West Hartford, CT
David Winsemius
2010-Jul-21 17:01 UTC
[R] [SPAM](Aktien) Re: Chi-square distribution probability density function:
On Jul 21, 2010, at 12:36 PM, Knut Krueger wrote:> David Winsemius schrieb: >> >> >> On Jul 21, 2010, at 6:52 AM, Knut Krueger wrote: >> >>> Hi to all I found >>> an formular of an ** >>> ***p-Value Calculator for the Chi-Square test* >>> *http://www.danielsoper.com/statcalc/calc11.aspx* >>> *with the formula* >>> <http://www.danielsoper.com/statkb/topic11.aspx> >>> *what's the gamma function of this formula in r?* >>> *df=5* >>> *ch2=25.50878* >>> *the following code does not give the result <0.001 for the >>> values above * >>> *p= ((0.5^(df/2))/gamma(df))*(ch2^((df/2)-1))* (2.718281828459^(- >>> ch2/2)) >>> or is there any other error? >> >> Check your implementation of that formula. You made an error in the >> gamma argument. >> > Sorry a copy and paste error but gamma(df/2) does not solve the > problem > I am not able to get the implementation of the function working :-( > >> See also: >> >> ?Chisquare >> ?gamma > > there is also a different result using this function from the helpf > files and the function > /f_n(x) = 1 / (2^(n/2) Gamma(n/2)) x^(n/2-1) e^(-x/2)That is (perhaps) because you are confusing a density function with a cumulative probability function. The expression above should give the same result as a (proper) R transcription of the formula on the page you offered above and should be what dchisq referenced on the ? Chisquare page returns as well. Sure enough... > dchisq(25.50878, 5) [1] 4.951e-05 > p= ((0.5^(df/2))/gamma(df/2))*(ch2^((df/2)-1))* (2.718281828459^(- ch2/2)) > p [1] 4.951e-05 Those formulae only differ in how they use grouping of the constant terms. (In R the function is gamma, not Gamma.) You should be able to get the P(X^2|x>25.508, df=5) from an integration of that function.> > Knut > > /David Winsemius, MD West Hartford, CT
Knut Krueger
2010-Jul-21 17:18 UTC
[R] Chi-square distribution probability density function:
David Winsemius schrieb:> > > And exactly why did you think I offered > > ?ChisquareI was completely on the wrong way, and tried to find a solution with the formula instead to substitute the formula. So I tried to implement pchisq into the formula - and of course I got wrong values ... Thank's Knut
David Winsemius
2010-Jul-21 17:26 UTC
[R] Chi-square distribution probability density function:
On Jul 21, 2010, at 1:18 PM, Knut Krueger wrote:> David Winsemius schrieb: >> >> >> And exactly why did you think I offered >> >> ?Chisquare > I was completely on the wrong way, and tried to find a solution with > the formula instead to substitute the formula. > > So I tried to implement pchisq into the formula - and of course I > got wrong values ...> p <- function(x) ((0.5^(5/2))/gamma(5/2))*(x^((5/2)-1))* (2.718281828459^(-x/2)) > integrate(p, 25.508, Inf) 0.0001111 with absolute error < 2.7e-05 Check result>>>> > pchisq(25.508,5) [1] 0.9999 > 1-pchisq(25.508,5) [1] 0.0001111> > Thank's KnutDavid Winsemius, MD West Hartford, CT