@datagrok/curves 1.12.2 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/CLAUDE.md +118 -15
  3. package/README.md +51 -4
  4. package/dist/package-test.js +8819 -5223
  5. package/dist/package-test.js.map +1 -1
  6. package/dist/package.js +3014 -1659
  7. package/dist/package.js.map +1 -1
  8. package/files/demo/Assay_Curves.csv +43 -43
  9. package/package.json +2 -2
  10. package/scripts/calculateMSR.py +16 -7
  11. package/src/fit/data-to-curves.ts +11 -6
  12. package/src/fit/fit-chart-data.ts +330 -0
  13. package/src/fit/fit-grid-cell-handler.ts +102 -235
  14. package/src/fit/fit-inspection.ts +3 -3
  15. package/src/fit/fit-interaction.ts +181 -0
  16. package/src/fit/fit-layout.ts +64 -0
  17. package/src/fit/fit-legend.ts +292 -0
  18. package/src/fit/fit-options.ts +222 -0
  19. package/src/fit/fit-parser.ts +16 -5
  20. package/src/fit/fit-renderer.ts +180 -469
  21. package/src/fit/fit-statistics.ts +154 -0
  22. package/src/fit/multi-curve-viewer.ts +48 -22
  23. package/src/fit/render-utils.ts +208 -150
  24. package/src/package-api.ts +78 -0
  25. package/src/package-test.ts +7 -0
  26. package/src/package.g.ts +59 -11
  27. package/src/package.ts +97 -18
  28. package/src/tests/calculated-columns-tests.ts +299 -0
  29. package/src/tests/converter-tests.ts +23 -0
  30. package/src/tests/curve-data.ts +82 -0
  31. package/src/tests/fit-cache-tests.ts +128 -0
  32. package/src/tests/fit-tests.ts +344 -4
  33. package/src/tests/legend-tests.ts +243 -0
  34. package/src/tests/multi-curve-viewer-tests.ts +100 -0
  35. package/src/tests/panel-renderer-tests.ts +502 -0
  36. package/src/tests/project-tests.ts +99 -0
  37. package/src/tests/statistics-tests.ts +127 -0
  38. package/src/tests/transform-tests.ts +3 -2
  39. package/test-console-output-1.log +410 -109
  40. package/test-record-1.mp4 +0 -0
@@ -0,0 +1,127 @@
1
+ import {tTest, uTest} from '@datagrok-libraries/statistics/src/tests';
2
+ import {fdrcorrection} from '@datagrok-libraries/statistics/src/multiple-tests';
3
+ import {category, test, expect, expectArray, expectFloat,
4
+ expectExceptionAsync} from '@datagrok-libraries/test/src/test';
5
+
6
+ // References are computed from the textbook formulae, not read back off this library: sample (n-1)
7
+ // variances, Welch-Satterthwaite dof, and t = (m1 - m2) / sqrt(v1/n1 + v2/n2).
8
+ const A = [1, 2, 3, 4, 5];
9
+ const B = [2, 4, 6, 8, 10];
10
+ const EPS = 1e-12;
11
+
12
+ // R's p.adjust(p, method = 'BH'): the running minimum, taken from the largest p downwards, of
13
+ // n/(i+1) * p_i. Independent of alpha - only `reject` depends on it.
14
+ const P = [0.001, 0.008, 0.039, 0.041, 0.042, 0.06, 0.074, 0.205, 0.212, 0.216];
15
+ const ADJUSTED = [0.01, 0.04, 0.084, 0.084, 0.084, 0.1, 0.10571428, 0.216, 0.216, 0.216];
16
+
17
+ category('statistics', () => {
18
+ test('tTest: the Welch branch uses the sample variance', async () => {
19
+ const r = tTest(A, B);
20
+ expectFloat(r['p-value'], 0.10753119493044197, EPS);
21
+ expectFloat(r['p-value less'], 0.053765597465220985, EPS);
22
+ expectFloat(r['Mean difference']!, -3, EPS);
23
+ // the population variance, which is what jStat returns without the flag, puts this at 0.0790
24
+ expect(r['p-value'] > 0.1);
25
+ });
26
+
27
+ test('tTest: the equal-variance branch divides by the pooled standard deviation', async () => {
28
+ const r = tTest(A, B, false, true);
29
+ expectFloat(r['p-value'], 0.09434977284244564, EPS);
30
+ expectFloat(r['p-value less'], 0.04717488642122282, EPS);
31
+ });
32
+
33
+ test('tTest: the known-deviation branch reports a tail probability', async () => {
34
+ const r = tTest(A, B, true);
35
+ expectFloat(r['p-value'], 0.05777957112359733, EPS);
36
+ expectFloat(r['p-value less'], 0.028889785561798664, EPS);
37
+ // a density is bounded by 0.3989 and is blind to the direction; a cdf is neither
38
+ expectFloat(tTest(B, A, true)['p-value less'], 1 - r['p-value less'], EPS);
39
+ });
40
+
41
+ test('tTest: the tails complement each other and the two-tailed p is twice the smaller', async () => {
42
+ const results = [tTest(A, B), tTest(A, B, false, true), tTest(A, B, true)];
43
+ for (const r of results) {
44
+ expectFloat(r['p-value less'] + r['p-value more'], 1, EPS);
45
+ expectFloat(r['p-value'], 2 * Math.min(r['p-value less'], r['p-value more']), EPS);
46
+ }
47
+ });
48
+
49
+ test('tTest: a sample of fewer than two values is refused', async () => {
50
+ await expectExceptionAsync(async () => void tTest([1], B), (e) => `${e}`.includes('Wrong sample size'));
51
+ await expectExceptionAsync(async () => void tTest(A, []), (e) => `${e}`.includes('Wrong sample size'));
52
+ });
53
+
54
+ test('uTest: no ties, hand-computable', async () => {
55
+ // ranks 1..10 with x on the odd ones: R1 = 25, U1 = 10, mu = 12.5, s = sqrt(25/12 * 11)
56
+ const r = uTest([1, 3, 5, 7, 9], [2, 4, 6, 8, 10]);
57
+ expectFloat(r['p-value'], 0.6761033140231467, EPS);
58
+ expectFloat(r['p-value less'], 0.33805165701157336, EPS);
59
+ expectFloat(r['p-value more'], 0.6619483429884266, EPS);
60
+ expectFloat(r['Median difference']!, -1, EPS);
61
+ });
62
+
63
+ test('uTest: ties are corrected with the sum of t^3 - t', async () => {
64
+ // xy ranks [1,3,3,5,8,3,6.5,6.5,9,10]: one group of 3 and one of 2, so the term is 24 + 6 = 30.
65
+ // Summing the group sizes instead gives 10 - the sample size - and a p-value of 0.1416.
66
+ const r = uTest([1, 2, 2, 3, 5], [2, 4, 4, 6, 7]);
67
+ expectFloat(r['p-value'], 0.1375638939099033, EPS);
68
+ expectFloat(r['p-value less'], 0.06878194695495166, EPS);
69
+ });
70
+
71
+ test('uTest: the one-tailed fields are one-tailed', async () => {
72
+ const r = uTest([1, 3, 5, 7, 9], [2, 4, 6, 8, 10]);
73
+ expect(r['p-value less'] !== r['p-value more']);
74
+ expectFloat(r['p-value less'] + r['p-value more'], 1, EPS);
75
+ expectFloat(r['p-value'], 2 * Math.min(r['p-value less'], r['p-value more']), EPS);
76
+
77
+ const swapped = uTest([2, 4, 6, 8, 10], [1, 3, 5, 7, 9]);
78
+ expectFloat(swapped['p-value less'], r['p-value more'], EPS);
79
+ expectFloat(swapped['p-value more'], r['p-value less'], EPS);
80
+ expectFloat(swapped['p-value'], r['p-value'], EPS);
81
+ });
82
+
83
+ test('uTest: the two-tailed p never exceeds 1', async () => {
84
+ // the continuity correction used to push U past the mean of its own null distribution
85
+ const r = uTest([1, 2, 3, 4], [1, 2, 3, 4]);
86
+ expectFloat(r['p-value'], 1, EPS);
87
+ expectFloat(r['p-value less'], 0.5, EPS);
88
+ });
89
+
90
+ test('uTest: a sample of fewer than two values is refused', async () => {
91
+ await expectExceptionAsync(async () => void uTest([1], [1, 2, 3]), (e) => `${e}`.includes('Wrong sample size'));
92
+ await expectExceptionAsync(async () => void uTest([1, 2, 3], []), (e) => `${e}`.includes('Wrong sample size'));
93
+ });
94
+
95
+ test('fdrcorrection: adjusted p-values match Benjamini-Hochberg', async () => {
96
+ const [, adjusted] = fdrcorrection(new Float32Array(P), 0.05, 'i');
97
+ for (let i = 0; i < P.length; i++)
98
+ expectFloat(adjusted[i], ADJUSTED[i], 1e-6);
99
+ });
100
+
101
+ test('fdrcorrection: every hypothesis at or below the line is rejected', async () => {
102
+ const alpha = 0.05;
103
+ const [reject, adjusted] = fdrcorrection(new Float32Array(P), alpha, 'i');
104
+ expectArray(reject, [true, true, false, false, false, false, false, false, false, false]);
105
+ // the largest rejected hypothesis used to be dropped, leaving reject out of step with adjusted
106
+ for (let i = 0; i < P.length; i++)
107
+ expect(reject[i], adjusted[i] <= alpha, `hypothesis ${i}`);
108
+ });
109
+
110
+ test('fdrcorrection: a lone passing hypothesis is rejected', async () => {
111
+ const [reject] = fdrcorrection(new Float32Array([0.001, 0.9, 0.9, 0.9]), 0.05, 'i');
112
+ expectArray(reject, [true, false, false, false]);
113
+ });
114
+
115
+ test('fdrcorrection: rejections come back in the caller order', async () => {
116
+ const shuffled = [0.216, 0.008, 0.212, 0.001, 0.042, 0.041, 0.074, 0.039, 0.205, 0.06];
117
+ const [reject, adjusted] = fdrcorrection(new Float32Array(shuffled), 0.05, 'i');
118
+ expectArray(reject, [false, true, false, true, false, false, false, false, false, false]);
119
+ for (let i = 0; i < shuffled.length; i++)
120
+ expectFloat(adjusted[i], ADJUSTED[P.indexOf(shuffled[i])], 1e-6);
121
+ });
122
+
123
+ test('fdrcorrection: nothing is rejected when nothing passes', async () => {
124
+ const [reject] = fdrcorrection(new Float32Array([0.4, 0.5, 0.6]), 0.05, 'i');
125
+ expectArray(reject, [false, false, false]);
126
+ });
127
+ });
@@ -1,7 +1,8 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
 
3
3
  import {Viewport} from '@datagrok-libraries/utils/src/transform';
4
- import {FitChartCellRenderer, layoutChart} from '../fit/fit-renderer';
4
+ import {FitChartCellRenderer} from '../fit/fit-renderer';
5
+ import {layoutChart} from '../fit/fit-layout';
5
6
 
6
7
  import {category, expect, test} from '@datagrok-libraries/test/src/test';
7
8
  import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
@@ -10,7 +11,7 @@ import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
10
11
  category('viewport', () => {
11
12
  test('viewportMethods', async () => {
12
13
  const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(120, 20, 160, 100));
13
- const [dataBox] = layoutChart(screenBounds, false, false);
14
+ const [dataBox] = layoutChart(screenBounds, false, false, false);
14
15
  const dataBounds = new DG.Rect(0.1, 0.06, 7, 5.94);
15
16
  const viewport = new Viewport(dataBounds, dataBox, false, false);
16
17