Quantcast

hypergeometric vs fisher.test

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

hypergeometric vs fisher.test

Andrea Franceschini
Dear R team,
I have a simple question.

I tried this command:
phyper(17,449,19551,181, FALSE)
[1] 1.47295e-07

and then I tried this command:
(fisher.test(matrix(c(17,449,181,19551),2,2), alternative='greater'))$p.value
[1] 3.693347e-06


Shouldn't be identical the results of the two commands ?
What is the difference ?

Thx a lot
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: hypergeometric vs fisher.test

Peter Dalgaard-2

On Aug 13, 2010, at 3:47 PM, Andrea Franceschini wrote:

>
> Dear R team,
> I have a simple question.
>
> I tried this command:
> phyper(17,449,19551,181, FALSE)
> [1] 1.47295e-07
>
> and then I tried this command:
> (fisher.test(matrix(c(17,449,181,19551),2,2),
> alternative='greater'))$p.value
> [1] 3.693347e-06
>
>
> Shouldn't be identical the results of the two commands ?
> What is the difference ?

Just read the phyper docs more carefully (and perhaps revisit the theory), and you'll see that phyper is using margin totals of the table, where fisher.test is using the individual entries. Also beware of left/right continuity issues with tails of discrete distributions: The convention is that the lower and the upper tail sums to 1, so your "17" is NOT included in the upper tail.

>
> Thx a lot
> --
> View this message in context: http://r.789695.n4.nabble.com/hypergeometric-vs-fisher-test-tp2324223p2324223.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: hypergeometric vs fisher.test

Andrea Franceschini
I ask the question also because I found this line in Wikipedia:
"The test (see above) based on the hypergeometric distribution
(hypergeometric test) is identical to the corresponding one-tailed
version of Fisher's exact test".

Is this wrong ?  May I kindly ask a friendly explanation for
not-experts in statistics ?

Thx a lot,
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: hypergeometric vs fisher.test

Peter Dalgaard-2
Andrea Franceschini wrote:

> I ask the question also because I found this line in Wikipedia:
> "The test (see above) based on the hypergeometric distribution
> (hypergeometric test) is identical to the corresponding one-tailed
> version of Fisher's exact test".
>
> Is this wrong ?  May I kindly ask a friendly explanation for
> not-experts in statistics ?
>
> Thx a lot,
>

You never said you were a non-expert. A question like that might very
well have come from a student, or an incompetent claiming to have found
a bug in fisher.test...

The point was that Fisher's test takes the 2x2 table

a b
c d

and interprets the situation under the null hypothesis as taking a
sample of size a+c from an urn with a+b white balls and c+d black balls.

Once you read the docs for phyper properly (it _is_ tricky to get it
right), you arrive at

> phyper(16,17+181,449+19551,17+449, lower.tail=FALSE)
[1] 3.693347e-06


--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: hypergeometric vs fisher.test

TGS-3
"or an incompetent"

Such harsh words Peter. You're not making this a friendly environment for people to ask questions. Is there a less competent attribute mailing list so that some of us don't offend you with our questions?

On Aug 13, 2010, at 2:11 PM, Peter Dalgaard wrote:

Andrea Franceschini wrote:

> I ask the question also because I found this line in Wikipedia:
> "The test (see above) based on the hypergeometric distribution
> (hypergeometric test) is identical to the corresponding one-tailed
> version of Fisher's exact test".
>
> Is this wrong ?  May I kindly ask a friendly explanation for
> not-experts in statistics ?
>
> Thx a lot,
>

You never said you were a non-expert. A question like that might very
well have come from a student, or an incompetent claiming to have found
a bug in fisher.test...

The point was that Fisher's test takes the 2x2 table

a b
c d

and interprets the situation under the null hypothesis as taking a
sample of size a+c from an urn with a+b white balls and c+d black balls.

Once you read the docs for phyper properly (it _is_ tricky to get it
right), you arrive at

> phyper(16,17+181,449+19551,17+449, lower.tail=FALSE)
[1] 3.693347e-06


--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...