README.md (3085B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # betaincinv 22 23 > Inverse of the [incomplete beta function][incomplete-beta-function]. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var betaincinv = require( '@stdlib/math/base/special/betaincinv' ); 37 ``` 38 39 #### betaincinv( p, a, b\[, upper] ) 40 41 Inverts the regularized [incomplete beta function][incomplete-beta-function]. Contrary to the more commonly used definition, in this implementation the first parameter is the probability `p` and the second and third parameter are `a` and `b`. By default, the function inverts the _lower_ regularized [incomplete beta function][incomplete-beta-function]. To invert the _upper_ function instead, set the `upper` argument to `true`. 42 43 ```javascript 44 var y = betaincinv( 0.2, 3.0, 3.0 ); 45 // returns ~0.327 46 47 y = betaincinv( 0.4, 3.0, 3.0 ); 48 // returns ~0.446 49 50 y = betaincinv( 0.4, 3.0, 3.0, true ); 51 // returns ~0.554 52 53 y = betaincinv( 0.4, 1.0, 6.0 ); 54 // returns ~0.082 55 56 y = betaincinv( 0.8, 1.0, 6.0 ); 57 // returns ~0.235 58 ``` 59 60 If provided `NaN` as any argument, the function returns `NaN`. 61 62 ```javascript 63 var y = betaincinv( NaN, 1.0, 1.0 ); 64 // returns NaN 65 66 y = betaincinv( 0.5, NaN, 1.0 ); 67 // returns NaN 68 69 y = betaincinv( 0.5, 1.0, NaN ); 70 // returns NaN 71 ``` 72 73 If provided a value outside `[0,1]` for `p`, the function returns `NaN`. 74 75 ```javascript 76 var y = betaincinv( 1.2, 1.0, 1.0 ); 77 // returns NaN 78 79 y = betaincinv( -0.5, 1.0, 1.0 ); 80 // returns NaN 81 ``` 82 83 If provided a nonpositive `a`, the function returns `NaN`. 84 85 ```javascript 86 var y = betaincinv( 0.5, -2.0, 2.0 ); 87 // returns NaN 88 89 y = betaincinv( 0.5, 0.0, 2.0 ); 90 // returns NaN 91 ``` 92 93 If provided a nonpositive `b`, the function returns `NaN`. 94 95 ```javascript 96 var y = betaincinv( 0.5, 2.0, -2.0 ); 97 // returns NaN 98 99 y = betaincinv( 0.5, 2.0, 0.0 ); 100 // returns NaN 101 ``` 102 103 </section> 104 105 <!-- /.usage --> 106 107 <section class="examples"> 108 109 ## Examples 110 111 <!-- eslint no-undef: "error" --> 112 113 ```javascript 114 var randu = require( '@stdlib/random/base/randu' ); 115 var betaincinv = require( '@stdlib/math/base/special/betaincinv' ); 116 117 var i; 118 var p; 119 var a; 120 var b; 121 122 for ( i = 0; i < 100; i++ ) { 123 p = randu(); 124 a = randu() * 10.0; 125 b = randu() * 10.0; 126 console.log( 'p: %d, \t a: %d, \t b: %d, \t f(p,a,b): %d', p.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), betaincinv( p, a, b ) ); 127 } 128 ``` 129 130 </section> 131 132 <!-- /.examples --> 133 134 <section class="links"> 135 136 [incomplete-beta-function]: https://en.wikipedia.org/wiki/Incomplete_beta_function 137 138 </section> 139 140 <!-- /.links -->