function
test(inputData) {
let wholeData = [];
for
(
let i = 0;
i < inputData.length;
i++
) {
wholeData = wholeData.concat(
inputData[i]
);
}
wholeData.sort((a, b) => a - b);
const position = {};
let currentPosition = 1;
for
(
let i = 0;
i < wholeData.length;
i++
) {
if
(
i > 0 &&
wholeData[i] !==
wholeData[i - 1]
) {
currentPosition++;
}
position[wholeData[i]] =
currentPosition;
}
let sumRanks = [];
for
(
let i = 0;
i < inputData.length;
i++
) {
let sum = 0;
for
(
let j = 0;
j < inputData[i].length;
j++
) {
sum +=
position[
inputData[i][j]
];
}
sumRanks.push(sum);
}
const n = wholeData.length;
const k = inputData.length;
const H =
(12 / (n * (n + 1))) *
(sumRanks.reduce(
(acc, curr) =>
acc + curr ** 2,
0
) -
(n * (n + 1) ** 2) / 4);
const df = k - 1;
const pValue = 1 - Math.exp(-H);
return
{ H, df, pValue };
}
const group1 = [
12, 14, 16, 19, 20, 21, 22, 23, 25,
27, 28,
];
const group2 = [
10, 11, 15, 18, 22, 24, 26, 28, 29,
30,
];
const group3 = [
8, 9, 13, 17, 19, 21, 24, 26, 28,
30, 32,
];
const result = test([
group1,
group2,
group3,
]);
console.log(
"Test Statistic (H):"
,
result.H
);
console.log(
"Degrees of Freedom (df):"
,
result.df
);
console.log(
"p-Value:"
, result.pValue);