@numero-uno-jpn/rstats 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/LICENSE +21 -0
  3. package/README.ja.md +181 -0
  4. package/README.md +172 -2
  5. package/THIRD_PARTY_NOTICES.md +297 -0
  6. package/dist/distributions/beta.d.ts +62 -0
  7. package/dist/distributions/beta.js +246 -0
  8. package/dist/distributions/binomial.d.ts +41 -0
  9. package/dist/distributions/binomial.js +136 -0
  10. package/dist/distributions/cauchy.d.ts +34 -0
  11. package/dist/distributions/cauchy.js +139 -0
  12. package/dist/distributions/chisq.d.ts +42 -0
  13. package/dist/distributions/chisq.js +60 -0
  14. package/dist/distributions/exponential.d.ts +34 -0
  15. package/dist/distributions/exponential.js +93 -0
  16. package/dist/distributions/f.d.ts +47 -0
  17. package/dist/distributions/f.js +214 -0
  18. package/dist/distributions/gamma.d.ts +61 -0
  19. package/dist/distributions/gamma.js +188 -0
  20. package/dist/distributions/geometric.d.ts +38 -0
  21. package/dist/distributions/geometric.js +116 -0
  22. package/dist/distributions/hypergeometric.d.ts +38 -0
  23. package/dist/distributions/hypergeometric.js +234 -0
  24. package/dist/distributions/logistic.d.ts +36 -0
  25. package/dist/distributions/logistic.js +94 -0
  26. package/dist/distributions/lognormal.d.ts +39 -0
  27. package/dist/distributions/lognormal.js +158 -0
  28. package/dist/distributions/nbeta.d.ts +7 -0
  29. package/dist/distributions/nbeta.js +312 -0
  30. package/dist/distributions/nchisq.d.ts +3 -0
  31. package/dist/distributions/nchisq.js +217 -0
  32. package/dist/distributions/negbinomial.d.ts +54 -0
  33. package/dist/distributions/negbinomial.js +325 -0
  34. package/dist/distributions/normal.d.ts +66 -0
  35. package/dist/distributions/normal.js +184 -0
  36. package/dist/distributions/nt.d.ts +3 -0
  37. package/dist/distributions/nt.js +491 -0
  38. package/dist/distributions/poisson.d.ts +41 -0
  39. package/dist/distributions/poisson.js +104 -0
  40. package/dist/distributions/signrank.d.ts +38 -0
  41. package/dist/distributions/signrank.js +216 -0
  42. package/dist/distributions/t.d.ts +49 -0
  43. package/dist/distributions/t.js +235 -0
  44. package/dist/distributions/tukey.d.ts +43 -0
  45. package/dist/distributions/tukey.js +985 -0
  46. package/dist/distributions/uniform.d.ts +36 -0
  47. package/dist/distributions/uniform.js +90 -0
  48. package/dist/distributions/weibull.d.ts +37 -0
  49. package/dist/distributions/weibull.js +125 -0
  50. package/dist/distributions/wilcox.d.ts +47 -0
  51. package/dist/distributions/wilcox.js +270 -0
  52. package/dist/htest/chisqTest.d.ts +55 -0
  53. package/dist/htest/chisqTest.js +160 -0
  54. package/dist/htest/cor.d.ts +81 -0
  55. package/dist/htest/cor.js +436 -0
  56. package/dist/htest/fisherTest.d.ts +48 -0
  57. package/dist/htest/fisherTest.js +468 -0
  58. package/dist/htest/pAdjust.d.ts +34 -0
  59. package/dist/htest/pAdjust.js +147 -0
  60. package/dist/htest/tTest.d.ts +57 -0
  61. package/dist/htest/tTest.js +153 -0
  62. package/dist/htest/types.d.ts +49 -0
  63. package/dist/htest/types.js +20 -0
  64. package/dist/htest/wilcoxTest.d.ts +61 -0
  65. package/dist/htest/wilcoxTest.js +471 -0
  66. package/dist/index.d.ts +50 -0
  67. package/dist/index.js +50 -0
  68. package/dist/internal/ddexp.d.ts +19 -0
  69. package/dist/internal/ddexp.js +94 -0
  70. package/dist/internal/discrete.d.ts +14 -0
  71. package/dist/internal/discrete.js +85 -0
  72. package/dist/internal/dpq.d.ts +43 -0
  73. package/dist/internal/dpq.js +54 -0
  74. package/dist/internal/integer.d.ts +4 -0
  75. package/dist/internal/integer.js +17 -0
  76. package/dist/internal/invert.d.ts +36 -0
  77. package/dist/internal/invert.js +124 -0
  78. package/dist/internal/noncentral.d.ts +12 -0
  79. package/dist/internal/noncentral.js +2 -0
  80. package/dist/internal/poissonMixture.d.ts +31 -0
  81. package/dist/internal/poissonMixture.js +401 -0
  82. package/dist/internal/summary.d.ts +21 -0
  83. package/dist/internal/summary.js +125 -0
  84. package/dist/internal/uniroot.d.ts +11 -0
  85. package/dist/internal/uniroot.js +75 -0
  86. package/dist/internal/vectorize.d.ts +12 -0
  87. package/dist/internal/vectorize.js +7 -0
  88. package/dist/linalg/basic.d.ts +95 -0
  89. package/dist/linalg/basic.js +152 -0
  90. package/dist/linalg/chol.d.ts +83 -0
  91. package/dist/linalg/chol.js +200 -0
  92. package/dist/linalg/eigen.d.ts +52 -0
  93. package/dist/linalg/eigen.js +753 -0
  94. package/dist/linalg/kappa.d.ts +51 -0
  95. package/dist/linalg/kappa.js +199 -0
  96. package/dist/linalg/matrix.d.ts +29 -0
  97. package/dist/linalg/matrix.js +65 -0
  98. package/dist/linalg/norm.d.ts +32 -0
  99. package/dist/linalg/norm.js +92 -0
  100. package/dist/linalg/qr.d.ts +264 -0
  101. package/dist/linalg/qr.js +494 -0
  102. package/dist/linalg/solve.d.ts +123 -0
  103. package/dist/linalg/solve.js +380 -0
  104. package/dist/linalg/svd.d.ts +38 -0
  105. package/dist/linalg/svd.js +275 -0
  106. package/dist/random/as241.d.ts +2 -0
  107. package/dist/random/as241.js +58 -0
  108. package/dist/random/beta.d.ts +14 -0
  109. package/dist/random/beta.js +117 -0
  110. package/dist/random/binomial.d.ts +25 -0
  111. package/dist/random/binomial.js +224 -0
  112. package/dist/random/common.d.ts +4 -0
  113. package/dist/random/common.js +35 -0
  114. package/dist/random/continuous.d.ts +91 -0
  115. package/dist/random/continuous.js +138 -0
  116. package/dist/random/gamma.d.ts +52 -0
  117. package/dist/random/gamma.js +217 -0
  118. package/dist/random/hyper.d.ts +12 -0
  119. package/dist/random/hyper.js +240 -0
  120. package/dist/random/mt.d.ts +16 -0
  121. package/dist/random/mt.js +97 -0
  122. package/dist/random/poisson.d.ts +33 -0
  123. package/dist/random/poisson.js +204 -0
  124. package/dist/random/rank.d.ts +19 -0
  125. package/dist/random/rank.js +62 -0
  126. package/dist/random/rng.d.ts +46 -0
  127. package/dist/random/rng.js +148 -0
  128. package/dist/random/sample.d.ts +45 -0
  129. package/dist/random/sample.js +255 -0
  130. package/dist/rstats.js +2 -0
  131. package/dist/special/beta.d.ts +30 -0
  132. package/dist/special/beta.js +152 -0
  133. package/dist/special/constants.d.ts +16 -0
  134. package/dist/special/constants.js +19 -0
  135. package/dist/special/dd.d.ts +29 -0
  136. package/dist/special/dd.js +693 -0
  137. package/dist/special/erf.d.ts +9 -0
  138. package/dist/special/erf.js +85 -0
  139. package/dist/special/gamma.d.ts +32 -0
  140. package/dist/special/gamma.js +270 -0
  141. package/dist/special/igam.d.ts +11 -0
  142. package/dist/special/igam.js +291 -0
  143. package/dist/special/igamAsympCoeff.d.ts +4 -0
  144. package/dist/special/igamAsympCoeff.js +233 -0
  145. package/dist/special/igami.d.ts +2 -0
  146. package/dist/special/igami.js +135 -0
  147. package/dist/special/incbet.d.ts +25 -0
  148. package/dist/special/incbet.js +326 -0
  149. package/dist/special/lgammaDiff.d.ts +2 -0
  150. package/dist/special/lgammaDiff.js +34 -0
  151. package/dist/special/loader.d.ts +43 -0
  152. package/dist/special/loader.js +456 -0
  153. package/dist/special/log1pmx.d.ts +2 -0
  154. package/dist/special/log1pmx.js +20 -0
  155. package/dist/special/ndtri.d.ts +4 -0
  156. package/dist/special/ndtri.js +82 -0
  157. package/dist/special/polevl.d.ts +4 -0
  158. package/dist/special/polevl.js +17 -0
  159. package/package.json +68 -4
@@ -0,0 +1,233 @@
1
+ // Ported from xsf include/xsf/cephes/igam_asymp_coeff.h (xsf commit c6a3afe).
2
+ // The table was generated by SciPy's _precomp/gammainc.py.
3
+ // xsf Copyright (c) 2024, SciPy. BSD-3-Clause. See THIRD_PARTY_NOTICES.md.
4
+ /** Coefficients d[k][n] of Temme's uniform asymptotic expansion (DLMF 8.12.3/8.12.4) */
5
+ export const IGAM_ASYMP_COEFF_K = 25;
6
+ export const IGAM_ASYMP_COEFF_N = 25;
7
+ export const IGAM_ASYMP_COEFF_D = [
8
+ [
9
+ -3.3333333333333333e-1, 8.3333333333333333e-2, -1.4814814814814815e-2, 1.1574074074074074e-3,
10
+ 3.527336860670194e-4, -1.7875514403292181e-4, 3.9192631785224378e-5, -2.1854485106799922e-6,
11
+ -1.85406221071516e-6, 8.296711340953086e-7, -1.7665952736826079e-7, 6.7078535434014986e-9,
12
+ 1.0261809784240308e-8, -4.3820360184533532e-9, 9.1476995822367902e-10, -2.551419399494625e-11,
13
+ -5.8307721325504251e-11, 2.4361948020667416e-11, -5.0276692801141756e-12, 1.1004392031956135e-13,
14
+ 3.3717632624009854e-13, -1.3923887224181621e-13, 2.8534893807047443e-14, -5.1391118342425726e-16,
15
+ -1.9752288294349443e-15,
16
+ ],
17
+ [
18
+ -1.8518518518518519e-3, -3.4722222222222222e-3, 2.6455026455026455e-3, -9.9022633744855967e-4,
19
+ 2.0576131687242798e-4, -4.0187757201646091e-7, -1.8098550334489978e-5, 7.6491609160811101e-6,
20
+ -1.6120900894563446e-6, 4.6471278028074343e-9, 1.378633446915721e-7, -5.752545603517705e-8,
21
+ 1.1951628599778147e-8, -1.7543241719747648e-11, -1.0091543710600413e-9, 4.1627929918425826e-10,
22
+ -8.5639070264929806e-11, 6.0672151016047586e-14, 7.1624989648114854e-12, -2.9331866437714371e-12,
23
+ 5.9966963656836887e-13, -2.1671786527323314e-16, -4.9783399723692616e-14, 2.0291628823713425e-14,
24
+ -4.13125571381061e-15,
25
+ ],
26
+ [
27
+ 4.1335978835978836e-3, -2.6813271604938272e-3, 7.7160493827160494e-4, 2.0093878600823045e-6,
28
+ -1.0736653226365161e-4, 5.2923448829120125e-5, -1.2760635188618728e-5, 3.4235787340961381e-8,
29
+ 1.3721957309062933e-6, -6.298992138380055e-7, 1.4280614206064242e-7, -2.0477098421990866e-10,
30
+ -1.4092529910867521e-8, 6.228974084922022e-9, -1.3670488396617113e-9, 9.4283561590146782e-13,
31
+ 1.2872252400089318e-10, -5.5645956134363321e-11, 1.1975935546366981e-11, -4.1689782251838635e-15,
32
+ -1.0940640427884594e-12, 4.6622399463901357e-13, -9.905105763906906e-14, 1.8931876768373515e-17,
33
+ 8.8592218725911273e-15,
34
+ ],
35
+ [
36
+ 6.4943415637860082e-4, 2.2947209362139918e-4, -4.6918949439525571e-4, 2.6772063206283885e-4,
37
+ -7.5618016718839764e-5, -2.3965051138672967e-7, 1.1082654115347302e-5, -5.6749528269915966e-6,
38
+ 1.4230900732435884e-6, -2.7861080291528142e-11, -1.6958404091930277e-7, 8.0994649053880824e-8,
39
+ -1.9111168485973654e-8, 2.3928620439808118e-12, 2.0620131815488798e-9, -9.4604966618551322e-10,
40
+ 2.1541049775774908e-10, -1.388823336813903e-14, -2.1894761681963939e-11, 9.7909989511716851e-12,
41
+ -2.1782191880180962e-12, 6.2088195734079014e-17, 2.126978363279737e-13, -9.3446887915174333e-14,
42
+ 2.0453671226782849e-14,
43
+ ],
44
+ [
45
+ -8.618882909167117e-4, 7.8403922172006663e-4, -2.9907248030319018e-4, -1.4638452578843418e-6,
46
+ 6.6414982154651222e-5, -3.9683650471794347e-5, 1.1375726970678419e-5, 2.5074972262375328e-10,
47
+ -1.6954149536558306e-6, 8.9075075322053097e-7, -2.2929348340008049e-7, 2.956794137544049e-11,
48
+ 2.8865829742708784e-8, -1.4189739437803219e-8, 3.4463580499464897e-9, -2.3024517174528067e-13,
49
+ -3.9409233028046405e-10, 1.8602338968504502e-10, -4.356323005056618e-11, 1.2786001016296231e-15,
50
+ 4.6792750266579195e-12, -2.1492464706134829e-12, 4.9088156148096522e-13, -6.3385914848915603e-18,
51
+ -5.0453320690800944e-14,
52
+ ],
53
+ [
54
+ -3.3679855336635815e-4, -6.9728137583658578e-5, 2.7727532449593921e-4, -1.9932570516188848e-4,
55
+ 6.7977804779372078e-5, 1.419062920643967e-7, -1.3594048189768693e-5, 8.0184702563342015e-6,
56
+ -2.2914811765080952e-6, -3.252473551298454e-10, 3.4652846491085265e-7, -1.8447187191171343e-7,
57
+ 4.8240967037894181e-8, -1.7989466721743515e-14, -6.3061945000135234e-9, 3.1624176287745679e-9,
58
+ -7.8409242536974293e-10, 5.1926791652540407e-15, 9.3589442423067836e-11, -4.5134262161632782e-11,
59
+ 1.0799129993116827e-11, -3.661886712685252e-17, -1.210902069055155e-12, 5.6807435849905643e-13,
60
+ -1.3249659916340829e-13,
61
+ ],
62
+ [
63
+ 5.3130793646399222e-4, -5.9216643735369388e-4, 2.7087820967180448e-4, 7.9023532326603279e-7,
64
+ -8.1539693675619688e-5, 5.6116827531062497e-5, -1.8329116582843376e-5, -3.0796134506033048e-9,
65
+ 3.4651553688036091e-6, -2.0291327396058604e-6, 5.7887928631490037e-7, 2.338630673826657e-13,
66
+ -8.8286007463304835e-8, 4.7435958880408128e-8, -1.2545415020710382e-8, 8.6496488580102925e-14,
67
+ 1.6846058979264063e-9, -8.5754928235775947e-10, 2.1598224929232125e-10, -7.6132305204761539e-16,
68
+ -2.6639822008536144e-11, 1.3065700536611057e-11, -3.1799163902367977e-12, 4.7109761213674315e-18,
69
+ 3.6902800842763467e-13,
70
+ ],
71
+ [
72
+ 3.4436760689237767e-4, 5.1717909082605922e-5, -3.3493161081142236e-4, 2.812695154763237e-4,
73
+ -1.0976582244684731e-4, -1.2741009095484485e-7, 2.7744451511563644e-5, -1.8263488805711333e-5,
74
+ 5.7876949497350524e-6, 4.9387589339362704e-10, -1.0595367014026043e-6, 6.1667143761104075e-7,
75
+ -1.7562973359060462e-7, -1.2974473287015439e-12, 2.695423606288966e-8, -1.4578352908731271e-8,
76
+ 3.887645959386175e-9, -3.8810022510194121e-17, -5.3279941738772867e-10, 2.7437977643314845e-10,
77
+ -6.9957960920705679e-11, 2.5899863874868481e-17, 8.8566890996696381e-12, -4.403168815871311e-12,
78
+ 1.0865561947091654e-12,
79
+ ],
80
+ [
81
+ -6.5262391859530942e-4, 8.3949872067208728e-4, -4.3829709854172101e-4, -6.969091458420552e-7,
82
+ 1.6644846642067548e-4, -1.2783517679769219e-4, 4.6299532636913043e-5, 4.5579098679227077e-9,
83
+ -1.0595271125805195e-5, 6.7833429048651666e-6, -2.1075476666258804e-6, -1.7213731432817145e-11,
84
+ 3.7735877416110979e-7, -2.1867506700122867e-7, 6.2202288040189269e-8, 6.5977038267330006e-16,
85
+ -9.5903864974256858e-9, 5.2132144922808078e-9, -1.3991589583935709e-9, 5.382058999060575e-16,
86
+ 1.9484714275467745e-10, -1.0127287556389682e-10, 2.6077347197254926e-11, -5.0904186999932993e-18,
87
+ -3.3721464474854592e-12,
88
+ ],
89
+ [
90
+ -5.9676129019274625e-4, -7.2048954160200106e-5, 6.7823088376673284e-4, -6.4014752602627585e-4,
91
+ 2.7750107634328704e-4, 1.8197008380465151e-7, -8.4795071170685032e-5, 6.105192082501531e-5,
92
+ -2.1073920183404862e-5, -8.8585890141255994e-10, 4.5284535953805377e-6, -2.8427815022504408e-6,
93
+ 8.7082341778646412e-7, 3.6886101871706965e-12, -1.5344695190702061e-7, 8.862466778790695e-8,
94
+ -2.5184812301826817e-8, -1.0225912098215092e-14, 3.8969470758154777e-9, -2.1267304792235635e-9,
95
+ 5.7370135528051385e-10, -1.887749850169741e-19, -8.0931538694657866e-11, 4.2382723283449199e-11,
96
+ -1.1002224534207726e-11,
97
+ ],
98
+ [
99
+ 1.3324454494800656e-3, -1.9144384985654775e-3, 1.1089369134596637e-3, 9.932404122642299e-7,
100
+ -5.0874501293093199e-4, 4.2735056665392884e-4, -1.6858853767910799e-4, -8.1301893922784998e-9,
101
+ 4.5284402370562147e-5, -3.127053674781734e-5, 1.044986828530338e-5, 4.8435226265680926e-11,
102
+ -2.1482565873456258e-6, 1.329369701097492e-6, -4.0295693092101029e-7, -1.7567877666323291e-13,
103
+ 7.0145043163668257e-8, -4.040787734999483e-8, 1.1474026743371963e-8, 3.9642746853563325e-18,
104
+ -1.7804938269892714e-9, 9.7480262548731646e-10, -2.6405338676507616e-10, 5.794875163403742e-18,
105
+ 3.7647749553543836e-11,
106
+ ],
107
+ [
108
+ 1.579727660730835e-3, 1.6251626278391582e-4, -2.0633421035543276e-3, 2.1389686185689098e-3,
109
+ -1.0108559391263003e-3, -3.9912705529919201e-7, 3.6235025084764691e-4, -2.8143901463712154e-4,
110
+ 1.0449513336495887e-4, 2.1211418491830297e-9, -2.5779417251947842e-5, 1.7281818956040463e-5,
111
+ -5.6413773872904282e-6, -1.1024320105776174e-11, 1.1223224418895175e-6, -6.8693396379526735e-7,
112
+ 2.0653236975414887e-7, 4.6714772409838506e-14, -3.5609886164949055e-8, 2.0470855345905963e-8,
113
+ -5.8091738633283358e-9, -1.332821287582869e-16, 9.0354604391335133e-10, -4.9598782517330834e-10,
114
+ 1.3481607129399749e-10,
115
+ ],
116
+ [
117
+ -4.0725121195140166e-3, 6.4033628338080698e-3, -4.0410161081676618e-3, -2.183732802866233e-6,
118
+ 2.1740441801254639e-3, -1.9700440518418892e-3, 8.3595469747962458e-4, 1.9445447567109655e-8,
119
+ -2.5779387120421696e-4, 1.9009987368139304e-4, -6.7696499937438965e-5, -1.4440629666426572e-10,
120
+ 1.5712512518742269e-5, -1.0304008744776893e-5, 3.304517767401387e-6, 7.9829760242325709e-13,
121
+ -6.4097794149313004e-7, 3.8894624761300056e-7, -1.1618347644948869e-7, -2.816808630596451e-15,
122
+ 1.9878012911297093e-8, -1.1407719956357511e-8, 3.2355857064185555e-9, 4.1759468293455945e-20,
123
+ -5.0423112718105824e-10,
124
+ ],
125
+ [
126
+ -5.9475779383993003e-3, -5.4016476789260452e-4, 8.7910413550767898e-3, -9.8576315587856125e-3,
127
+ 5.0134695031021538e-3, 1.2807521786221875e-6, -2.0626019342754683e-3, 1.7109128573523058e-3,
128
+ -6.7695312714133799e-4, -6.9011545676562133e-9, 1.8855128143995902e-4, -1.3395215663491969e-4,
129
+ 4.6263183033528039e-5, 4.0034230613321351e-11, -1.0255652921494033e-5, 6.612086372797651e-6,
130
+ -2.0913022027253008e-6, -2.0951775649603837e-13, 3.9756029041993247e-7, -2.3956211978815887e-7,
131
+ 7.1182883382145864e-8, 8.925574873053455e-16, -1.2101547235064676e-8, 6.9350618248334386e-9,
132
+ -1.9661464453856102e-9,
133
+ ],
134
+ [
135
+ 1.7402027787522711e-2, -2.9527880945699121e-2, 2.0045875571402799e-2, 7.0289515966903407e-6,
136
+ -1.2375421071343148e-2, 1.1976293444235254e-2, -5.4156038466518525e-3, -6.3290893396418616e-8,
137
+ 1.8855118129005065e-3, -1.473473274825001e-3, 5.5515810097708387e-4, 5.2406834412550662e-10,
138
+ -1.4357913535784836e-4, 9.9181293224943297e-5, -3.3460834749478311e-5, -3.5755837291098993e-12,
139
+ 7.1560851960630076e-6, -4.5516802628155526e-6, 1.4236576649271475e-6, 1.8803149082089664e-14,
140
+ -2.6623403898929211e-7, 1.5950642189595716e-7, -4.7187514673841102e-8, -6.5107872958755177e-17,
141
+ 7.9795091026746235e-9,
142
+ ],
143
+ [
144
+ 3.0249124160905891e-2, 2.4817436002649977e-3, -4.9939134373457022e-2, 5.9915643009307869e-2,
145
+ -3.2483207601623391e-2, -5.7212968652103441e-6, 1.5085251778569354e-2, -1.3261324005088445e-2,
146
+ 5.5515262632426148e-3, 3.0263182257030016e-8, -1.7229548406756723e-3, 1.2893570099929637e-3,
147
+ -4.6845138348319876e-4, -1.830259937893045e-10, 1.1449739014822654e-4, -7.7378565221244477e-5,
148
+ 2.5625836246985201e-5, 1.0766165333192814e-12, -5.3246809282422621e-6, 3.349634863064464e-6,
149
+ -1.0381253128684018e-6, -5.608909920621128e-15, 1.9150821930676591e-7, -1.1418365800203486e-7,
150
+ 3.3654425209171788e-8,
151
+ ],
152
+ [
153
+ -9.9051020880159045e-2, 1.7954011706123486e-1, -1.2989606383463778e-1, -3.1478872752284357e-5,
154
+ 9.0510635276848131e-2, -9.2828824411184397e-2, 4.4412112839877808e-2, 2.7779236316835888e-7,
155
+ -1.7229543805449697e-2, 1.4182925050891573e-2, -5.6214161633747336e-3, -2.39598509186381e-9,
156
+ 1.6029634366079908e-3, -1.1606784674435773e-3, 4.1001337768153873e-4, 1.8365800754090661e-11,
157
+ -9.5844256563655903e-5, 6.3643062337764708e-5, -2.076250624489065e-5, -1.1806020912804483e-13,
158
+ 4.2131808239120649e-6, -2.6262241337012467e-6, 8.0770620494930662e-7, 6.0125912123632725e-16,
159
+ -1.4729737374018841e-7,
160
+ ],
161
+ [
162
+ -1.9994542198219728e-1, -1.5056113040026424e-2, 3.6470239469348489e-1, -4.6435192311733545e-1,
163
+ 2.6640934719197893e-1, 3.4038266027147191e-5, -1.3784338709329624e-1, 1.276467178337056e-1,
164
+ -5.6213828755200985e-2, -1.753150885483011e-7, 1.9235592956768113e-2, -1.5088821281095315e-2,
165
+ 5.7401854451350123e-3, 1.0622382710310225e-9, -1.5335082692563998e-3, 1.0819320643228214e-3,
166
+ -3.7372510193945659e-4, -6.6170909729031985e-12, 8.4263617380909628e-5, -5.5150706827483479e-5,
167
+ 1.7769536448348069e-5, 3.8827923210205533e-14, -3.53513697488768e-6, 2.1865832130045269e-6,
168
+ -6.6812849447625594e-7,
169
+ ],
170
+ [
171
+ 7.2438608504029431e-1, -1.3918010932653375, 1.0654143352413968, 1.876173868950258e-4,
172
+ -8.2705501176152696e-1, 8.9352433347828414e-1, -4.4971003995291339e-1, -1.6107401567546652e-6,
173
+ 1.9235590165271091e-1, -1.6597702160042609e-1, 6.8882222681814333e-2, 1.3910091724608687e-8,
174
+ -2.146911561508663e-2, 1.6228980898865892e-2, -5.9796016172584256e-3, -1.1287469112826745e-10,
175
+ 1.5167451119784857e-3, -1.0478634293553899e-3, 3.5539072889126421e-4, 8.1704322111801517e-13,
176
+ -7.7773013442452395e-5, 5.0291413897007722e-5, -1.6035083867000518e-5, 1.2469354315487605e-14,
177
+ 3.1369106244517615e-6,
178
+ ],
179
+ [
180
+ 1.6668949727276811, 1.165462765994632e-1, -3.3288393225018906, 4.4692325482864037,
181
+ -2.6977693045875807, -2.600667859891061e-4, 1.5389017615694539, -1.4937962361134612,
182
+ 6.8881964633233148e-1, 1.3077482004552385e-6, -2.5762963325596288e-1, 2.1097676102125449e-1,
183
+ -8.3714408359219882e-2, -7.7920428881354753e-9, 2.4267923064833599e-2, -1.7813678334552311e-2,
184
+ 6.3970330388900056e-3, 4.9430807090480523e-11, -1.5554602758465635e-3, 1.0561196919903214e-3,
185
+ -3.5277184460472902e-4, 9.3002334645022459e-14, 7.5285855026557172e-5, -4.8186515569156351e-5,
186
+ 1.5227271505597605e-5,
187
+ ],
188
+ [
189
+ -6.6188298861372935, 1.3397985455142589e+1, -1.0789350606845146e+1, -1.4352254537875018e-3,
190
+ 9.2333694596189809, -1.0456552819547769e+1, 5.5105526029033471, 1.2024439690716742e-5,
191
+ -2.5762961164755816, 2.3207442745387179, -1.0045728797216284, -1.0207833290021914e-7,
192
+ 3.3975092171169466e-1, -2.6720517450757468e-1, 1.0235252851562706e-1, 8.4329730484871625e-10,
193
+ -2.7998284958442595e-2, 2.0066274144976813e-2, -7.0554368915086242e-3, 1.9402238183698188e-12,
194
+ 1.6562888105449611e-3, -1.1082898580743683e-3, 3.654545161310169e-4, -5.1290032026971794e-11,
195
+ -7.6340103696869031e-5,
196
+ ],
197
+ [
198
+ -1.7112706061976095e+1, -1.1208044642899116, 3.7131966511885444e+1, -5.2298271025348962e+1,
199
+ 3.3058589696624618e+1, 2.4791298976200222e-3, -2.061089403411526e+1, 2.088672775145582e+1,
200
+ -1.0045703956517752e+1, -1.2238783449063012e-5, 4.0770134274221141, -3.473667358470195,
201
+ 1.4329352617312006, 7.1359914411879712e-8, -4.4797257159115612e-1, 3.4112666080644461e-1,
202
+ -1.2699786326594923e-1, -2.8953677269081528e-10, 3.3125776278259863e-2, -2.3274087021036101e-2,
203
+ 8.0399993503648882e-3, -1.177805216235265e-9, -1.8321624891071668e-3, 1.2108282933588665e-3,
204
+ -3.9479941246822517e-4,
205
+ ],
206
+ [
207
+ 7.389033153567425e+1, -1.5680141270402273e+2, 1.322177542759164e+2, 1.3692876877324546e-2,
208
+ -1.2366496885920151e+2, 1.4620689391062729e+2, -8.0365587724865346e+1, -1.1259851148881298e-4,
209
+ 4.0770132196179938e+1, -3.8210340013273034e+1, 1.719522294277362e+1, 9.3519707955168356e-7,
210
+ -6.2716159907747034, 5.1168999071852637, -2.0319658112299095, -4.9507215582761543e-9,
211
+ 5.9626397294332597e-1, -4.4220765337238094e-1, 1.6079998700166273e-1, -2.4733786203223402e-8,
212
+ -4.0307574759979762e-2, 2.7849050747097869e-2, -9.4751858992054221e-3, 6.419922235909132e-6,
213
+ 2.1250180774699461e-3,
214
+ ],
215
+ [
216
+ 2.1216837098382522e+2, 1.3107863022633868e+1, -4.9698285932871748e+2, 7.3121595266969204e+2,
217
+ -4.8213821720890847e+2, -2.8817248692894889e-2, 3.2616720302947102e+2, -3.4389340280087117e+2,
218
+ 1.7195193870816232e+2, 1.4038077378096158e-4, -7.52594195897599e+1, 6.651969984520934e+1,
219
+ -2.8447519748152462e+1, -7.613702615875391e-7, 9.5402237105304373, -7.5175301113311376,
220
+ 2.8943997568871961, -4.6612194999538201e-7, -8.0615149598794088e-1, 5.8483006570631029e-1,
221
+ -2.0845408972964956e-1, 1.4765818959305817e-4, 5.1000433863753019e-2, -3.3066252141883665e-2,
222
+ 1.5109265210467774e-2,
223
+ ],
224
+ [
225
+ -9.8959643098322368e+2, 2.1925555360905233e+3, -1.9283586782723356e+3, -1.5925738122215253e-1,
226
+ 1.9569985945919857e+3, -2.4072514765081556e+3, 1.3756149959336496e+3, 1.2920735237496668e-3,
227
+ -7.525941715948055e+2, 7.3171668742208716e+2, -3.4137023466220065e+2, -9.9857390260608043e-6,
228
+ 1.3356313181291573e+2, -1.1276295161252794e+2, 4.6310396098204458e+1, -7.9237387133614756e-6,
229
+ -1.4510726927018646e+1, 1.1111771248100563e+1, -4.1690817945270892, 3.1008219800117808e-3,
230
+ 1.1220095449981468, -7.6052379926149916e-1, 3.6262236505085254e-1, 2.216867741940747e-1,
231
+ 4.8683443692930507e-1,
232
+ ],
233
+ ];
@@ -0,0 +1,2 @@
1
+ /** Approximate x with P(a, x) = p (Q = q = 1 - p) */
2
+ export declare function findInverseGamma(a: number, p: number, q: number): number;
@@ -0,0 +1,135 @@
1
+ // Ported from xsf include/xsf/cephes/igami.h (find_inverse_gamma) (xsf commit c6a3afe).
2
+ // Cephes Math Library Release 2.8, Copyright 1984, 1995, 2000 by Stephen L. Moshier.
3
+ // xsf Copyright (c) 2024, SciPy. BSD-3-Clause. See THIRD_PARTY_NOTICES.md.
4
+ //
5
+ // Starting value for the inverse of the incomplete gamma function (DiDonato & Morris 1986, ACM TOMS 12(4)).
6
+ // xsf follows this with three Halley steps, but this library finishes with Newton's method in
7
+ // src/internal/invert.ts, so only the starting value is returned here.
8
+ import { EULER } from "./constants.js";
9
+ import { gamma, lgamma } from "./gamma.js";
10
+ import { polevl } from "./polevl.js";
11
+ function findInverseS(p, q) {
12
+ /* DiDonato & Morris Eq 32 */
13
+ const a = [0.213623493715853, 4.28342155967104, 11.6616720288968, 3.31125922108741];
14
+ const b = [0.3611708101884203e-1, 1.27364489782223, 6.40691597760039, 6.61053765625462, 1];
15
+ const t = p < 0.5 ? Math.sqrt(-2 * Math.log(p)) : Math.sqrt(-2 * Math.log(q));
16
+ const s = t - polevl(t, a) / polevl(t, b);
17
+ return p < 0.5 ? -s : s;
18
+ }
19
+ function didonatoSN(a, x, N, tolerance) {
20
+ /* DiDonato & Morris Eq 34 */
21
+ let sum = 1;
22
+ if (N >= 1) {
23
+ let partial = x / (a + 1);
24
+ sum += partial;
25
+ for (let i = 2; i <= N; ++i) {
26
+ partial *= x / (a + i);
27
+ sum += partial;
28
+ if (partial < tolerance)
29
+ break;
30
+ }
31
+ }
32
+ return sum;
33
+ }
34
+ /* DiDonato & Morris Eq 25 */
35
+ function eq25(a, y) {
36
+ const c1 = (a - 1) * Math.log(y);
37
+ const c1_2 = c1 * c1;
38
+ const c1_3 = c1_2 * c1;
39
+ const c1_4 = c1_2 * c1_2;
40
+ const a_2 = a * a;
41
+ const a_3 = a_2 * a;
42
+ const c2 = (a - 1) * (1 + c1);
43
+ const c3 = (a - 1) * (-(c1_2 / 2) + (a - 2) * c1 + (3 * a - 5) / 2);
44
+ const c4 = (a - 1) * (c1_3 / 3 - ((3 * a - 5) * c1_2) / 2 + (a_2 - 6 * a + 7) * c1 + (11 * a_2 - 46 * a + 47) / 6);
45
+ const c5 = (a - 1) *
46
+ (-(c1_4 / 4) +
47
+ ((11 * a - 17) * c1_3) / 6 +
48
+ (-3 * a_2 + 13 * a - 13) * c1_2 +
49
+ ((2 * a_3 - 25 * a_2 + 72 * a - 61) * c1) / 2 +
50
+ (25 * a_3 - 195 * a_2 + 477 * a - 379) / 12);
51
+ const y_2 = y * y;
52
+ const y_3 = y_2 * y;
53
+ const y_4 = y_2 * y_2;
54
+ return y + c1 + c2 / y + c3 / y_2 + c4 / y_3 + c5 / y_4;
55
+ }
56
+ /** Approximate x with P(a, x) = p (Q = q = 1 - p) */
57
+ export function findInverseGamma(a, p, q) {
58
+ if (a === 1)
59
+ return q > 0.9 ? -Math.log1p(-p) : -Math.log(q);
60
+ if (a < 1) {
61
+ const g = gamma(a);
62
+ const b = q * g;
63
+ if (b > 0.6 || (b >= 0.45 && a >= 0.3)) {
64
+ /* DiDonato & Morris Eq 21 */
65
+ const u = b * q > 1e-8 && q > 1e-5 ? Math.pow(p * g * a, 1 / a) : Math.exp(-q / a - EULER);
66
+ return u / (1 - u / (a + 1));
67
+ }
68
+ if (a < 0.3 && b >= 0.35) {
69
+ /* DiDonato & Morris Eq 22 */
70
+ const t = Math.exp(-EULER - b);
71
+ const u = t * Math.exp(t);
72
+ return t * Math.exp(u);
73
+ }
74
+ if (b > 0.15 || a >= 0.3) {
75
+ /* DiDonato & Morris Eq 23 */
76
+ const y = -Math.log(b);
77
+ const u = y - (1 - a) * Math.log(y);
78
+ return y - (1 - a) * Math.log(u) - Math.log(1 + (1 - a) / (1 + u));
79
+ }
80
+ if (b > 0.1) {
81
+ /* DiDonato & Morris Eq 24 */
82
+ const y = -Math.log(b);
83
+ const u = y - (1 - a) * Math.log(y);
84
+ return (y -
85
+ (1 - a) * Math.log(u) -
86
+ Math.log((u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) / (u * u + (5 - a) * u + 2)));
87
+ }
88
+ return eq25(a, -Math.log(b));
89
+ }
90
+ /* DiDonato and Morris Eq 31 */
91
+ let s = findInverseS(p, q);
92
+ const s_2 = s * s;
93
+ const s_3 = s_2 * s;
94
+ const s_4 = s_2 * s_2;
95
+ const s_5 = s_4 * s;
96
+ const ra = Math.sqrt(a);
97
+ let w = a + s * ra + (s_2 - 1) / 3;
98
+ w += (s_3 - 7 * s) / (36 * ra);
99
+ w -= (3 * s_4 + 7 * s_2 - 16) / (810 * a);
100
+ w += (9 * s_5 + 256 * s_3 - 433 * s) / (38880 * a * ra);
101
+ if (a >= 500 && Math.abs(1 - w / a) < 1e-6)
102
+ return w;
103
+ if (p > 0.5) {
104
+ if (w < 3 * a)
105
+ return w;
106
+ const D = Math.max(2, a * (a - 1));
107
+ const lb = Math.log(q) + lgamma(a);
108
+ if (lb < -D * 2.3)
109
+ return eq25(a, -lb);
110
+ /* DiDonato and Morris Eq 33 */
111
+ const u = -lb + (a - 1) * Math.log(w) - Math.log(1 + (1 - a) / (1 + w));
112
+ return -lb + (a - 1) * Math.log(u) - Math.log(1 + (1 - a) / (1 + u));
113
+ }
114
+ let z = w;
115
+ const ap1 = a + 1;
116
+ const ap2 = a + 2;
117
+ if (w < 0.15 * ap1) {
118
+ /* DiDonato and Morris Eq 35 */
119
+ const v = Math.log(p) + lgamma(ap1);
120
+ z = Math.exp((v + w) / a);
121
+ s = Math.log1p((z / ap1) * (1 + z / ap2));
122
+ z = Math.exp((v + z - s) / a);
123
+ s = Math.log1p((z / ap1) * (1 + z / ap2));
124
+ z = Math.exp((v + z - s) / a);
125
+ s = Math.log1p((z / ap1) * (1 + (z / ap2) * (1 + z / (a + 3))));
126
+ z = Math.exp((v + z - s) / a);
127
+ }
128
+ if (z <= 0.01 * ap1 || z > 0.7 * ap1)
129
+ return z;
130
+ /* DiDonato and Morris Eq 36 */
131
+ const ls = Math.log(didonatoSN(a, z, 100, 1e-4));
132
+ const v = Math.log(p) + lgamma(ap1);
133
+ z = Math.exp((v + z - ls) / a);
134
+ return z * (1 - (a * Math.log(z) - z - v + ls) / (a - z));
135
+ }
@@ -0,0 +1,25 @@
1
+ import { type DD } from "./dd.js";
2
+ /**
3
+ * Regularized incomplete beta function: I_x(a, b) if lower, otherwise 1 - I_x(a, b).
4
+ * The caller passes xc = 1 - x accurately. Assumes a, b > 0 and 0 <= x <= 1.
5
+ *
6
+ * The requested tail is computed by the first applicable subtraction-free method in this order:
7
+ * 1. series in that tail's frame 2. complement of the series in the opposite frame (pseriesComplement)
8
+ * 3. continued fraction in that tail's frame 4. 1 - (other side) from the continued fraction in the opposite frame
9
+ * (the lower frame is (a, b, x); the upper is (b, a, 1-x) via 1 - I_x(a,b) = I_{1-x}(b, a))
10
+ */
11
+ export declare function betaInc(a: number, b: number, x: number, xc: number, lower: boolean, log: boolean): number;
12
+ /**
13
+ * Version of betaInc taking x and 1 - x in double-double.
14
+ * When x is itself computed, as in n/(n + t^2) for the t distribution, its rounding (0.5 ulp) is amplified
15
+ * a times (3e-14 at a = 500), so the caller builds it in double-double and passes it as is.
16
+ */
17
+ export declare function betaIncDD(a: number, b: number, xd: DD, xcd: DD, lower: boolean, log: boolean): number;
18
+ /**
19
+ * Return both the log and the linear value of betaIncDD from a single core computation ([log, linear]).
20
+ * Used by the Newton iteration for quantiles, which needs both the log and linear distribution function at the same x.
21
+ * The values are bit-identical to betaIncDD(..., true) and betaIncDD(..., false) respectively
22
+ */
23
+ export declare function betaIncBothDD(a: number, b: number, xd: DD, xcd: DD, lower: boolean): [number, number];
24
+ /** Version of betaInc returning both (takes x and 1 - x in double precision, like betaInc) */
25
+ export declare function betaIncBoth(a: number, b: number, x: number, xc: number, lower: boolean): [number, number];