3
$\begingroup$

Consider $X=Y_{1}+\cdots+Y_{n}$, where $Y_{1}, \cdots, Y_{n}$ are $\mathrm{n}$ independent Bernoulli random variables with $Y_i\sim Bernoulli (1,p_i)$, $i=1,2,\cdots,n$. Then $X$ has a so-called Poisson-binomial distribution of parameters $p_{1}, \cdots, p_{n}$ and $n$.

Suppose $n=20$ and $p_i=0.5+i/50$, $i=1,2,\cdots,20$. How to compute the conditional probability of $P(X=i |X\le 5)$, $i=1,2,3,4,5$, by formula derivation or software simulation (R or Python) ?

So far, I try my best to have the following results. $$ P \triangleq P(X=i |X\le 5) = \frac{P(X=i,X\le5)}{P(X\le 5)} \overset{i=1,\cdots,5}{=} \frac{P(X=i)}{P(X\le 5)} $$ Then I resort to the library(poisbinom) package in R to compute the conditional probability P

# 20 Bernouilli r.v.s
n = 20; ii = 1:n; pp = 0.5 + ii/50
library(poisbinom)
numerator = dpoisbinom(1:5, pp) #P(X=i), i=1,2,3,4,5
denominator = ppoisbinom(5, pp) #P(X<=5)
p5 = numerator/denominator
round(p5,5)
# [1] 0.00001 0.00040 0.00742 0.09509 0.89707

However, I am not sure whether my results are correct. Further, is there any other ways [formula derivation or software simulation (R or Python)] to calculate the above conditional probability?

$\endgroup$
0

1 Answer 1

3
$\begingroup$

Is there a reason you did not mention the small possibility $X=0$?

That being said, your rounded numbers look correct. Here is a recursion producing the same results (including $0$, which has a conditional probability about $0.000000207$)

maxi <- 20
limitn <- 5
bernprob <- function(n){ 1/2 + n/50 }
probmat <- matrix(0, nrow=maxi+1, ncol=maxi+1)    # offset to include 0
probmat[1,1] <- 1
for (i in 1:maxi){
  probmat[i+1,] <-  (c(probmat[i,], 0) * (1-bernprob(i)) + 
                     c(0, probmat[i,]) * bernprob(i)    )[-(maxi+2)]
  }   
condprob <- probmat[maxi+1, 1:(limitn+1)] / sum(probmat[maxi+1, 1:(limitn+1)])
names(condprob) <- 0:limitn
condprob  

#            0            1            2            3            4            5 
# 2.070919e-07 1.338460e-05 4.012590e-04 7.423162e-03 9.509096e-02 8.970710e-01
$\endgroup$
1
  • $\begingroup$ As you pointed out, $X=0$ indeed has a small probability, while it just takes 1:5 into account. Very appreciated your recursion procedures and correct confirmation! @Henry $\endgroup$
    – John Stone
    Aug 21, 2022 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.