time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (5875B)


      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 # Binomial Test
     22 
     23 > Exact test for the success probability in a Bernoulli experiment.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var binomialTest = require( '@stdlib/stats/binomial-test' );
     31 ```
     32 
     33 #### binomialTest( x\[, n]\[, opts] )
     34 
     35 When supplied nonnegative integers `x` (number of successes in a Bernoulli experiment) and `n` (total number of trials), the function computes an exact test for the success probability in a Bernoulli experiment. Alternatively, `x` may be a two-element array containing the number of successes and failures, respectively.
     36 
     37 ```javascript
     38 var out = binomialTest( 550, 1000 );
     39 /* returns
     40     {
     41         'rejected': true,
     42         'pValue': ~0.001,
     43         'statistic': 0.55,
     44         'ci': [ ~0.519, ~0.581 ],
     45         // ...
     46     }
     47 */
     48 
     49 out = binomialTest( [ 550, 450 ] );
     50 /* returns
     51     {
     52         'rejected': true,
     53         'pValue': ~0.001,
     54         'statistic': 0.55,
     55         'ci': [ ~0.519, ~0.581 ],
     56         // ...
     57     }
     58 */
     59 ```
     60 
     61 The returned object comes with a `.print()` method which when invoked will print a formatted output of the results of the hypothesis test. `print` accepts a `digits` option that controls the number of decimal digits displayed for the outputs and a `decision` option, which when set to `false` will hide the test decision.
     62 
     63 <!-- run-disable -->
     64 
     65 ```javascript
     66 console.log( out.print() );
     67 /* e.g., =>
     68     Exact binomial test
     69 
     70     Alternative hypothesis: True correlation coefficient is not equal to 0.5
     71 
     72         pValue: 0.0017
     73         statistic: 0.55
     74         95% confidence interval: [0.5186,0.5811]
     75 
     76     Test Decision: Reject null in favor of alternative at 5% significance level
     77 */
     78 ```
     79 
     80 The function accepts the following `options`:
     81 
     82 -   **alpha**: `number` in the interval `[0,1]` giving the significance level of the hypothesis test. Default: `0.05`.
     83 -   **alternative**: Either `two-sided`, `less` or `greater`. Indicates whether the alternative hypothesis is that the true ratio of variances is greater than one (`greater`), smaller than one (`less`), or that the variances are the same (`two-sided`). Default: `two-sided`.
     84 -   **p**: success `probability` under the null hypothesis. Default: `0.5`.
     85 
     86 By default, the hypothesis test is carried out at a significance level of `0.05`. To choose a different significance level, set the `alpha` option.
     87 
     88 ```javascript
     89 var out = binomialTest( 59, 100, {
     90     'alpha': 0.1
     91 });
     92 /* returns
     93     {
     94         'rejected': true,
     95         'pValue': ~0.089,
     96         'statistic': 0.59,
     97         'ci': [ ~0.487, ~0.687 ],
     98         // ...
     99     }
    100 */
    101 ```
    102 
    103 By default, a two-sided test is performed. To perform either of the one-sided tests, set the `alternative` option to `less` or `greater`.
    104 
    105 ```javascript
    106 out = binomialTest( 550, 1000, {
    107     'alternative': 'greater'
    108 });
    109 table = out.print();
    110 /** e.g., returns
    111     Exact binomial test
    112 
    113     Alternative hypothesis: True correlation coefficient is greater than 0.5
    114 
    115         pValue: 0.0009
    116         statistic: 0.55
    117         95% confidence interval: [0.5235,1]
    118 
    119     Test Decision: Reject null in favor of alternative at 5% significance level
    120 */
    121 
    122 out = binomialTest( 550, 1000, {
    123     'alternative': 'less'
    124 });
    125 table = out.print();
    126 /* e.g., returns
    127     Exact binomial test
    128 
    129     Alternative hypothesis: True correlation coefficient is less than 0.5
    130 
    131         pValue: 0.9993
    132         statistic: 0.55
    133         95% confidence interval: [0,0.5762]
    134 
    135     Test Decision: Fail to reject null in favor of alternative at 5% significance level
    136 */
    137 ```
    138 
    139 To test whether the success probability in the population is equal to some other value than `0.5`, set the `p` option.
    140 
    141 ```javascript
    142 var out = binomialTest( 23, 100, {
    143     'p': 0.2
    144 });
    145 /* returns
    146     {
    147         'rejected': false,
    148         'pValue': ~0.453,
    149         'statistic': 0.23,
    150         'ci': [ ~0.152, ~0.325 ],
    151         // ...
    152     }
    153 */
    154 
    155 var table = out.print();
    156 /* e.g., returns
    157     Exact binomial test
    158 
    159     Alternative hypothesis: True correlation coefficient is not equal to 0.2
    160 
    161         pValue: 0.4534
    162         statistic: 0.23
    163         95% confidence interval: [0.1517,0.3249]
    164 
    165     Test Decision: Fail to reject null in favor of alternative at 5% significance level
    166 */
    167 ```
    168 
    169 </section>
    170 
    171 <!-- /.usage -->
    172 
    173 <section class="examples">
    174 
    175 ## Examples
    176 
    177 <!-- eslint no-undef: "error" -->
    178 
    179 ```javascript
    180 var binomialTest = require( '@stdlib/stats/binomial-test' );
    181 
    182 var out = binomialTest( 682, 925 );
    183 /* returns
    184     {
    185         'rejected': true,
    186         'pValue': ~3.544e-49,
    187         'statistic': 0.737,
    188         'ci': [ ~0.708, ~0.765 ],
    189         // ...
    190     }
    191 */
    192 
    193 out = binomialTest( [ 682, 925 - 682 ] );
    194 /* returns
    195     {
    196         'rejected': true,
    197         'pValue': ~3.544e-49,
    198         'statistic': 0.737,
    199         'ci': [ ~0.708, ~0.765 ],
    200         // ...
    201     }
    202 */
    203 
    204 out = binomialTest( 682, 925, {
    205     'p': 0.75,
    206     'alpha': 0.05
    207 });
    208 /* returns
    209     {
    210         'rejected': false,
    211         'pValue': ~0.382
    212         'statistic': 0.737,
    213         'ci': [ ~0.708, ~0.765 ],
    214         // ...
    215     }
    216 */
    217 
    218 out = binomialTest( 21, 40, {
    219     'p': 0.4,
    220     'alternative': 'greater'
    221 });
    222 /* returns
    223     {
    224         'rejected': false,
    225         'pValue': ~0.382,
    226         'statistic': 0.737,
    227         'ci': [ ~0.385, 1.0 ],
    228         // ...
    229     }
    230 */
    231 ```
    232 
    233 </section>
    234 
    235 <!-- /.examples -->
    236 
    237 <section class="links">
    238 
    239 </section>
    240 
    241 <!-- /.links -->