repl.txt (4645B)
1 2 {{alias}}( x, y[, ...params][, options] ) 3 Computes a Kolmogorov-Smirnov goodness-of-fit test. 4 5 For a numeric array or typed array `x`, a Kolmogorov-Smirnov goodness-of-fit 6 is computed for the null hypothesis that the values of `x` come from the 7 distribution specified by `y`. `y` can be either a string with the name of 8 the distribution to test against, or a function. 9 10 In the latter case, `y` is expected to be the cumulative distribution 11 function (CDF) of the distribution to test against, with its first parameter 12 being the value at which to evaluate the CDF and the remaining parameters 13 constituting the parameters of the distribution. The parameters of the 14 distribution are passed as additional arguments after `y` from `kstest` to 15 the chosen CDF. The function returns an object holding the calculated test 16 statistic `statistic` and the `pValue` of the test. 17 18 The returned object comes with a `.print()` method which when invoked will 19 print a formatted output of the hypothesis test results. 20 21 Parameters 22 ---------- 23 x: Array<number> 24 Input array holding numeric values. 25 26 y: Function|string 27 Either a CDF function or a string denoting the name of a distribution. 28 29 params: ...number (optional) 30 Distribution parameters passed to reference CDF. 31 32 options: Object (optional) 33 Function options. 34 35 options.alpha: number (optional) 36 Number in the interval `[0,1]` giving the significance level of the 37 hypothesis test. Default: `0.05`. 38 39 options.sorted: boolean (optional) 40 Boolean indicating if the input array is already in sorted order. 41 Default: `false`. 42 43 options.alternative: string (optional) 44 Either `two-sided`, `less` or `greater`. Indicates whether the 45 alternative hypothesis is that the true distribution of `x` is not equal 46 to the reference distribution specified by `y` (`two-sided`), whether it 47 is `less` than the reference distribution or `greater` than the 48 reference distribution. Default: `'two-sided'`. 49 50 Returns 51 ------- 52 out: Object 53 Test result object. 54 55 out.alpha: number 56 Used significance level. 57 58 out.rejected: boolean 59 Test decision. 60 61 out.pValue: number 62 p-value of the test. 63 64 out.statistic: number 65 Value of test statistic. 66 67 out.alternative: string 68 Used test alternative. Either `two-sided`, `less` or `greater`. 69 70 out.method: string 71 Name of test. 72 73 out.print: Function 74 Function to print formatted output. 75 76 Examples 77 -------- 78 // Verify that data is drawn from a normal distribution: 79 > var rnorm = {{alias:@stdlib/random/base/normal}}.factory({ 'seed': 4839 }); 80 > var x = new Array( 100 ); 81 > for ( var i = 0; i < 100; i++ ) { x[ i ] = rnorm( 3.0, 1.0 ); } 82 83 // Test against N(0,1) 84 > var out = {{alias}}( x, 'normal', 0.0, 1.0 ) 85 { pValue: 0.0, statistic: 0.847, ... } 86 87 // Test against N(3,1) 88 > out = {{alias}}( x, 'normal', 3.0, 1.0 ) 89 { pValue: 0.6282, statistic: 0.0733, ... } 90 91 // Verify that data is drawn from a uniform distribution: 92 > runif = {{alias:@stdlib/random/base/uniform}}.factory( 0.0, 1.0, { 'seed': 8798 }) 93 > x = new Array( 100 ); 94 > for ( i = 0; i < x.length; i++ ) { x[ i ] = runif(); } 95 > out = {{alias}}( x, 'uniform', 0.0, 1.0 ) 96 { pValue: ~0.703, statistic: ~0.069, ... } 97 98 // Print output: 99 > out.print() 100 Kolmogorov-Smirnov goodness-of-fit test. 101 102 Null hypothesis: the CDF of `x` is equal equal to the reference CDF. 103 104 pValue: 0.7039 105 statistic: 0.0689 106 107 Test Decision: Fail to reject null in favor of alternative at 5% 108 significance level 109 110 // Set custom significance level: 111 > out = {{alias}}( x, 'uniform', 0.0, 1.0, { 'alpha': 0.1 }) 112 { pValue: ~0.7039, statistic: ~0.069, ... } 113 114 // Carry out one-sided hypothesis tests: 115 > runif = {{alias:@stdlib/random/base/uniform}}.factory( 0.0, 1.0, { 'seed': 8798 }); 116 > x = new Array( 100 ); 117 > for ( i = 0; i < x.length; i++ ) { x[ i ] = runif(); } 118 > out = {{alias}}( x, 'uniform', 0.0, 1.0, { 'alternative': 'less' }) 119 { pValue: ~0.358, statistic: ~0.07, ... } 120 > out = {{alias}}( x, 'uniform', 0.0, 1.0, { 'alternative': 'greater' }) 121 { pValue: ~0.907, statistic: ~0.02, ... } 122 123 // Set `sorted` option to true when data is in increasing order: 124 > x = [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 ]; 125 > out = {{alias}}( x, 'uniform', 0.0, 1.0, { 'sorted': true }) 126 { pValue: ~1, statistic: 0.1, ... } 127 128 See Also 129 -------- 130