repl.txt (5045B)
1 2 {{alias}}( x[, y][, options] ) 3 Computes a one-sample or paired Student's t test. 4 5 When no `y` is supplied, the function performs a one-sample t-test for the 6 null hypothesis that the data in array or typed array `x` is drawn from a 7 normal distribution with mean zero and unknown variance. 8 9 When array or typed array `y` is supplied, the function tests whether the 10 differences `x - y` come from a normal distribution with mean zero and 11 unknown variance via the paired t-test. 12 13 The returned object comes with a `.print()` method which when invoked will 14 print a formatted output of the results of the hypothesis test. 15 16 Parameters 17 ---------- 18 x: Array<number> 19 Data array. 20 21 y: Array<number> (optional) 22 Paired data array. 23 24 options: Object (optional) 25 Options. 26 27 options.alpha: number (optional) 28 Number in the interval `[0,1]` giving the significance level of the 29 hypothesis test. Default: `0.05`. 30 31 options.alternative: string (optional) 32 Indicates whether the alternative hypothesis is that the mean of `x` is 33 larger than `mu` (`greater`), smaller than `mu` (`less`) or equal to 34 `mu` (`two-sided`). Default: `'two-sided'`. 35 36 options.mu: number (optional) 37 Hypothesized true mean under the null hypothesis. Set this option to 38 test whether the data comes from a distribution with the specified `mu`. 39 Default: `0`. 40 41 Returns 42 ------- 43 out: Object 44 Test result object. 45 46 out.alpha: number 47 Used significance level. 48 49 out.rejected: boolean 50 Test decision. 51 52 out.pValue: number 53 p-value of the test. 54 55 out.statistic: number 56 Value of test statistic. 57 58 out.ci: Array<number> 59 1-alpha confidence interval for the mean. 60 61 out.nullValue: number 62 Assumed mean under H0 (or difference in means when `y` is supplied). 63 64 out.alternative: string 65 Alternative hypothesis (`two-sided`, `less` or `greater`). 66 67 out.df: number 68 Degrees of freedom. 69 70 out.mean: number 71 Sample mean of `x` or `x - y`, respectively. 72 73 out.sd: number 74 Standard error of the mean. 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 // One-sample t-test: 85 > var rnorm = {{alias:@stdlib/random/base/normal}}.factory( 0.0, 2.0, { 'seed': 5776 }); 86 > var x = new Array( 100 ); 87 > for ( var i = 0; i < x.length; i++ ) { 88 ... x[ i ] = rnorm(); 89 ... } 90 > var out = {{alias}}( x ) 91 { 92 rejected: false, 93 pValue: ~0.722, 94 statistic: ~0.357, 95 ci: [~-0.333,~0.479], 96 // ... 97 } 98 99 // Paired t-test: 100 > rnorm = {{alias:@stdlib/random/base/normal}}.factory( 1.0, 2.0, { 'seed': 786 }); 101 > x = new Array( 100 ); 102 > var y = new Array( 100 ); 103 > for ( i = 0; i < x.length; i++ ) { 104 ... x[ i ] = rnorm(); 105 ... y[ i ] = rnorm(); 106 ... } 107 > out = {{alias}}( x, y ) 108 { 109 rejected: false, 110 pValue: ~0.191, 111 statistic: ~1.315, 112 ci: [ ~-0.196, ~0.964 ], 113 // ... 114 } 115 116 // Print formatted output: 117 > var table = out.print() 118 Paired t-test 119 120 Alternative hypothesis: True difference in means is not equal to 0 121 122 pValue: 0.1916 123 statistic: 1.3148 124 df: 99 125 95% confidence interval: [-0.1955,0.9635] 126 127 Test Decision: Fail to reject null in favor of alternative at 5% 128 significance level 129 130 // Choose custom significance level: 131 > arr = [ 2, 4, 3, 1, 0 ]; 132 > out = {{alias}}( arr, { 'alpha': 0.01 }); 133 > table = out.print() 134 One-sample t-test 135 136 Alternative hypothesis: True mean is not equal to 0 137 138 pValue: 0.0474 139 statistic: 2.8284 140 df: 4 141 99% confidence interval: [-1.2556,5.2556] 142 143 Test Decision: Fail to reject null in favor of alternative at 1% 144 significance level 145 146 // Test for a mean equal to five: 147 > var arr = [ 4, 4, 6, 6, 5 ]; 148 > out = {{alias}}( arr, { 'mu': 5 }) 149 { 150 rejected: false, 151 pValue: 1, 152 statistic: 0, 153 ci: [ ~3.758, ~6.242 ], 154 // ... 155 } 156 157 // Perform one-sided tests: 158 > arr = [ 4, 4, 6, 6, 5 ]; 159 > out = {{alias}}( arr, { 'alternative': 'less' }); 160 > table = out.print() 161 One-sample t-test 162 163 Alternative hypothesis: True mean is less than 0 164 165 pValue: 0.9998 166 statistic: 11.1803 167 df: 4 168 95% confidence interval: [-Infinity,5.9534] 169 170 Test Decision: Fail to reject null in favor of alternative at 5% 171 significance level 172 173 > out = {{alias}}( arr, { 'alternative': 'greater' }); 174 > table = out.print() 175 One-sample t-test 176 177 Alternative hypothesis: True mean is greater than 0 178 179 pValue: 0.0002 180 statistic: 11.1803 181 df: 4 182 95% confidence interval: [4.0466,Infinity] 183 184 Test Decision: Reject null in favor of alternative at 5% significance level 185 186 See Also 187 -------- 188