pdtr.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* pdtr.c
  2. *
  3. * Poisson distribution
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * int k;
  10. * double m, y, pdtr();
  11. *
  12. * y = pdtr( 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. * See igamc().
  39. *
  40. */
  41. /* pdtrc()
  42. *
  43. * Complemented poisson distribution
  44. *
  45. *
  46. *
  47. * SYNOPSIS:
  48. *
  49. * int k;
  50. * double m, y, pdtrc();
  51. *
  52. * y = pdtrc( k, m );
  53. *
  54. *
  55. *
  56. * DESCRIPTION:
  57. *
  58. * Returns the sum of the terms k+1 to infinity of the Poisson
  59. * distribution:
  60. *
  61. * inf. j
  62. * -- -m m
  63. * > e --
  64. * -- j!
  65. * j=k+1
  66. *
  67. * The terms are not summed directly; instead the incomplete
  68. * gamma integral is employed, according to the formula
  69. *
  70. * y = pdtrc( k, m ) = igam( k+1, m ).
  71. *
  72. * The arguments must both be positive.
  73. *
  74. *
  75. *
  76. * ACCURACY:
  77. *
  78. * See igam.c.
  79. *
  80. */
  81. /* pdtri()
  82. *
  83. * Inverse Poisson distribution
  84. *
  85. *
  86. *
  87. * SYNOPSIS:
  88. *
  89. * int k;
  90. * double m, y, pdtr();
  91. *
  92. * m = pdtri( k, y );
  93. *
  94. *
  95. *
  96. *
  97. * DESCRIPTION:
  98. *
  99. * Finds the Poisson variable x such that the integral
  100. * from 0 to x of the Poisson density is equal to the
  101. * given probability y.
  102. *
  103. * This is accomplished using the inverse gamma integral
  104. * function and the relation
  105. *
  106. * m = igami( k+1, y ).
  107. *
  108. *
  109. *
  110. *
  111. * ACCURACY:
  112. *
  113. * See igami.c.
  114. *
  115. * ERROR MESSAGES:
  116. *
  117. * message condition value returned
  118. * pdtri domain y < 0 or y >= 1 0.0
  119. * k < 0
  120. *
  121. */
  122. /*
  123. Cephes Math Library Release 2.8: June, 2000
  124. Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
  125. */
  126. #include <math.h>
  127. #ifdef ANSIPROT
  128. extern double igam ( double, double );
  129. extern double igamc ( double, double );
  130. extern double igami ( double, double );
  131. #else
  132. double igam(), igamc(), igami();
  133. #endif
  134. double pdtrc( k, m )
  135. int k;
  136. double m;
  137. {
  138. double v;
  139. if( (k < 0) || (m <= 0.0) )
  140. {
  141. mtherr( "pdtrc", DOMAIN );
  142. return( 0.0 );
  143. }
  144. v = k+1;
  145. return( igam( v, m ) );
  146. }
  147. double pdtr( k, m )
  148. int k;
  149. double m;
  150. {
  151. double v;
  152. if( (k < 0) || (m <= 0.0) )
  153. {
  154. mtherr( "pdtr", DOMAIN );
  155. return( 0.0 );
  156. }
  157. v = k+1;
  158. return( igamc( v, m ) );
  159. }
  160. double pdtri( k, y )
  161. int k;
  162. double y;
  163. {
  164. double v;
  165. if( (k < 0) || (y < 0.0) || (y >= 1.0) )
  166. {
  167. mtherr( "pdtri", DOMAIN );
  168. return( 0.0 );
  169. }
  170. v = k+1;
  171. v = igami( v, y );
  172. return( v );
  173. }