# Weighted sum of Bernoulli distributions

Suppose $$X_i \sim \text{Bernoulli }(p)$$ What can be said about the distribution of $$Y$$, given by $$Y = \sum_{i=1}^N w_i X_i$$ for non-negative weights $$w_i$$? Note that $$N$$ here is small, so that no form of the CLT may be applied. I know, from this question, that this is a Poisson Binomial distribution if $$w_i=1$$, $$\forall i$$, but my question differs in the fact that I'm taking the same probability $$p$$ for all $$i$$.

• You mention "Poisson Binomial". Is $N$ given, or is it a random variable? Mar 29, 2022 at 14:50
• @Henry $N$ is given. Mar 29, 2022 at 14:51
• For small $N$, say up to $20$, and knowing $p$ and the $w_i$, and that the $X_i$ are independent, it would be easy enough to calculate the exact distribution Mar 29, 2022 at 14:55
– whuber
Mar 30, 2022 at 15:38
• If you post the same question simultaneously on multiple forums, it's good form to mention that in the question. Otherwise, if the answer or instructive comments on one forum aren't known on the other forum, you'll be wasting the time of the experts from which you're asking for help: math.stackexchange.com/questions/4415458/….
– JimB
Mar 30, 2022 at 16:54

n = 4;

t = Tuples[{0, 1}, {n}]
(* {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 0, 0},
{0, 1, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1}, {1, 0, 0, 0}, {1, 0, 0, 1},
{1, 0, 1, 0}, {1, 0, 1, 1}, {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0},
{1, 1, 1, 1}} *)

ss = Table[w[i], {i, n}] . # & /@ t
(* {0, w[4], w[3], w[3] + w[4], w[2], w[2] + w[4], w[2] + w[3],
w[2] + w[3] + w[4], w[1], w[1] + w[4], w[1] + w[3],
w[1] + w[3] + w[4], w[1] + w[2], w[1] + w[2] + w[4],
w[1] + w[2] + w[3], w[1] + w[2] + w[3] + w[4]} *)

prob = p^Total[#] (1 - p)^(n - Total[#]) & /@ t
(* {(1 - p)^4, (1 - p)^3 p, (1 - p)^3 p, (1 - p)^2 p^2, (1 - p)^3 p, (1 - p)^2 p^2,
(1 - p)^2 p^2, (1 - p) p^3, (1 - p)^3 p, (1 - p)^2 p^2, (1 - p)^2 p^2,
(1 - p) p^3, (1 - p)^2 p^2, (1 - p) p^3, (1 - p) p^3, p^4} *)

pmf = Transpose[{ss, prob}];
TableForm[pmf, TableHeadings -> {None, {"Y", "Probability"}}]


If the values of $$Y$$ are not all unique (i.e., w[3]+w[4] == w[1]+w[2] for example), then you'd want to "condense" the above table. Suppose w[i] = i:

TableForm[
Sort[{#[[1, 1]], Total[#[[All, 2]]]} & /@ GatherBy[pmf /. w[i_] -> i, First] //
Simplify, #1[[1]] < #2[[1]] &],


An alternative approach with known weights:

n = 4;

dist = TransformedDistribution[Sum[w[i] x[i], {i, n}],
Table[x[i] \[Distributed] BernoulliDistribution[p], {i, n}],
Assumptions -> 0 < p < 1];

Table[{k, PDF[dist /. w[i_] -> i, k] // Simplify}, {k, 0, n (n + 1)/2}]
(* {{0, (-1 + p)^4}, {1, -(-1 + p)^3 p}, {2, -(-1 + p)^3 p}, {3, (-1 + p)^2 p},
{4, (-1 + p)^2 p}, {5, 2 (-1 + p)^2 p^2}, {6, -((-1 + p) p^2)},
{7, -((-1 + p) p^2)}, {8, -((-1 + p) p^3)}, {9, -((-1 + p) p^3)}, {10, p^4}} *)


This last approach is much, much slower.