Skip to content

Commit 6530781

Browse files
burakodabasaozisik
andauthored
Cochran (#7)
* feat: add cochran outline function * feat: find squareDeviations * feat: calculating c value * feat: n & p value added * feat: cochran algorithm finished ✅ * test: cochran test added ✅ * fix: some style change, refactor code * feat: cochranCriticalValue 1/2 created * feat: cochran critival value finish 1/1 ✅ * fix: cochran algorithm update by new criticalValues * test: cochran test add & finish ✅ * set generatedCode to es5 * refactor cochran method * move cochran test to separate file * rename nonoutlier to correct Co-authored-by: Ahmet Özışık <ozisikahmet@gmail.com>
1 parent 9bcf9e3 commit 6530781

File tree

6 files changed

+541
-0
lines changed

6 files changed

+541
-0
lines changed

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default [
1717
file: `${name}.js`,
1818
format: 'cjs',
1919
sourcemap: true,
20+
generatedCode: 'es5',
2021
},
2122
],
2223
}),

src/algorithms/cochran.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { get } from 'lodash';
2+
import { CochranResult } from '../types';
3+
import { standardDeviation } from 'simple-statistics';
4+
import cochranCriticalValues from './cochranCriticalValues';
5+
6+
export function Cochran(values: Array<number[]>): CochranResult | null {
7+
/* p -> numune sayısı */
8+
const pValue = values.length;
9+
10+
/* n -> yapılan tekrar,test sayısı */
11+
const nValue = values[0].length;
12+
13+
const onePercentCriticalValue = get(
14+
cochranCriticalValues,
15+
`${nValue}.1%.${pValue}`
16+
);
17+
18+
const fivePercentCriticalValue = get(
19+
cochranCriticalValues,
20+
`${nValue}.5%.${pValue}`
21+
);
22+
23+
if (!onePercentCriticalValue || !fivePercentCriticalValue) {
24+
return null;
25+
}
26+
27+
const squareDeviations = values
28+
.map((value) => {
29+
return standardDeviation(value);
30+
})
31+
.map((value) => {
32+
return value * value;
33+
});
34+
35+
const maxDeviation = Math.max.apply(null, squareDeviations);
36+
const sumOfSquareDeviations = squareDeviations.reduce((a, b) => a + b, 0);
37+
38+
const cValue = maxDeviation / sumOfSquareDeviations;
39+
40+
if (cValue < fivePercentCriticalValue) {
41+
return CochranResult.Correct;
42+
}
43+
44+
if (cValue < onePercentCriticalValue && cValue > fivePercentCriticalValue) {
45+
return CochranResult.Straggler;
46+
}
47+
48+
if (cValue > onePercentCriticalValue) {
49+
return CochranResult.Outlier;
50+
}
51+
52+
return null;
53+
}

0 commit comments

Comments
 (0)