1

I need to sample a variable from a distribution that's like a binomial distribution except with a "bias", I'm not sure what it may be called: $p(X=k)$ is proportional to $k.B(n,p)(k)$ where $B(n,p)$ is the binomial distribution.

Any ideas on how this can be done?

I'm working in python so if there's any "direct" way in numpy or other packages that would be extra useful...

alan
  • 83
  • 4
  • 2
    So you're saying the PDF is $k\binom{a}{b}p^k(1-p)^{n-k}$ instead of the usual $\binom{a}{b}p^k(1-p)^{n-k}$? Does that still sum to one over positive integers? Also, if you know the analytical form of the distribution, you might find an answer in this question from a year ago: http://stats.stackexchange.com/q/67911/36229 – shadowtalker Sep 03 '14 at 22:38
  • @ssdecontrol the question says "is proportional to" so I think the OP understands that $\binom{n}{k}kp^k(1-p)^{n-k}$ isn't normalized. – Glen_b Sep 04 '14 at 03:07
  • @Glen_b I wasn't sure if the OP meant that $B(n,p)$ was the proportional factor. – shadowtalker Sep 04 '14 at 03:27

1 Answers1

5

Since the expectation of a binomial is straightforward:

$$\sum_{k=0}^n\binom{n}{k}kp^k(1-p)^{n-k}=np$$

we have that $P(X=k)$ can be written in closed form:

$$\binom{n}{k} \frac{k}{np} p^{k}(1-p)^{n-k}\,,$$

$$=\binom{n-1}{k-1}p^{k-1}(1-p)^{n-1-(k-1)}\,.$$

This is just a shifted binomial.

Sampling from a binomial$(n-1,p)$ and shifting it up by 1 would seem to solve the problem.


Here's an example, by way of a check on the algebra:

n=10;p=.4
dbinom(0:(n-1),n-1,p)/dbinom(1:n,n,p)
 [1] 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50

Yep, that increases linearly (in fact, it is $\frac{k}{np}$ as it ought to be).

Glen_b
  • 257,508
  • 32
  • 553
  • 939