pdtrf.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* pdtrf.c
  2. *
  3. * Poisson distribution
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * int k;
  10. * float m, y, pdtrf();
  11. *
  12. * y = pdtrf( k, m );
  13. *
  14. *
  15. *
  16. * DESCRIPTION:
  17. *
  18. * Returns the sum of the first k terms of the Poisson
  19. * distribution:
  20. *
  21. * k j
  22. * -- -m m
  23. * > e --
  24. * -- j!
  25. * j=0
  26. *
  27. * The terms are not summed directly; instead the incomplete
  28. * gamma integral is employed, according to the relation
  29. *
  30. * y = pdtr( k, m ) = igamc( k+1, m ).
  31. *
  32. * The arguments must both be positive.
  33. *
  34. *
  35. *
  36. * ACCURACY:
  37. *
  38. * Relative error:
  39. * arithmetic domain # trials peak rms
  40. * IEEE 0,100 5000 6.9e-5 8.0e-6
  41. *
  42. */
  43. /* pdtrcf()
  44. *
  45. * Complemented poisson distribution
  46. *
  47. *
  48. *
  49. * SYNOPSIS:
  50. *
  51. * int k;
  52. * float m, y, pdtrcf();
  53. *
  54. * y = pdtrcf( k, m );
  55. *
  56. *
  57. *
  58. * DESCRIPTION:
  59. *
  60. * Returns the sum of the terms k+1 to infinity of the Poisson
  61. * distribution:
  62. *
  63. * inf. j
  64. * -- -m m
  65. * > e --
  66. * -- j!
  67. * j=k+1
  68. *
  69. * The terms are not summed directly; instead the incomplete
  70. * gamma integral is employed, according to the formula
  71. *
  72. * y = pdtrc( k, m ) = igam( k+1, m ).
  73. *
  74. * The arguments must both be positive.
  75. *
  76. *
  77. *
  78. * ACCURACY:
  79. *
  80. * Relative error:
  81. * arithmetic domain # trials peak rms
  82. * IEEE 0,100 5000 8.4e-5 1.2e-5
  83. *
  84. */
  85. /* pdtrif()
  86. *
  87. * Inverse Poisson distribution
  88. *
  89. *
  90. *
  91. * SYNOPSIS:
  92. *
  93. * int k;
  94. * float m, y, pdtrf();
  95. *
  96. * m = pdtrif( k, y );
  97. *
  98. *
  99. *
  100. *
  101. * DESCRIPTION:
  102. *
  103. * Finds the Poisson variable x such that the integral
  104. * from 0 to x of the Poisson density is equal to the
  105. * given probability y.
  106. *
  107. * This is accomplished using the inverse gamma integral
  108. * function and the relation
  109. *
  110. * m = igami( k+1, y ).
  111. *
  112. *
  113. *
  114. *
  115. * ACCURACY:
  116. *
  117. * Relative error:
  118. * arithmetic domain # trials peak rms
  119. * IEEE 0,100 5000 8.7e-6 1.4e-6
  120. *
  121. * ERROR MESSAGES:
  122. *
  123. * message condition value returned
  124. * pdtri domain y < 0 or y >= 1 0.0
  125. * k < 0
  126. *
  127. */
  128. /*
  129. Cephes Math Library Release 2.2: July, 1992
  130. Copyright 1984, 1987, 1992 by Stephen L. Moshier
  131. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  132. */
  133. #include <math.h>
  134. #ifdef ANSIC
  135. float igamf(float, float), igamcf(float, float), igamif(float, float);
  136. #else
  137. float igamf(), igamcf(), igamif();
  138. #endif
  139. float pdtrcf( int k, float mm )
  140. {
  141. float v, m;
  142. m = mm;
  143. if( (k < 0) || (m <= 0.0) )
  144. {
  145. mtherr( "pdtrcf", DOMAIN );
  146. return( 0.0 );
  147. }
  148. v = k+1;
  149. return( igamf( v, m ) );
  150. }
  151. float pdtrf( int k, float mm )
  152. {
  153. float v, m;
  154. m = mm;
  155. if( (k < 0) || (m <= 0.0) )
  156. {
  157. mtherr( "pdtr", DOMAIN );
  158. return( 0.0 );
  159. }
  160. v = k+1;
  161. return( igamcf( v, m ) );
  162. }
  163. float pdtrif( int k, float yy )
  164. {
  165. float v, y;
  166. y = yy;
  167. if( (k < 0) || (y < 0.0) || (y >= 1.0) )
  168. {
  169. mtherr( "pdtrif", DOMAIN );
  170. return( 0.0 );
  171. }
  172. v = k+1;
  173. v = igamif( v, y );
  174. return( v );
  175. }