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
|
{{alias}}( x[, y][, options] )
Computes a one-sample or paired Student's t test.
When no `y` is supplied, the function performs a one-sample t-test for the
null hypothesis that the data in array or typed array `x` is drawn from a
normal distribution with mean zero and unknown variance.
When array or typed array `y` is supplied, the function tests whether the
differences `x - y` come from a normal distribution with mean zero and
unknown variance via the paired t-test.
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>
Data array.
y: Array<number> (optional)
Paired 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)
Indicates whether the alternative hypothesis is that the mean of `x` is
larger than `mu` (`greater`), smaller than `mu` (`less`) or equal to
`mu` (`two-sided`). Default: `'two-sided'`.
options.mu: number (optional)
Hypothesized true mean under the null hypothesis. Set this option to
test whether the data comes from a distribution with the specified `mu`.
Default: `0`.
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 mean under H0 (or difference in means when `y` is supplied).
out.alternative: string
Alternative hypothesis (`two-sided`, `less` or `greater`).
out.df: number
Degrees of freedom.
out.mean: number
Sample mean of `x` or `x - y`, respectively.
out.sd: number
Standard error of the mean.
out.method: string
Name of test.
out.print: Function
Function to print formatted output.
Examples
--------
// One-sample t-test:
> var rnorm = {{alias:@stdlib/random/base/normal}}.factory( 0.0, 2.0, { 'seed': 5776 });
> var x = new Array( 100 );
> for ( var i = 0; i < x.length; i++ ) {
... x[ i ] = rnorm();
... }
> var out = {{alias}}( x )
{
rejected: false,
pValue: ~0.722,
statistic: ~0.357,
ci: [~-0.333,~0.479],
// ...
}
// Paired t-test:
> rnorm = {{alias:@stdlib/random/base/normal}}.factory( 1.0, 2.0, { 'seed': 786 });
> x = new Array( 100 );
> var y = new Array( 100 );
> for ( i = 0; i < x.length; i++ ) {
... x[ i ] = rnorm();
... y[ i ] = rnorm();
... }
> out = {{alias}}( x, y )
{
rejected: false,
pValue: ~0.191,
statistic: ~1.315,
ci: [ ~-0.196, ~0.964 ],
// ...
}
// Print formatted output:
> var table = out.print()
Paired t-test
Alternative hypothesis: True difference in means is not equal to 0
pValue: 0.1916
statistic: 1.3148
df: 99
95% confidence interval: [-0.1955,0.9635]
Test Decision: Fail to reject null in favor of alternative at 5%
significance level
// Choose custom significance level:
> arr = [ 2, 4, 3, 1, 0 ];
> out = {{alias}}( arr, { 'alpha': 0.01 });
> table = out.print()
One-sample t-test
Alternative hypothesis: True mean is not equal to 0
pValue: 0.0474
statistic: 2.8284
df: 4
99% confidence interval: [-1.2556,5.2556]
Test Decision: Fail to reject null in favor of alternative at 1%
significance level
// Test for a mean equal to five:
> var arr = [ 4, 4, 6, 6, 5 ];
> out = {{alias}}( arr, { 'mu': 5 })
{
rejected: false,
pValue: 1,
statistic: 0,
ci: [ ~3.758, ~6.242 ],
// ...
}
// Perform one-sided tests:
> arr = [ 4, 4, 6, 6, 5 ];
> out = {{alias}}( arr, { 'alternative': 'less' });
> table = out.print()
One-sample t-test
Alternative hypothesis: True mean is less than 0
pValue: 0.9998
statistic: 11.1803
df: 4
95% confidence interval: [-Infinity,5.9534]
Test Decision: Fail to reject null in favor of alternative at 5%
significance level
> out = {{alias}}( arr, { 'alternative': 'greater' });
> table = out.print()
One-sample t-test
Alternative hypothesis: True mean is greater than 0
pValue: 0.0002
statistic: 11.1803
df: 4
95% confidence interval: [4.0466,Infinity]
Test Decision: Reject null in favor of alternative at 5% significance level
See Also
--------
|