spm_ECdensity.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function [EC] = spm_ECdensity(STAT,t,df)
  2. % Returns the Euler characteristic (EC) density
  3. % FORMAT function [EC] = spm_ECdensity(STAT,t,df)
  4. %__________________________________________________________________________
  5. %
  6. % Reference : Worsley KJ et al (1996), Hum Brain Mapp. 4:58-73
  7. %__________________________________________________________________________
  8. % Copyright (C) 1999-2013 Wellcome Trust Centre for Neuroimaging
  9. % Karl Friston
  10. % $Id: spm_ECdensity.m 5544 2013-06-12 11:01:49Z guillaume $
  11. % EC densities
  12. %--------------------------------------------------------------------------
  13. t = t(:)';
  14. if STAT == 'Z'
  15. % Gaussian Field
  16. %----------------------------------------------------------------------
  17. a = 4*log(2);
  18. b = exp(-t.^2/2);
  19. EC(1,:) = 1 - spm_Ncdf(t);
  20. EC(2,:) = a^(1/2)/(2*pi)*b;
  21. EC(3,:) = a/((2*pi)^(3/2))*b.*t;
  22. EC(4,:) = a^(3/2)/((2*pi)^2)*b.*(t.^2 - 1);
  23. elseif STAT == 'T'
  24. % T - Field
  25. %----------------------------------------------------------------------
  26. v = df(2);
  27. a = 4*log(2);
  28. b = exp(gammaln((v+1)/2) - gammaln(v/2));
  29. c = (1+t.^2/v).^((1-v)/2);
  30. EC(1,:) = 1 - spm_Tcdf(t,v);
  31. EC(2,:) = a^(1/2)/(2*pi)*c;
  32. EC(3,:) = a/((2*pi)^(3/2))*c.*t/((v/2)^(1/2))*b;
  33. EC(4,:) = a^(3/2)/((2*pi)^2)*c.*((v-1)*(t.^2)/v - 1);
  34. elseif STAT == 'X'
  35. % X - Field
  36. %----------------------------------------------------------------------
  37. v = df(2);
  38. a = (4*log(2))/(2*pi);
  39. b = t.^(1/2*(v - 1)).*exp(-t/2-gammaln(v/2))/2^((v-2)/2);
  40. EC(1,:) = 1 - spm_Xcdf(t,v);
  41. EC(2,:) = a^(1/2)*b;
  42. EC(3,:) = a*b.*(t-(v-1));
  43. EC(4,:) = a^(3/2)*b.*(t.^2-(2*v-1)*t+(v-1)*(v-2));
  44. elseif STAT == 'F'
  45. % F Field
  46. %----------------------------------------------------------------------
  47. k = df(1);
  48. v = df(2);
  49. a = (4*log(2))/(2*pi);
  50. b = gammaln(v/2) + gammaln(k/2);
  51. EC(1,:) = 1 - spm_Fcdf(t,df);
  52. EC(2,:) = a^(1/2)*exp(gammaln((v+k-1)/2)-b)*2^(1/2)...
  53. *(k*t/v).^(1/2*(k-1)).*(1+k*t/v).^(-1/2*(v+k-2));
  54. EC(3,:) = a*exp(gammaln((v+k-2)/2)-b)*(k*t/v).^(1/2*(k-2))...
  55. .*(1+k*t/v).^(-1/2*(v+k-2)).*((v-1)*k*t/v-(k-1));
  56. EC(4,:) = a^(3/2)*exp(gammaln((v+k-3)/2)-b)...
  57. *2^(-1/2)*(k*t/v).^(1/2*(k-3)).*(1+k*t/v).^(-1/2*(v+k-2))...
  58. .*((v-1)*(v-2)*(k*t/v).^2-(2*v*k-v-k-1)*(k*t/v)+(k-1)*(k-2));
  59. end