1 | function p = tdist(x,v) |
---|

2 | % TDIST - Calculates Student's cumulative distribution function. |
---|

3 | % |
---|

4 | % Synopsis: |
---|

5 | % p = tdist(X,V) |
---|

6 | % |
---|

7 | % Description: |
---|

8 | % Calculates Student's cumulative distribution function with V |
---|

9 | % degrees of freedom at the values in X. |
---|

10 | % |
---|

11 | % Examples: |
---|

12 | % |
---|

13 | % See also: |
---|

14 | % FMRI_ANALYSIS |
---|

15 | |
---|

16 | % This function is a part of Aedes - A graphical tool for analyzing |
---|

17 | % medical images |
---|

18 | % |
---|

19 | % Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi> |
---|

20 | % |
---|

21 | % Department of Physics, Department of Neurobiology |
---|

22 | % University of Kuopio, FINLAND |
---|

23 | % |
---|

24 | % This program may be used under the terms of the GNU General Public |
---|

25 | % License version 2.0 as published by the Free Software Foundation |
---|

26 | % and appearing in the file LICENSE.TXT included in the packaging of |
---|

27 | % this program. |
---|

28 | % |
---|

29 | % This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
---|

30 | % WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|

31 | |
---|

32 | if nargin < 2, |
---|

33 | error('Too few input arguments.'); |
---|

34 | end |
---|

35 | |
---|

36 | if numel(v)==1 |
---|

37 | v = ones(size(x),class(v)).*v; |
---|

38 | end |
---|

39 | |
---|

40 | % Initialize P. |
---|

41 | if isa(x,'single') || isa(v,'single') |
---|

42 | p = NaN(size(x),'single'); |
---|

43 | else |
---|

44 | p = NaN(size(x)); |
---|

45 | end |
---|

46 | |
---|

47 | nans = (isnan(x) | ~(0<v)); |
---|

48 | |
---|

49 | % Handle special cases of degrees of freedom |
---|

50 | ind = (v == 1); |
---|

51 | if any(ind(:)) |
---|

52 | p(ind) = 0.5+(1/pi).*atan(x); |
---|

53 | end |
---|

54 | ind = (v == 2); |
---|

55 | if any(ind(:)) |
---|

56 | p(ind) = 0.5*(1+x./sqrt(2+x.^2)); |
---|

57 | end |
---|

58 | |
---|

59 | ind = isnan(p); |
---|

60 | if any(ind(:)) |
---|

61 | % When degrees of freedom are other than 1 or 2, the cumulative |
---|

62 | % distribution function is calculated as an incomplete beta function |
---|

63 | p(ind) = betainc((x(ind)+sqrt(x(ind).^2+v(ind)))./(2*sqrt(x(ind).^2+v(ind))),v(ind)/2,v(ind)/2); |
---|

64 | end |
---|

65 | p(x == 0 & ~nans) = 0.5; |
---|