time-to-botec

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

repl.txt (5437B)


      1 
      2 {{alias}}( x[, y][, options] )
      3     Computes a one-sample or paired Wilcoxon signed rank test.
      4 
      5     When no `y` is supplied, the function performs a one-sample  Wilcoxon signed
      6     rank test for the null hypothesis that the data is drawn from a symmetric
      7     distribution around zero.
      8 
      9     When `y` is supplied, the function tests whether the
     10     differences `x - y` come from a symmetric distribution around zero.
     11 
     12     If `x` has less than fifty elements, an exact p-value is computed if there
     13     are no zero values or ties. Otherwise, a normal approximation is used.
     14 
     15     The returned object comes with a `.print()` method which when invoked will
     16     print a formatted output of the results of the hypothesis test.
     17 
     18     Parameters
     19     ----------
     20     x: Array<number>|TypedArray
     21         Data array.
     22 
     23     y: Array<number>|TypedArray (optional)
     24         Paired data array.
     25 
     26     options: Object (optional)
     27         Options.
     28 
     29     options.alpha: number (optional)
     30         Number in the interval `[0,1]` giving the significance level of the
     31         hypothesis test. Default: `0.05`.
     32 
     33     options.alternative: string (optional)
     34         Indicates whether the alternative hypothesis is that the mean of `x` is
     35         larger than `mu` (`greater`), smaller than `mu` (`less`), or equal to
     36         `mu` (`two-sided`). Default: `'two-sided'`.
     37 
     38     options.correction: boolean (optional)
     39         Determines whether to apply continuity correction adjusting the Wilcoxon
     40         rank statistic by 0.5 towards the mean when using the normal
     41         approximation. Default: `true`.
     42 
     43     options.exact: boolean (optional)
     44         Determines whether to force use of the exact distribution instead of a
     45         normal approximation when there are more than fifty data points.
     46         Default: `false`.
     47 
     48     options.mu: number (optional)
     49         Hypothesized true location under the null hypothesis. Set this option to
     50         test whether the data comes from a distribution with the specified `mu`.
     51         Default: `0`.
     52 
     53     options.zeroMethod: string (optional)
     54         Method governing how zero-differences are handled (`pratt`, `wilcox`, or
     55         `zsplit`). When set to `pratt`, differences of zero are used to
     56         calculate ranks but their ranks are then dropped. When set to `wilcox`,
     57         all zero-differences are discarded. When set to `zsplit`, differences of
     58         zero are used to rank and their ranks are then split between positive
     59         and negative ones. Default: `'wilcox'`.
     60 
     61     Returns
     62     -------
     63     out: Object
     64         Test result object.
     65 
     66     out.alpha: number
     67         Used significance level.
     68 
     69     out.rejected: boolean
     70         Test decision.
     71 
     72     out.pValue: number
     73         p-value of the test.
     74 
     75     out.statistic: number
     76         Value of test statistic.
     77 
     78     out.nullValue: number
     79         Assumed location parameter under H0.
     80 
     81     out.alternative: string
     82         Alternative hypothesis (`two-sided`, `less` or `greater`).
     83 
     84     out.method: string
     85         Name of test.
     86 
     87     out.print: Function
     88         Function to print formatted output.
     89 
     90     Examples
     91     --------
     92     // One-sample test:
     93     > var arr = [ 6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75 ];
     94     > var out = {{alias}}( x )
     95     {
     96         'rejected': true,
     97         'alpha': 0.05,
     98         'pValue': 0.04125976562499978,
     99         'statistic': 96
    100         // ...
    101     }
    102 
    103     // Paired test:
    104     > runif = {{alias:@stdlib/random/base/discrete-uniform}}.factory( 1, 5, { 'seed': 786 });
    105     > var x = new Array( 100 );
    106     > var y = new Array( 100 );
    107     > for ( i = 0; i < x.length; i++ ) {
    108     ...     x[ i ] = runif();
    109     ...     y[ i ] = runif();
    110     ... }
    111     > out = {{alias}}( x, y )
    112     {
    113         'rejected': false,
    114         'alpha': 0.05,
    115         'pValue': 0.21759090963694638,
    116         'statistic': 2702.5,
    117         // ...
    118     }
    119 
    120     // Print formatted output:
    121     > var table = out.print()
    122     Paired Wilcoxon signed rank test
    123 
    124     Alternative hypothesis: Median of the difference `x - y` is not equal to 0
    125 
    126         pValue: 0.2176
    127         statistic: 2702.5
    128 
    129     Test Decision: Fail to reject null in favor of alternative at 5% significance level
    130 
    131 
    132     // Choose custom significance level:
    133     > out = {{alias}}( arr, { 'alpha': 0.01 });
    134     > table = out.print()
    135     One-Sample Wilcoxon signed rank test
    136 
    137     Alternative hypothesis: Median of `x` is not equal to 0
    138 
    139         pValue: 0.0413
    140         statistic: 96
    141 
    142     Test Decision: Fail to reject null in favor of alternative at 1% significance level
    143 
    144 
    145     // Test for a median equal to ten:
    146     > out = {{alias}}( arr, { 'mu': 10 })
    147     {
    148         'rejected': false,
    149         'alpha': 0.05,
    150         'pValue': 0.11169650413134602,
    151         'statistic': 88.5,
    152         'nullValue': 10,
    153         // ...
    154     }
    155 
    156     // Perform one-sided tests:
    157     > out = {{alias}}( arr, { 'alternative': 'less' });
    158     > table = out.print()
    159     One-Sample Wilcoxon signed rank test
    160 
    161     Alternative hypothesis: Median of `x` is less than 0
    162 
    163         pValue: 0.9823
    164         statistic: 96
    165 
    166     Test Decision: Fail to reject null in favor of alternative at 5% significance level
    167 
    168 
    169     > out = {{alias}}( arr, { 'alternative': 'greater' });
    170     > table = out.print()
    171     One-Sample Wilcoxon signed rank test
    172 
    173     Alternative hypothesis: Median of `x` is greater than 0
    174 
    175         pValue: 0.0206
    176         statistic: 96
    177 
    178     Test Decision: Reject null in favor of alternative at 5% significance level
    179 
    180     See Also
    181     --------
    182