spm_invXcdf.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function x = spm_invXcdf(F,v)
  2. % Inverse Cumulative Distribution Function (CDF) of Chi-squared distribution
  3. % FORMAT x = spm_invXcdf(F,v)
  4. %
  5. % F - CDF (lower tail p-value)
  6. % v - degrees of freedom (v>0, non-integer d.f. accepted)
  7. % x - Chi-squared ordinates at which CDF F(x)=F
  8. %__________________________________________________________________________
  9. %
  10. % spm_invXcdf implements the inverse Cumulative Distribution of the
  11. % Chi-squared distribution.
  12. %
  13. % Definition:
  14. %--------------------------------------------------------------------------
  15. % The Chi-squared distribution with v degrees of freedom is defined for
  16. % positive integer v and x in [0,Inf). The Cumulative Distribution
  17. % Function (CDF) F(x) is the probability that a realisation of a
  18. % Chi-squared random variable X has value less than x. F(x)=Pr{X<x}:
  19. % (See Evans et al., Ch8)
  20. %
  21. % Variate relationships: (Evans et al., Ch8 & Ch18)
  22. %--------------------------------------------------------------------------
  23. % The Chi-squared distribution with v degrees of freedom is equivalent to
  24. % the Gamma distribution with scale parameter 1/2 and shape parameter v/2.
  25. %
  26. % Algorithm:
  27. %--------------------------------------------------------------------------
  28. % Using routine spm_invGcdf for Gamma distribution, with appropriate
  29. % parameters.
  30. %
  31. % References:
  32. %--------------------------------------------------------------------------
  33. % Evans M, Hastings N, Peacock B (1993)
  34. % "Statistical Distributions"
  35. % 2nd Ed. Wiley, New York
  36. %
  37. % Abramowitz M, Stegun IA, (1964)
  38. % "Handbook of Mathematical Functions"
  39. % US Government Printing Office
  40. %
  41. % Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992)
  42. % "Numerical Recipes in C"
  43. % Cambridge
  44. %
  45. %__________________________________________________________________________
  46. % Copyright (C) 1993-2011 Wellcome Trust Centre for Neuroimaging
  47. % Andrew Holmes
  48. % $Id: spm_invXcdf.m 4182 2011-02-01 12:29:09Z guillaume $
  49. %-Check enough arguments
  50. %--------------------------------------------------------------------------
  51. if nargin<2, error('Insufficient arguments'), end
  52. %-Computation
  53. %--------------------------------------------------------------------------
  54. x = spm_invGcdf(F,v/2,1/2);