Difference of two random variable distributions I have two sets of random variables. I have generated two CDFs for them. Two of the CDFs are plotted graphically. I need to find the difference in distribution of the two CDFs. 
I have learned about the method called convolution of distributions, which gives the distribution of the sums. If we add the negation of one distribution to be subtracted, we get the difference of distribution (like, A - B = A + (-B) ) which is what I needed.
Could anyone suggest me some software tools like scipy in python, which I can use for finding a solution to my problem?
 A: Are the two random variables $X$ and $Y$ supposed to be independent? If so, it is easy to prove that the distribution function of $Z=X-Y$ is given by the convolution
$$
  F_Z(z) = P(X-Y\leq z) = \int F_X(z+y) \, dF_Y(y) \, .
$$
Hence, one idea is to compute the empirical distribution functions $\hat{F}_m$ of $(x_1,\dots,x_m)$, and $\hat{G}_n$ of $(y_1,\dots,y_n)$, and use
$$
  \hat{H}(z) = \int \hat{F}_m(z+y)\,d\hat{G}_n(y) = \frac{1}{m\,n}\sum_{i=1}^n \sum_{j=1}^m I_{[x_j,\infty)}(z + y_i)
$$
as an estimate for $F_Z(z)$. Note that the corresponding estimator is strongly consistent for each $z$.
A: I don't think you need a special package to do this; ordinary numpy is enough.  I've appended example code and its output below.  Note that the cdf of (A-B) looks very similar to the cdfs of A and B separately, but actually it's not.  You can see a subtle difference at around +/- 2 or 3 sigma.  The cdf of (A-B) is a little wider than the individual cdfs of A and B separately.

import numpy as np
import matplotlib.pyplot as plt

#!/usr/bin/env python

# Number of random draws to use
ndraws = 1000
# Set this distance (in sigmas) large enough to capture all of the outliers
plotrange = 5
# Number of bins to use for pdf/cdf
nbin = 100
# Get random draws from a Gaussian
A = np.random.randn(1,ndraws)
B = np.random.randn(1,ndraws)
dfAB = A - B

# Calculate cdfs of A and B
Apdf, edges = np.histogram(A, bins=nbin, range=(-plotrange, plotrange))
Bpdf, edges = np.histogram(B, bins=nbin, range=(-plotrange, plotrange))
dfABpdf, edges = np.histogram(dfAB, bins=nbin, range=(-plotrange, plotrange))
xrng = (edges[0:-1] + edges[1:]) / 2

Acdf = np.cumsum(map(float, Apdf)) / ndraws
Bcdf = np.cumsum(map(float, Bpdf)) / ndraws
dfABcdf = np.cumsum(map(float,dfABpdf)) / ndraws

# Plot cdfs and differences of cdfs
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax1.plot(xrng, Acdf)
ax1.set_title("A cdf")

ax2 = fig.add_subplot(2,2,2)
ax2.plot(xrng, Bcdf)
ax2.set_title("B cdf")

ax3 = fig.add_subplot(2,2,3)
ax3.plot(xrng, dfABcdf)
ax3.set_title("(A-B) cdf")

ax4 = fig.add_subplot(2,2,4)
ax4.plot(xrng, Acdf - Bcdf)
ax4.set_title("(A cdf) - (B cdf)")

plt.show()

