Last active
October 22, 2025 09:54
-
-
Save abikoushi/248459f017f2649298eea2757242bde6 to your computer and use it in GitHub Desktop.
Check probability function of a multivariate Fisher's noncentral hypergeometric distribution
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
| library(BiasedUrn) | |
| softmax <- function(x){ | |
| mx = max(x) | |
| ex = exp(x-mx) | |
| ex/sum(ex) | |
| } | |
| MVNCH_Fisher <- function(K,M,OR){ | |
| CB = combn(K,M) | |
| nr = ncol(CB) | |
| X = matrix(0, nr, K) | |
| for(i in 1:nr){ | |
| X[i, CB[,i]]=1 | |
| } | |
| prob = softmax(X%*%log(OR)) | |
| list(X=X, prob = prob) | |
| } | |
| K=10 | |
| set.seed(123); OR = rexp(K) | |
| M=3 | |
| dist_F = MVNCH_Fisher(K,M,OR) | |
| theo_F = numeric(nrow(dist_F$X)) | |
| for(i in 1:nrow(dist_F$X)){ | |
| theo_F[i] = dMFNCHypergeo(x = dist_F$X[i,], m = rep(1, K), n=M, odds = OR) | |
| } | |
| plot(dist_F$prob, theo_F) | |
| abline(0, 1, lty=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment