Hello,

I am interested in the convolution of random independent discrete variables (and in particular uniform discrete random variables). Is there an efficient way of constructing this ? Or should I just write my own convolution function ?

Hello,

I am interested in the convolution of random independent discrete variables (and in particular uniform discrete random variables). Is there an efficient way of constructing this ? Or should I just write my own convolution function ?

Well, the probability mass function would be nice. But to be precise I want to construct a distribution which is the sum of n independant DiscreteUniform over {1,…,k}. This is thus a Categorical distribution over {n, n+1, …, nk}. I can write the convolution by myself, but was wondering if I missed a function allowing to construct a new discrete random variable as the sum of two (independent) random variables.

Oh, and I thought I had specified it in the tags, but I am using Distributions.jl

But the question is what you want to do with that? E.g. if you just want to sample from it, you don’t have to construct it at all:

```
julia> mysample(k, N) = sum(rand(1:k) for i in 1:N)
mysample (generic function with 1 method)
julia> mysample(5, 10)
36
julia> mysample(5, 10)
23
julia> mysample(5, 10)
35
```

But I agree that conceptually it would be nice to be able to write `Z = X + Y`

for random variables `X`

and `Y`

.

I want to have it as a Distribution object, to be able to do stuff with it

Simple example in mind : finding the probability that rolling 100 6-faced dices give less than 50 12-faced dices.

I am actually cooking up hands on session around the CLT and its limits, and I hoped that a `Z = X + Y`

method would exist instead of having to code it by myself.

There’s packages like Turing but I think it only support sampling (which is the preferred method when models become complicated), and I’m not sure it actually supports adding random variables.

Usually I just write down the convolution by hand, something like:

```
a = Distributions.DiscreteUniform(0,10)
b = Distributions.DiscreteUniform(0,10)
mydensity(a,b,x) = sum(pdf(a,x-k)*pdf(b,k) for k=0:10)
plot(y=mydensity.(0:20),Geom.line)
```

But that’s probably not ideal.

I don’t see how having it as a Distributions object will help you to do that calculation?