Skip to content

Commit c1108f3

Browse files
committed
Add README
1 parent a2cbb76 commit c1108f3

File tree

1 file changed

+177
-0
lines changed
  • lib/node_modules/@stdlib/stats/incr/grubbs

1 file changed

+177
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# incrgrubbs
22+
23+
> [Grubbs' test][grubbs-test] for outliers.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var incrgrubbs = require( '@stdlib/stats/incr/grubbs' );
37+
```
38+
39+
#### incrgrubbs( \[options] )
40+
41+
Returns an accumulator `function` which incrementally performs [Grubbs' test][grubbs-test] for outliers.
42+
43+
```javascript
44+
var accumulator = incrgrubbs();
45+
```
46+
47+
The function accepts the following `options`:
48+
49+
- **alpha**: significance level. Default: `0.05`.
50+
51+
- **alternative**: alternative hypothesis. The option may be one of the following values:
52+
53+
- `'two-sided'`: test whether the minimum or maximum value is an outlier.
54+
- `'min'`: test whether the minimum value is an outlier.
55+
- `'max'`: test whether the maximum value is an outlier.
56+
57+
Default: `'two-sided'`.
58+
59+
- **init**: number of data points the accumulator should use to compute initial statistics **before** testing for an outlier. Until the accumulator is provided the number of data points specified by this option, the accumulator returns `null`. Default: `100`.
60+
61+
#### accumulator( \[x] )
62+
63+
If provided an input value `x`, the accumulator function returns updated test results. If not provided an input value `x`, the accumulator function returns the current test results.
64+
65+
```javascript
66+
var rnorm = require( '@stdlib/random/base/normal' );
67+
68+
var opts = {
69+
'init': 0
70+
};
71+
var accumulator = incrgrubbs( opts );
72+
73+
var results = accumulator( rnorm( 10.0, 5.0 ) );
74+
// returns null
75+
76+
results = accumulator( rnorm( 10.0, 5.0 ) );
77+
// returns null
78+
79+
results = accumulator( rnorm( 10.0, 5.0 ) );
80+
// returns <Object>
81+
82+
results = accumulator();
83+
// returns <Object>
84+
```
85+
86+
The accumulator function returns an `object` having the following fields:
87+
88+
- **rejected**: boolean indicating whether the null hypothesis should be rejected.
89+
- **alpha**: significance level.
90+
- **criticalValue**: critical value.
91+
- **statistic**: test statistic.
92+
- **df**: degrees of freedom.
93+
- **mean**: sample mean.
94+
- **sd**: corrected sample standard deviation.
95+
- **min**: minimum value.
96+
- **max**: maximum value.
97+
- **alt**: alternative hypothesis.
98+
- **method**: method name.
99+
- **print**: method for pretty-printing test output.
100+
101+
The `print` method accepts the following options:
102+
103+
- **digits**: number of digits after the decimal point. Default: `4`.
104+
- **decision**: `boolean` indicating whether to print the test decision. Default: `true`.
105+
106+
</section>
107+
108+
<!-- /.usage -->
109+
110+
<section class="notes">
111+
112+
## Notes
113+
114+
- [Grubbs' test][grubbs-test] **assumes** that data is normally distributed. Accordingly, one should first **verify** that the data can be _reasonably_ approximated by a normal distribution before applying the [Grubbs' test][grubbs-test].
115+
- The accumulator must be provided **at least** three data points before performing [Grubbs' test][grubbs-test]. Until at least three data points are provided, the accumulator returns `null`.
116+
- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the test statistic is `NaN` for **all** future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function.
117+
118+
</section>
119+
120+
<!-- /.notes -->
121+
122+
<section class="examples">
123+
124+
## Examples
125+
126+
<!-- eslint no-undef: "error" -->
127+
128+
```javascript
129+
var incrgrubbs = require( '@stdlib/stats/incr/grubbs' );
130+
131+
var data;
132+
var opts;
133+
var acc;
134+
var i;
135+
136+
// Define a data set (8 mass spectrometer measurements of a uranium isotope; see Tietjen and Moore. 1972. "Some Grubbs-Type Statistics for the Detection of Several Outliers".)
137+
data = [ 199.31, 199.53, 200.19, 200.82, 201.92, 201.95, 202.18, 245.57 ];
138+
139+
// Create a new accumulator:
140+
opts = {
141+
'init': data.length,
142+
'alternative': 'two-sided'
143+
};
144+
acc = incrgrubbs( opts );
145+
146+
// Update the accumulator:
147+
for ( i = 0; i < data.length; i++ ) {
148+
acc( data[ i ] );
149+
}
150+
151+
// Print the test results:
152+
console.log( acc().print() );
153+
/* e.g., =>
154+
Grubbs' Test
155+
156+
Alternative hypothesis: The maximum value (245.57) is an outlier
157+
158+
criticalValue: 2.1266
159+
statistic: 2.4688
160+
df: 6
161+
162+
Test Decision: Reject null in favor of alternative at 5% significance level
163+
164+
*/
165+
```
166+
167+
</section>
168+
169+
<!-- /.examples -->
170+
171+
<section class="links">
172+
173+
[grubbs-test]: https://en.wikipedia.org/wiki/Grubbs%27_test_for_outliers
174+
175+
</section>
176+
177+
<!-- /.links -->

0 commit comments

Comments
 (0)