How to integrate the difference between the CDFs of two normal distributions

1.3k Views Asked by At

I have two normal distributions A and B. I am trying to write a program that will take mean(A), stddev(A), mean(B), stddev(B) and output the result of the following equation: $$ \int_{-\infty}^{\infty} CDF_A(x) - CDF_B(x)\,dx $$ Is there some closed-form equation to calculate this? If not, is there a nice way to break it down to get a good approximation?

I could just iterate over some range of x values and sum up the differences over a small delta around x, but I'd prefer a non linear time solution.

3

There are 3 best solutions below

2
On

If I got your question correctly, you need to derive $W=X_1-X_2$ and then find $P(W<0$. See also here

2
On

To find what you are looking for (as you say in your comments), look at the answers to this question.

1
On

First you should know that for normal random variables : $$ CDF(x) = \frac12 (1+erf(\frac{x-\mu}{\sqrt{2\sigma^2}})) $$ where $$ erf(x)= \frac2{\sqrt \pi} \int_0^xe^{-t^2}dt $$ Therefore: $$\large {I= \int_{-\infty}^{+\infty}CDF_A(x)-CDF_B(x)dx =\frac1{\sqrt \pi} \int_{-\infty}^{+\infty} \int_{\frac{x-\mu_B}{\sqrt{2\sigma_B^2}}}^{\frac{x-\mu_A}{\sqrt{2\sigma_B^2}}} e^{-t^2}dt dx} $$ After changing variables we would have : $$I = \mu_B - \mu_A $$