Modeling balls in silos for R

I would like to simulate a distribution for a fixed number of balls min a fixed number of boxes nin R. So far I have used the Poisson approximation with rpois(). This is a decent approximation for a large number of balls in the bays n.

However, rpois()it allows you to specify a speed lambdathat is equal to m/n. As a result, the number of positive bins is often less than the number of balls.

Does anyone know of a function or script that allows me to randomly distribute balls into cells?

Ultimately, I try to calculate confidence intervals -log(empty bins/total bins)by bootstrap. This problem is “breaking my balls,” so to speak.

+4
source share
1 answer

I think you need a polynomial distribution.

Here's a quick function - we take m balls in n bins and give x results, returning the vector of your metric for each of x trials:

myfunc <- function(m,n,x){
  out <- rmultinom(x,m,rep(1,n))
  -log(colSums(out == 0)/n)
}

myfunc(10,40,10)
[1] 0.1923719 0.2548922 0.2231436 0.2548922 0.2876821 0.2876821 0.2231436 0.2231436 0.2231436 0.2548922

Then you can get quantiles / confidence intervals:

out = myfunc(10,40,1000)
quantile(out, c(0.05,0.95))
       5%       95% 
0.1923719 0.2876821 
+2
source

Source: https://habr.com/ru/post/1683178/


All Articles