1 |
{ RCSid $Id: normcomp.cal,v 1.4 2021/09/12 17:04:41 greg Exp $ } |
2 |
{ |
3 |
Compute overlap between two normal distribution functions, |
4 |
defined by mean1, mean2, stdev1 and stdev2. |
5 |
|
6 |
2/10/95 Greg Ward |
7 |
|
8 |
relies on gauss.cal and norm.cal |
9 |
} |
10 |
|
11 |
Z1(u) = Z((u - mean1)/stdev1) / stdev1; |
12 |
Z2(u) = Z((u - mean2)/stdev2) / stdev2; |
13 |
|
14 |
f(u) = min(Z1(u),Z2(u)); |
15 |
|
16 |
xmin = min(mean1-3*stdev1, mean2-3*stdev2); |
17 |
xmax = max(mean1+3*stdev1, mean2+3*stdev2); |
18 |
|
19 |
{ |
20 |
Following is an alternative calculation that doesn't |
21 |
require numerical integration, nor gauss.cal nor norm.cal |
22 |
|
23 |
(ref: stats.stackexchange.com/questions/103800 – wolfies Dec 24 '16 at 14:40) |
24 |
} |
25 |
|
26 |
abs(x) : if(x, x, -x); |
27 |
|
28 |
Finteg(c, m, s) : 0.5*erf((c-m)/(sqrt(2)*s)); |
29 |
|
30 |
m1 = mean1; m2 = mean2; |
31 |
s1 = stdev1; s2 = stdev2; |
32 |
|
33 |
den = s1*s1 - s2*s2; |
34 |
c0 = (m2*s1*s1 - m1*s2*s2)/den; |
35 |
cr = s1*s2*sqrt((m1-m2)*(m1-m2) + 2*den*log(s1/s2))/den; |
36 |
|
37 |
NormOverlap = if(1e-7 - abs(s1-s2), erfc(abs(m1-m2)/(s1+s2)/sqrt(2)), |
38 |
1 - Finteg(c0-cr,m1,s1) + Finteg(c0-cr,m2,s2) |
39 |
+ Finteg(c0+cr,m1,s1) - Finteg(c0+cr,m2,s2) ); |