Assume that I have two discrete random variables $X$ and $Y$.

$X ∈ \{1,3,3,5,7,7,7,9,9,9,9,9\}$


$Y ∈ \{5,5,9,9,10,12,13\}$

Where their empirical CDFs are given as:

$F_x(1) = 0.0833, F_x(3) = 0.25, F_x(5) = 0.33, F_x(7) = 0.5833 and F_x(9) = 1 $


$F_y(5) = 0.2857, F_y(9) = 0.5714, F_y(10) = 0.7143, F_y(12) = 0.8571 and F_y(13) = 1 $

Assuming their joint distribution is

$H(x,y) = F_x(x)F_y(y)$

which is actually the "assumption" of $X$ and $Y$ are independent.

How can i calculate the $Z = X + Y$ and $F(z)$ in MATLAB ?

Note: I gave the $H(x,y)$ as a simple product function for the simplicity, but it can be anything in reality which actually models the dependency between $X$ and $Y$.

Edit 1: Ok, based on @gunes's answer. What i "actually" do is to calculate the distribution of Frechet Lower Bound of $Z$.

From the definition $H_l(u,v) = max(u + v - 1, 0)$ where $u = F_{x}(x)$ and $v = F_{y}(y)$ and $F_{x}$, $F_{y}$ corresponds to the CDFs of $X$ and $Y$.

Assuming $H(x,y) = H_l(u,v)$ where $x = F_{x}^{-1}(u)$ and $y = F_{y}^{-1}(v)$

So if I want to find $P(18)$, I can select ($9$ from $X$ and $9$ from $Y$) and ($5$ from $X$ and $13$ from $Y$).

So, $H(9,9) = max(F_{x}(9) + F_{y}(9) - 1, 0) = max(1 + 0.5714 - 1) = 0.5714$


$H(5,13) = max(F_{x}(5) + F_{y}(13) - 1, 0) = max(0.33 + 1 - 1) = 0.33$

So, if i understood correctly I now have $H(9,9)$ and $H(5,13)$, but what am i supposed to do with those values ?

I think in some point i misunderstood something, but what?


To be precise, you must be using $*$ sign for multiplication, and $H(x,y)$ is the joint CDF, i.e. $$H(x,y)=P(X\leq x, Y\leq y)=P(X\leq x)P(Y\leq y)=F_X(x)F_Y(y)$$ I just felt obliged to verify it since your title and keyword mention convolution, which is quite commonly shown with the operator $*$.

Apart from this, you've your empirical CDFs and therefore PMFs. The PMF of $Z=X+Y$ is the convolutions of the PMFs of $X$ and $Y$, when they're independent. This can be done via conv(fx,fy) command, where fx and fy are your empirical PMFs, i.e. fx = [0.0833,0,0.1667,0,0.0833, 0, ...], fy = [0,0,0,0,0.2857,...]. You can start fy from 5 and then append four 0 in the end, it doesn't matter. You just need to respect the indices. After you've found the PMF, it's just cumsum operation to reach the CDF.

For the dependent case, all you need is the joint distribution, and we can't use convolution any more. You've have a table of values for $H(x,y)$, which actually means $P(X\leq x, Y\leq y)$. A straightforward method would be first obtaining the joint PMF by differencing the joint CDF, because in the end, we'll need the probability $P(X+Y\leq z)$. If we had the joint PMF, we'd obtain joint CDF by cumsuming in each coordinate direction which means we need to take difference in each direction to get the joint PMF.

When you have the joint PMF, the coding depends on how you constructed your table (i.e. matrix). If you've one entry for each integer, then $X+Y=Z$ corresponds to sweeping an oblique line throughout your matrix, and summing the probability masses below the line for each possible $z\in [\min (X)+\min (Y), \max (X)+\max (Y)]$.

Alternative: w/o going back to joint PMF, it seems like we can calculate (assuming integer steps) $$P(X+Y\leq z)=\sum_{x+y=z} H(x,y)-\sum_{x+y=z-1} H(x,y)$$ Think about a simple $3\times 3$ joint PMF matrix, and the values of $x,y\in \{0,1,2\}.$ $P(X+Y\leq 2)$ is actually the sum of the joint PMF values at coordinates $(0,0),(0,1),(1,0),(0,2),(2,0)$, i.e. below (and including) the diagonal, $x+y=2$. The summation of $H(1,1), H(0,2), H(2,0)$ includes the squares in $x+y=2$ once, $x+y=1$ twice and $x+y=0$ three times. Similarly, the summation of $H(1,0)$ and $H(0,1)$ includes the squares $(0,1),(1,0)$ once and $(0,0)$ twice. When we subtract the latter from the first we'll obtain a sum where each square in joint PMF is represented exactly once in the summation.

  • $\begingroup$ Thank you very much. This has clarified a lot for me. For the "*" sign, you are right i used that on the purpose of multiplication operation. I have one more thing that i do not understand. Consider that X and Y are dependent and I want to find F_z(18). Both H(5, 13) and H(9,9) gives the Z=18. What i did not understand is that what am i supposed to do with H(5,13) and H(9,9) based on my example, do i need to sum the results of H(9,9) and H(5,13) which i think its not true. Assume that H(x,y) = F_x(x) + F_y(y) in this case. $\endgroup$ – Levent Bekdemir May 17 '19 at 7:37
  • $\begingroup$ $H(x,y)$ is the area under the rectangle $X\leq x$, $Y\leq y$; but we actually need $X+Y\leq z$. So, a straightforward way to compute it is to go back to joint PMF and calculate the area/probability mass under the sweeping line. $\endgroup$ – gunes May 17 '19 at 7:50
  • $\begingroup$ @LeventBekdemir I've also added an alternative approach using the CDF directly. $\endgroup$ – gunes May 17 '19 at 8:08
  • $\begingroup$ thanks i edited my question and added my "real" purpose if you can help i would be very appreaciated $\endgroup$ – Levent Bekdemir May 17 '19 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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