We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 55e6c11 commit 1cc22c3Copy full SHA for 1cc22c3
package.json
@@ -1,6 +1,6 @@
1
{
2
"name": "labkar-algorithms",
3
- "version": "5.3.1",
+ "version": "5.3.3",
4
"description": "Labkar Algorithms",
5
"main": "dist/lib.js",
6
"author": "ODTÜ PAL",
src/algorithms/q-hampel.ts
const { jStat } = require('jstat');
import { median } from 'simple-statistics';
-import { get, sortBy, sumBy, round, sortedUniq, findIndex } from 'lodash';
+import { get, sortBy, sumBy, round, sortedUniq, findIndex, uniq } from 'lodash';
import { Result } from '../types';
@@ -22,6 +22,15 @@ export function Q(
22
): Result {
23
const { precision } = options;
24
25
+ if (!results.length) {
26
+ throw new Error('At least one test result is required to calculate Q');
27
+ }
28
+
29
+ // If all values are the same, return the first value
30
+ if (uniq(results).length === 1) {
31
+ return { value: results[0] };
32
33
34
const values: number[] = ([] as number[]).concat(results).sort();
35
36
let deltas = [];
@@ -36,6 +45,8 @@ export function Q(
45
const sortedUniqueDeltas = sortedUniq(sortedDeltas);
37
46
const hMultiplier = 2 / (results.length * (results.length - 1));
38
47
48
+ console.log(JSON.stringify({ sortedDeltas, sortedUniqueDeltas }, null, 2));
49
39
50
const calculations: Q_Calculation[] = [];
40
51
41
52
for (let i = 0; i < sortedUniqueDeltas.length; i++) {
@@ -53,6 +64,8 @@ export function Q(
53
64
});
54
65
}
55
66
67
+ console.log(calculations);
68
56
69
// START OF Q Calc.
57
70
const firstParameter = calculations[0].h1 * 0.75 + 0.25;
58
71
const secondParameter = calculations[0].h1 * 0.375 + 0.625;
src/grubbs/index.ts
@@ -1,4 +1,4 @@
-import { average, standardDeviation } from 'simple-statistics';
+import { average, sampleStandardDeviation } from 'simple-statistics';
import criticalValueTable from './criticalValueTable';
export type GrubbsResult = {
@@ -17,7 +17,7 @@ export function grubbs(
17
originOptions: { alpha: number }
18
): GrubbsResult[] {
19
if (typeof originDataSet === 'undefined') {
20
- throw new Error('dataSet MUST be passed');
+ throw new Error('dataSet MUST be passed');
21
} else if (originDataSet.filter(isValidData).length > 500) {
throw new Error('dataSet.length MUST less than 500');
} else if (originDataSet.filter(isValidData).length <= 2) {
@@ -58,7 +58,7 @@ export function grubbs(
done = true;
59
currentRound = {};
60
currentRound.dataSet = dataSet.slice();
61
- currentRound.stdev = standardDeviation(
+ currentRound.stdev = sampleStandardDeviation(
62
currentRound.dataSet.filter(isValidData)
63
);
currentRound.average =
tests/algorithms.test.ts
@@ -63,6 +63,26 @@ describe('Algorithms', () => {
// expect(output.hampel).toBeCloseTo(44.722, 3);
+ it('Q/Hampel Method (samples with no variance)', () => {
+ const samples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
+ const q = Q(samples);
+ const hampel = Hampel(samples, q.value);
72
+ expect(q.value).toBe(1);
73
+ expect(hampel.value).toBe(1);
74
+ });
75
76
+ it.only('Q/Hampel Method (samples with low variance)', () => {
77
+ const samples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1.1, 1, 1, 1, 1, 1, 1];
78
79
80
81
82
+ expect(q.value).toBeCloseTo(1.0040785270846, 4);
83
+ expect(hampel.value).toBeCloseTo(0.040785270845889, 4);
84
85
86
it('Hampel Method', () => {
87
const samples = [
88
41.41, 39.22, 47.29, 82.46, 45.24, 49.96, 38.2, 45.41, 39.82, 48.17,
tests/grubbs.test.ts
@@ -8,7 +8,22 @@ describe('Grubbs test', () => {
8
9
10
expect(result[0].outlierIndexes).toEqual([4]);
11
- expect(result[0].stdev).toEqual(29.7);
+ expect(result[0].stdev).toBeCloseTo(31.31, 2);
12
13
14
+ it('Only -60 is outlier in this group', () => {
15
+ const results = grubbs([-60, -55.6, -54.7, -54.6, -54.5, -54.4, -54.1], {
16
+ alpha: 0.01,
+ // console.log(results);
+ // Find all outlier indexes
+ const outlierIndexes = results
+ .map((result) => result.outlierIndexes)
+ .flat();
+ expect(outlierIndexes).toEqual([0]);
it.skip('calculates for %1', () => {
0 commit comments