@sjcrh/proteinpaint-shared 2.145.1-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 +22 -10
package/package.json
CHANGED
package/src/descriptive.stats.js
CHANGED
|
@@ -32,12 +32,9 @@ export function getDescriptiveStats(array) {
|
|
|
32
32
|
const min = sorted_arr[0]
|
|
33
33
|
const max = sorted_arr[sorted_arr.length - 1]
|
|
34
34
|
|
|
35
|
-
// Calculate
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
// Identify outliers
|
|
40
|
-
const outlierRange = { min: lowerFence, max: upperFence }
|
|
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
|
|
41
38
|
|
|
42
39
|
return {
|
|
43
40
|
total: n,
|
|
@@ -50,14 +47,18 @@ export function getDescriptiveStats(array) {
|
|
|
50
47
|
variance,
|
|
51
48
|
stdDev,
|
|
52
49
|
IQR,
|
|
53
|
-
|
|
50
|
+
outlierMin,
|
|
51
|
+
outlierMax
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
export function summaryStats(array) {
|
|
55
|
+
export function summaryStats(array, showOutlierRange = false) {
|
|
58
56
|
const stats = getDescriptiveStats(array)
|
|
57
|
+
return summaryStatsFromStats(stats, showOutlierRange)
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
export function summaryStatsFromStats(stats, showOutlierRange = false) {
|
|
61
|
+
const result = {
|
|
61
62
|
values: [
|
|
62
63
|
{ id: 'total', label: 'Total', value: stats.total },
|
|
63
64
|
{ id: 'min', label: 'Minimum', value: roundValueAuto(stats.min, true) },
|
|
@@ -71,6 +72,13 @@ export function summaryStats(array) {
|
|
|
71
72
|
{ id: 'IQR', label: 'Inter-quartile range', value: roundValueAuto(stats.IQR, true) }
|
|
72
73
|
]
|
|
73
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
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
function computePercentile(values, percentile) {
|
|
@@ -86,7 +94,11 @@ export function getMean(data) {
|
|
|
86
94
|
export function getVariance(data) {
|
|
87
95
|
const meanValue = getMean(data)
|
|
88
96
|
const squaredDifferences = data.map(value => Math.pow(value - meanValue, 2))
|
|
89
|
-
|
|
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)
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
export function getStdDev(data) {
|