time | Calls | line |
---|
| | 1 | function bd0 = binodeviance(x,np)
|
| | 2 | %BINODEVIANCE Deviance term for binomial and Poisson probability calculation.
|
| | 3 | % BD0=BINODEVIANCE(X,NP) calculates the deviance as defined in equation
|
| | 4 | % 5.2 in C. Loader, "Fast and Accurate Calculations of Binomial
|
| | 5 | % Probabilities", July 9, 2000. X and NP must be of the same size.
|
| | 6 | %
|
| | 7 | % For "x/np" not close to 1:
|
| | 8 | % bd0(x,np) = np*f(x/np) where f(e)=e*log(e)+1-e
|
| | 9 | % For "x/np" close to 1:
|
| | 10 | % The function is calculated using the formula in Equation 5.2.
|
| | 11 |
|
| | 12 | % Copyright 2010-2014 The MathWorks, Inc.
|
| | 13 |
|
| | 14 |
|
0.002 | 8 | 15 | bd0=zeros(size(x),'like',internal.stats.dominantType(x,np));
|
| | 16 |
|
| | 17 | % If "x/np" is close to 1:
|
< 0.001 | 8 | 18 | k = abs(x-np)<0.1*(x+np);
|
< 0.001 | 8 | 19 | if any(k(:))
|
0.001 | 8 | 20 | s = (x(k)-np(k)).*(x(k)-np(k))./(x(k)+np(k));
|
< 0.001 | 8 | 21 | v = (x(k)-np(k))./(x(k)+np(k));
|
< 0.001 | 8 | 22 | ej = 2.*x(k).*v;
|
< 0.001 | 8 | 23 | s1 = zeros(size(s),'like',s);
|
< 0.001 | 8 | 24 | ok = true(size(s));
|
< 0.001 | 8 | 25 | j = 0;
|
< 0.001 | 8 | 26 | while any(ok(:))
|
< 0.001 | 60 | 27 | ej(ok) = ej(ok).*v(ok).*v(ok);
|
< 0.001 | 60 | 28 | j = j+1;
|
< 0.001 | 60 | 29 | s1(ok) = s(ok) + ej(ok)./(2*j+1);
|
< 0.001 | 60 | 30 | ok = ok & s1~=s;
|
< 0.001 | 60 | 31 | s(ok) = s1(ok);
|
< 0.001 | 60 | 32 | end
|
< 0.001 | 8 | 33 | bd0(k) = s;
|
< 0.001 | 8 | 34 | end
|
| | 35 |
|
| | 36 | % If "x/np" is not close to 1:
|
< 0.001 | 8 | 37 | k = ~k;
|
< 0.001 | 8 | 38 | if any(k(:))
|
0.001 | 8 | 39 | bd0(k)= x(k).*log(x(k)./np(k))+np(k)-x(k);
|
< 0.001 | 8 | 40 | end
|
| | 41 |
|
< 0.001 | 8 | 42 | end
|
Other subfunctions in this file are not included in this listing.