Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created October 20, 2025 08:24
Show Gist options
  • Select an option

  • Save abikoushi/47af420c6f072ce5dffb8e5efd56dd9b to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/47af420c6f072ce5dffb8e5efd56dd9b to your computer and use it in GitHub Desktop.
Try multivariate noncentral hypergeometric distribution in BiasedUrn package
library(BiasedUrn)
library(dplyr)
K=10
set.seed(1234); OR = rexp(K)
ressim = sample.int(K, size = 10000, prob = OR, replace = TRUE) |>
table() |>
as.data.frame()
ressim = mutate(ressim, prob = Freq/sum(Freq))
theo_F = numeric(nrow(ressim))
theo_W = numeric(nrow(ressim))
#i=1
for(i in 1:nrow(ressim)){
x = numeric(K)
x[ressim$Var1[i]] = 1
theo_F[i] = dMFNCHypergeo(x = x, m = rep(1, K), n=1, odds = OR)
theo_W[i] = dMWNCHypergeo(x = x, m = rep(1, K), n=1, odds = OR)
}
plot(theo_F, theo_W)
abline(0,1,lty=2)
plot(ressim$prob, theo_F)
abline(0,1,lty=2)
plot(ressim$prob, theo_W)
abline(0,1,lty=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment