Let's $X_1, X_2, ..., X_n$, $n=1,2,...$ are independent discrete random variables.
It is necessary to find the distribution law of the their sum:
$p(k) =P(X_1 + X_2 + ... + X_n = k), k=0, 1, 2, ... $
I solved the problem case $n=3$ when random variables take the same values $x=\{0,1,2\}$ and probabilities $p =\{0.85, 0.1, 0.05\}$ using the convolution twice.
x <- x0 <- c(0:2) # value's of random variable
p <- p0 <- c(0.85, 0.1, 0.05) # probabilities
n = 2
for(i in 1:n){
p1 <- outer(p0, p)
d1 <- outer(x0, x, +)
z1 <- tapply(p1, d1, sum)
p <- z1
x <- as.integer(names(z1))
}
z1
0 1 2 3 4 5 6
0.614125 0.216750 0.133875 0.026500 0.007875 0.000750 0.000125
Question. I am looking for a function/packages for obtaining the density of a sum of independent discret random variables.
Rasfft. Look also at theconvolvefunction. See, inter alia, https://stats.stackexchange.com/questions/41251, https://stats.stackexchange.com/questions/41247, https://stats.stackexchange.com/questions/191193, and https://stats.stackexchange.com/questions/5347. – whuber Mar 25 '22 at 14:43