Re: [R] hypergeometric vs fisher.test

2010-08-13 Thread peter dalgaard

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.
 
 __
 R-help@r-project.org 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: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org 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.


Re: [R] hypergeometric vs fisher.test

2010-08-13 Thread 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,

-- 
View this message in context: 
http://r.789695.n4.nabble.com/hypergeometric-vs-fisher-test-tp2324223p2324429.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] hypergeometric vs fisher.test

2010-08-13 Thread Peter Dalgaard
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: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org 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.


Re: [R] hypergeometric vs fisher.test

2010-08-13 Thread TGS
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: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.