@sjcrh/proteinpaint-shared 2.143.0 → 2.145.2
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.
- package/package.json +1 -1
- package/src/descriptive.stats.js +49 -13
package/package.json
CHANGED
package/src/descriptive.stats.js
CHANGED
|
@@ -2,7 +2,7 @@ import { roundValueAuto } from './roundValue.js'
|
|
|
2
2
|
|
|
3
3
|
/* This file generates summary statistics on any given array of numbers*/
|
|
4
4
|
|
|
5
|
-
export function
|
|
5
|
+
export function getDescriptiveStats(array) {
|
|
6
6
|
//console.log("array:",array)
|
|
7
7
|
let arr = array
|
|
8
8
|
if (typeof array[0] == 'string') {
|
|
@@ -31,22 +31,54 @@ export function summaryStats(array) {
|
|
|
31
31
|
const IQR = p75 - p25
|
|
32
32
|
const min = sorted_arr[0]
|
|
33
33
|
const max = sorted_arr[sorted_arr.length - 1]
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
// Calculate outlier boundaries
|
|
36
|
+
const outlierMin = p25 - 1.5 * IQR //p25 is same as q1
|
|
37
|
+
const outlierMax = p75 + 1.5 * IQR //p75 is same as q3
|
|
35
38
|
|
|
36
39
|
return {
|
|
40
|
+
total: n,
|
|
41
|
+
min,
|
|
42
|
+
max,
|
|
43
|
+
p25,
|
|
44
|
+
p75,
|
|
45
|
+
median,
|
|
46
|
+
mean,
|
|
47
|
+
variance,
|
|
48
|
+
stdDev,
|
|
49
|
+
IQR,
|
|
50
|
+
outlierMin,
|
|
51
|
+
outlierMax
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function summaryStats(array, showOutlierRange = false) {
|
|
56
|
+
const stats = getDescriptiveStats(array)
|
|
57
|
+
return summaryStatsFromStats(stats, showOutlierRange)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function summaryStatsFromStats(stats, showOutlierRange = false) {
|
|
61
|
+
const result = {
|
|
37
62
|
values: [
|
|
38
|
-
{ id: 'total', label: 'Total', value:
|
|
39
|
-
{ id: 'min', label: 'Minimum', value: roundValueAuto(min, true) },
|
|
40
|
-
{ id: 'p25', label: '1st quartile', value: roundValueAuto(p25, true) },
|
|
41
|
-
{ id: 'median', label: 'Median', value: roundValueAuto(median, true) },
|
|
42
|
-
{ id: 'mean', label: 'Mean', value: roundValueAuto(mean, true) },
|
|
43
|
-
{ id: 'p75', label: '3rd quartile', value: roundValueAuto(p75, true) },
|
|
44
|
-
{ id: 'max', label: 'Maximum', value: roundValueAuto(max, true) },
|
|
45
|
-
{ id: 'SD', label: 'Standard deviation', value: roundValueAuto(stdDev, true) },
|
|
46
|
-
{ id: 'variance', label: 'Variance', value: roundValueAuto(variance, true) },
|
|
47
|
-
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(IQR, true) }
|
|
63
|
+
{ id: 'total', label: 'Total', value: stats.total },
|
|
64
|
+
{ id: 'min', label: 'Minimum', value: roundValueAuto(stats.min, true) },
|
|
65
|
+
{ id: 'p25', label: '1st quartile', value: roundValueAuto(stats.p25, true) },
|
|
66
|
+
{ id: 'median', label: 'Median', value: roundValueAuto(stats.median, true) },
|
|
67
|
+
{ id: 'mean', label: 'Mean', value: roundValueAuto(stats.mean, true) },
|
|
68
|
+
{ id: 'p75', label: '3rd quartile', value: roundValueAuto(stats.p75, true) },
|
|
69
|
+
{ id: 'max', label: 'Maximum', value: roundValueAuto(stats.max, true) },
|
|
70
|
+
{ id: 'SD', label: 'Standard deviation', value: roundValueAuto(stats.stdDev, true) },
|
|
71
|
+
{ id: 'variance', label: 'Variance', value: roundValueAuto(stats.variance, true) },
|
|
72
|
+
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(stats.IQR, true) }
|
|
48
73
|
]
|
|
49
74
|
}
|
|
75
|
+
if (showOutlierRange) {
|
|
76
|
+
result.values.push(
|
|
77
|
+
{ id: 'outlierMin', label: 'Outlier min', value: roundValueAuto(stats.outlierMin, true) },
|
|
78
|
+
{ id: 'outlierMax', label: 'Outlier max', value: roundValueAuto(stats.outlierMax, true) }
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
return result
|
|
50
82
|
}
|
|
51
83
|
|
|
52
84
|
function computePercentile(values, percentile) {
|
|
@@ -62,7 +94,11 @@ export function getMean(data) {
|
|
|
62
94
|
export function getVariance(data) {
|
|
63
95
|
const meanValue = getMean(data)
|
|
64
96
|
const squaredDifferences = data.map(value => Math.pow(value - meanValue, 2))
|
|
65
|
-
|
|
97
|
+
//Using n−1 compensates for the fact that we're basing variance on a sample mean,
|
|
98
|
+
// which tends to underestimate true variability. The correction is especially important with small sample sizes,
|
|
99
|
+
// where dividing by n would significantly distort the variance estimate.
|
|
100
|
+
// For more details see https://en.wikipedia.org/wiki/Bessel%27s_correction
|
|
101
|
+
return squaredDifferences.reduce((sum, value) => sum + value, 0) / (data.length - 1)
|
|
66
102
|
}
|
|
67
103
|
|
|
68
104
|
export function getStdDev(data) {
|