repl.txt (4916B)
1 2 {{alias}}( x, y, sigmax, sigmay[, options] ) 3 Computes a two-sample z-test. 4 5 By default, the function performs a two-sample z-test for the null 6 hypothesis that the data in arrays or typed arrays `x` and `y` is 7 independently drawn from normal distributions with equal means and known 8 standard deviations `sigmax` and `sigmay`. 9 10 The returned object comes with a `.print()` method which when invoked will 11 print a formatted output of the results of the hypothesis test. 12 13 Parameters 14 ---------- 15 x: Array<number> 16 First data array. 17 18 y: Array<number> 19 Second data array. 20 21 sigmax: number 22 Known standard deviation of first group. 23 24 sigmay: number 25 Known standard deviation of second group. 26 27 options: Object (optional) 28 Options. 29 30 options.alpha: number (optional) 31 Number in the interval `[0,1]` giving the significance level of the 32 hypothesis test. Default: `0.05`. 33 34 options.alternative: string (optional) 35 Either `two-sided`, `less` or `greater`. Indicates whether the 36 alternative hypothesis is that `x` has a larger mean than `y` 37 (`greater`), `x` has a smaller mean than `y` (`less`) or the means are 38 the same (`two-sided`). Default: `'two-sided'`. 39 40 options.difference: number (optional) 41 Number denoting the difference in means under the null hypothesis. 42 Default: `0`. 43 44 Returns 45 ------- 46 out: Object 47 Test result object. 48 49 out.alpha: number 50 Used significance level. 51 52 out.rejected: boolean 53 Test decision. 54 55 out.pValue: number 56 p-value of the test. 57 58 out.statistic: number 59 Value of test statistic. 60 61 out.ci: Array<number> 62 1-alpha confidence interval for the mean. 63 64 out.nullValue: number 65 Assumed difference in means under H0. 66 67 out.xmean: number 68 Sample mean of `x`. 69 70 out.ymean: number 71 Sample mean of `y`. 72 73 out.alternative: string 74 Alternative hypothesis (`two-sided`, `less` or `greater`). 75 76 out.method: string 77 Name of test. 78 79 out.print: Function 80 Function to print formatted output. 81 82 Examples 83 -------- 84 // Drawn from Normal(0,2): 85 > var x = [ -0.21, 0.14, 1.65, 2.11, -1.86, -0.29, 1.48, 0.81, 0.86, 1.04 ]; 86 87 // Drawn from Normal(1,2): 88 > var y = [ -1.53, -2.93, 2.34, -1.15, 2.7, -0.12, 4.22, 1.66, 3.43, 4.66 ]; 89 > var out = {{alias}}( x, y, 2.0, 2.0 ) 90 { 91 alpha: 0.05, 92 rejected: false, 93 pValue: ~0.398, 94 statistic: ~-0.844 95 ci: [ ~-2.508, ~0.988 ], 96 alternative: 'two-sided', 97 method: 'Two-sample z-test', 98 nullValue: 0, 99 xmean: ~0.573, 100 ymean: ~1.328 101 } 102 103 // Print table output: 104 > var table = out.print() 105 Two-sample z-test 106 107 Alternative hypothesis: True difference in means is not equal to 0 108 109 pValue: 0.3986 110 statistic: -0.8441 111 95% confidence interval: [-2.508,0.998] 112 113 Test Decision: Fail to reject null in favor of alternative at 5% 114 significance level 115 116 // Choose a different significance level than `0.05`: 117 > out = {{alias}}( x, y, 2.0, 2.0, { 'alpha': 0.4 }); 118 > table = out.print() 119 Two-sample z-test 120 121 Alternative hypothesis: True difference in means is not equal to 0 122 123 pValue: 0.3986 124 statistic: -0.8441 125 60% confidence interval: [-1.5078,-0.0022] 126 127 Test Decision: Reject null in favor of alternative at 40% significance level 128 129 // Perform one-sided tests: 130 > out = {{alias}}( x, y, 2.0, 2.0, { 'alternative': 'less' }); 131 > table = out.print() 132 Two-sample z-test 133 134 Alternative hypothesis: True difference in means is less than 0 135 136 pValue: 0.1993 137 statistic: -0.8441 138 95% confidence interval: [-Infinity,0.7162] 139 140 Test Decision: Fail to reject null in favor of alternative at 5% 141 significance level 142 143 144 > out = {{alias}}( x, y, 2.0, 2.0, { 'alternative': 'greater' }); 145 > table = out.print() 146 Two-sample z-test 147 148 Alternative hypothesis: True difference in means is greater than 0 149 150 pValue: 0.8007 151 statistic: -0.8441 152 95% confidence interval: [-2.2262,Infinity] 153 154 Test Decision: Fail to reject null in favor of alternative at 5% 155 significance level 156 157 // Test for a difference in means besides zero: 158 > var rnorm = {{alias:@stdlib/random/base/normal}}.factory({ 'seed': 372 }); 159 > x = new Array( 100 ); 160 > for ( i = 0; i < x.length; i++ ) { 161 ... x[ i ] = rnorm( 2.0, 1.0 ); 162 ... } 163 > y = new Array( 100 ); 164 ... for ( i = 0; i < x.length; i++ ) { 165 ... y[ i ] = rnorm( 0.0, 2.0 ); 166 ... } 167 > out = {{alias}}( x, y, 1.0, 2.0, { 'difference': 2.0 }) 168 { 169 rejected: false, 170 pValue: ~0.35, 171 statistic: ~-0.935 172 ci: [ ~1.353, ~2.229 ], 173 // ... 174 } 175 176 See Also 177 -------- 178