My question was inspired by this topic, but is a bit different: phyher() in R and Fisher exact test p-value
I try to understand how does it work?
The question is as follows:
knowing that 50 people out of 300 have got disease and that 100 out of those 300 are Women and assuming that Women and Men have the same same probability of having a disease:
What is the probability that those 50 persons will be so unevenly distributed between Women and Men (in both directions p-value)?
If we selected 50 people at random, what is the probability that 40 or more of of them would be in the group of 200 Men,
And only 10 or fewer in the group of 100 Women?
I tried so far:
df <- data.frame(Women = c(10,90), Men = c(40,160)) rownames(df) <- c("Diseased","Not_Diseased") df as.table(as.matrix(df)) mat = matrix(c(10, 90, 40, 160), nrow = 2, ncol = 2) stats::fisher.test(mat, alternative = "less") stats::fisher.test(mat, alternative = "two.sided") # What is the probability of getting 10 or fewer Women? phyper( q = 10, # the number of Women 'drawn' in the sample m = 100, # the total number of Women n = 200, # the total number of Men k = 50, # the number of people 'drawn' in the sample lower.tail = TRUE # to get the probability of 10 or fewer Women ) # What is the probability of getting 40 or more Men? phyper( q = 40, # the number of Men 'drawn' in the sample m = 200, # the total number of Men n = 100, # the total number of Women k = 50, # the number of people 'drawn' in the sample lower.tail = FALSE # to get the probability of 40 or more Men )
I have some difficulties with understanding lower.tail = TRUE - is it always <= x
and lower.tail=FALSE is it always > x?
Then I found "Visualize" package to help me to understand this with plots:
library(visualize) visualize.hyper(stat = 10, m = 100, n = 200, k = 50, section = "lower", strict = FALSE)
visualize.hyper(stat = 40, m = 200, n = 100, k = 50, section = "upper", strict = FALSE)
So I would like to know (all in all) why is that, these results are equal?
Shouldn't it be: 0.01355895 for 40 and more Men?
I mean: two-sided p-value Fisher exact test gives 0.03242455, one-sided p-value (for 10 or fewer Women) gives 0.0188656, then: 0.03242455 - 0.0188656 = 0.01355895
phyper(q = 40, m = 200, n = 100, k = 50, lower.tail = FALSE )
phyper(q = 39, m = 200, n = 100, k = 50, lower.tail = FALSE )
gives again 0.0188656