Created
July 8, 2024 15:48
-
-
Save abikoushi/3422e7c424c15275312e895d74768712 to your computer and use it in GitHub Desktop.
p-values of fisher exact test (and likelihood)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions | |
using Plots | |
function Fishertest(X, phi) | |
cs = sum(X, dims=1) | |
rs = sum(X, dims=2) | |
f(x, phi) = pdf(FisherNoncentralHypergeometric(cs[1],cs[2],rs[1], exp(phi)), x) | |
prob = f.(0:cs[1], phi) | |
return sum(prob[prob .<= prob[X[1,1]+1]]) | |
end | |
X = [12 6; 5 12] | |
pfun(phi) = Fishertest(X, phi) | |
plot(x->pfun(x), label="p-value") | |
cs = sum(X, dims=1) | |
rs = sum(X, dims=2) | |
f(phi) = pdf(FisherNoncentralHypergeometric(cs[1],cs[2],rs[1], exp(phi)),X[1,1]) | |
plot!(x->f(x), label="likelihood") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment