2
$\begingroup$

I am trying to use Mathematica to do some computations in Advanced Probability. I am quite new to Mathematica, so I need help in understanding the Convolve function. I used Mathematica 11 to compute the convolution of two independent geometric random variables with parameters p and q respectively, I don't seem to get a closed form expression for the convolution. Here is what I have attempted:

Convolve[PDF[GeometricDistribution[p], k], 
 PDF[GeometricDistribution[q], k], k - n, n]

The output is:

 Convolve[\[Piecewise]  (1-p)^k p   k>=0
0   True

,\[Piecewise]   (1-q)^k q   k>=0
0   True

,k-n,n].

I further tried to get the same result using the Transformed distribution as follows:

f[x_] = PDF[GeometricDistribution[p], k];
g[y_] = PDF[GeometricDistribution[q], k];
PDF[
 TransformedDistribution[
  x + y,
  {
   x \[Distributed] ProbabilityDistribution[f[x], {x, 0, k}], 
   y \[Distributed] ProbabilityDistribution[g[x], {y, 0, k}]
   }
  ], x
 ]

I got the output as :

\[Piecewise]    k (1-p)^k p (1-q)^k q   k>0&&2 k-x==0
(1-p)^k p (1-q)^k q (2 k-x) k>0&&k-x<0&&2 k-x>0
(1-p)^k p (1-q)^k q x   k>0&&x>0&&k-x>=0
0   True

I am new to Mathematica so could anyone help me understand what is happening with the two codes above?

$\endgroup$
2
  • $\begingroup$ The syntax is: Convolve[PDF[GeometricDistribution[p], k], PDF[GeometricDistribution[q], k], k, n] $\endgroup$ Nov 29 '21 at 12:18
  • $\begingroup$ @DanielHuber: This produces Piecewise[{{(p*((1 - p)^n - (1 - q)^n)*q)/ (Log[1 - p] - Log[1 - q]), n > 0}}, 0] . Summarizing it by n from 0 to Infinity. one obtains (-p + q)/(Log[1 - p] - Log[1 - q]) instead of 1. Also in the case p==q Convolve produces Piecewise[{{n*(1 - p)^n*p^2, n > 0}}, 0] instead of Piecewise[{{(1 + n)*(1 - p)^n*p^2, n >= 0}}, 0] (see Wiki). If I am not mistaken, it looks like a bug in Convolve. $\endgroup$
    – user64494
    Nov 29 '21 at 14:56
4
$\begingroup$

GeometricDistribution is a discrete distribution. Because of it, DiscreteConvolve should be applied:

DiscreteConvolve[PDF[GeometricDistribution[p], k],PDF[GeometricDistribution[q], k], k, n]

Piecewise[{{(p*q*(-(1 - p)^n + (1 - p)^n*p + (1 - q)^n - (1 - q)^n*q))/(p - q), n >= 0}}, 0]

To verify it

Sum[(p*q*(-(1 - p)^n + (1 - p)^n*p + (1 - q)^n - (1 - q)^n*q))/(p - 
q), {n, 0, Infinity}, Assumptions -> {p, q} > 0 && {p, q} < 1]

1

See the documentation for more info.

$\endgroup$
3
  • 1
    $\begingroup$ +1 Use FullSimplify to get a simpler form. For completeness you should also look at Limit[conv, p -> q] $\endgroup$
    – Bob Hanlon
    Nov 30 '21 at 2:40
  • $\begingroup$ @user64494: Thanks. DiscreteConvolve worked! I verified the sum too. Thanks a lot for all the answers received. Could you please recommend a book to learn programming in Mathematica, especially for concepts in advanced probability? $\endgroup$
    – Rosy
    Nov 30 '21 at 5:23
  • $\begingroup$ @Rosy: Thank you for good words. See the results of Google search "Probability with Mathematica" (The link is too long to be quoted here.). $\endgroup$
    – user64494
    Nov 30 '21 at 5:44

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