1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
{{alias}}( x, y[, options] )
Computes a two-sample Student's t test.
By default, the function performs a two-sample t-test for the null
hypothesis that the data in arrays or typed arrays `x` and `y` is
independently drawn from normal distributions with equal means.
The returned object comes with a `.print()` method which when invoked will
print a formatted output of the results of the hypothesis test.
Parameters
----------
x: Array<number>
First data array.
y: Array<number>
Second data array.
options: Object (optional)
Options.
options.alpha: number (optional)
Number in the interval `[0,1]` giving the significance level of the
hypothesis test. Default: `0.05`.
options.alternative: string (optional)
Either `two-sided`, `less` or `greater`. Indicates whether the
alternative hypothesis is that `x` has a larger mean than `y`
(`greater`), `x` has a smaller mean than `y` (`less`) or the means are
the same (`two-sided`). Default: `'two-sided'`.
options.difference: number (optional)
Number denoting the difference in means under the null hypothesis.
Default: `0`.
options.variance: string (optional)
String indicating if the test should be conducted under the assumption
that the unknown variances of the normal distributions are `equal` or
`unequal`. As a default choice, the function carries out the Welch test
(using the Satterthwaite approximation for the degrees of freedom),
which does not have the requirement that the variances of the underlying
distributions are equal. If the equal variances assumption seems
warranted, set the option to `equal`. Default: `unequal`.
Returns
-------
out: Object
Test result object.
out.alpha: number
Used significance level.
out.rejected: boolean
Test decision.
out.pValue: number
p-value of the test.
out.statistic: number
Value of test statistic.
out.ci: Array<number>
1-alpha confidence interval for the mean.
out.nullValue: number
Assumed difference in means under H0.
out.xmean: number
Sample mean of `x`.
out.ymean: number
Sample mean of `y`.
out.alternative: string
Alternative hypothesis (`two-sided`, `less` or `greater`).
out.df: number
Degrees of freedom.
out.method: string
Name of test.
out.print: Function
Function to print formatted output.
Examples
--------
// Student's sleep data:
> var x = [ 0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0.0, 2.0 ];
> var y = [ 1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4 ];
> var out = {{alias}}( x, y )
{
rejected: false,
pValue: ~0.079,
statistic: ~-1.861,
ci: [ ~-3.365, ~0.205 ],
// ...
}
// Print table output:
> var table = out.print()
Welch two-sample t-test
Alternative hypothesis: True difference in means is not equal to 0
pValue: 0.0794
statistic: -1.8608
95% confidence interval: [-3.3655,0.2055]
Test Decision: Fail to reject null in favor of alternative at 5%
significance level
// Choose a different significance level than `0.05`:
> out = {{alias}}( x, y, { 'alpha': 0.1 });
> table = out.print()
Welch two-sample t-test
Alternative hypothesis: True difference in means is not equal to 0
pValue: 0.0794
statistic: -1.8608
90% confidence interval: [-3.0534,-0.1066]
Test Decision: Reject null in favor of alternative at 10% significance level
// Perform one-sided tests:
> out = {{alias}}( x, y, { 'alternative': 'less' });
> table = out.print()
Welch two-sample t-test
Alternative hypothesis: True difference in means is less than 0
pValue: 0.0397
statistic: -1.8608
df: 17.7765
95% confidence interval: [-Infinity,-0.1066]
Test Decision: Reject null in favor of alternative at 5% significance level
> out = {{alias}}( x, y, { 'alternative': 'greater' });
> table = out.print()
Welch two-sample t-test
Alternative hypothesis: True difference in means is greater than 0
pValue: 0.9603
statistic: -1.8608
df: 17.7765
95% confidence interval: [-3.0534,Infinity]
Test Decision: Fail to reject null in favor of alternative at 5%
significance level
// Run tests with equal variances assumption:
> x = [ 2, 3, 1, 4 ];
> y = [ 1, 2, 3, 1, 2, 5, 3, 4 ];
> out = {{alias}}( x, y, { 'variance': 'equal' });
> table = out.print()
Two-sample t-test
Alternative hypothesis: True difference in means is not equal to 0
pValue: 0.8848
statistic: -0.1486
df: 10
95% confidence interval: [-1.9996,1.7496]
Test Decision: Fail to reject null in favor of alternative at 5%
significance level
// Test for a difference in means besides zero:
> var rnorm = {{alias:@stdlib/random/base/normal}}.factory({ 'seed': 372 });
> x = new Array( 100 );
> for ( i = 0; i < x.length; i++ ) {
... x[ i ] = rnorm( 2.0, 3.0 );
... }
> y = new Array( 100 );
> for ( i = 0; i < x.length; i++ ) {
... y[ i ] = rnorm( 1.0, 3.0 );
... }
> out = {{alias}}( x, y, { 'difference': 1.0, 'variance': 'equal' })
{
rejected: false,
pValue: ~0.642,
statistic: ~-0.466,
ci: [ ~-0.0455, ~1.646 ],
// ...
}
See Also
--------
|