x = 22;
others = [27, 43, 17, 5];
Прочитал про среднеквадратичное отклонение, не уверен что это то что мне нужно, но реализовал так:
function deviationFromOthers(data, x) {
const others = data.filter(v => v !== x);
const mean = others.reduce((s, v) => s + v, 0) / others.length;
const variance = others.reduce((s, v) => {
const d = v - mean;
return s + d * d;
}, 0) / others.length;
const std = Math.sqrt(variance);
return {
delta: x - mean,
z: (x - mean) / std
};
}
console.log(deviationFromOthers([27, 43, 17, 5], 22)); // {delta: -1, z: -0.07179581586177382}
-0.071 это много или мало, или вообще ничего не значит на таком незначительном наборе данных?