弗里德曼测试计算器
Friedman 检验是重复测量的单向方差分析的非参数替代方法。当因变量为序数时,它用于测试组之间的差异。
要对给定数据集执行弗里德曼检验,只需在下面的单元格中输入最多五个样本的值,然后按“计算”按钮即可。
计算器将显示 Q 检验统计量、检验 p 值以及用于导出 Q 检验统计量的计算。
第 1 组 | 第2组 | 第3组 | 第4组 | 第5组 |
---|---|---|---|---|
Q 检验统计量:
p 值:
解决方案
Q=
Q=
Q=
//create function that performs calculations function calc() {
//define addition function function add(a, b) { return a + b; }
//define function that can flatten a multi-dimensional array function flatten(arr) { return arr.reduce(function (flat, toFlatten) { return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); }, []); }
//get total number of rows var row_input = document.getElementsByClassName('table_span_a'); var row_array = []; for (var i = 0; i < row_input.length; i++) { row_array[i] = row_input[i].innerText; } values_row = row_array.filter(n => n); var n = values_row.length;
//create massive for loop that gets ranks for every single row all_data = [];
for (var i = 0; i < n; i++) { var p = "p" var p_number = i-(-1); var str = p.concat(p_number); str = str.replace(/ +/g, ""); //get row data var p1_input = document.getElementsByClassName(str); var p1_array = []; for (var j = 0; j < p1_input.length; j++) { p1_array[j] = p1_input[j].innerText; } values_p1 = p1_array.filter(n => n); var p1 = values_p1.map(Number);
//sort row data var sorted = p1.slice().sort(function(a,b){return a-b}) var reversed = sorted.slice(0).reverse(); var frac_rank = p1.slice().map(function(n) { return ( (sorted.indexOf(n) + 1) + (reversed.length - reversed.indexOf(n)) ) / 2 });
//push sorted row data to total data array all_data.push(frac_rank);
} //end massive for loop that ranks every row
//find total treatments var k = all_data[0].length;
//flatten multi-dimensional array into one long array flat_data = flatten(all_data);
//find sum of ranks for each treatment var a = [], b = [], c = [], d = [], e = [], total_squared_ranks;
if (k == 2) { for (i = 0; i < flat_data.length; i+= k) { a.push(flat_data[i]); } for (i = 1; i < flat_data.length; i+= k) { b.push(flat_data[i]); } var sum_a_squared = Math.pow(a.reduce(add, 0), 2); var sum_b_squared = Math.pow(b.reduce(add, 0), 2); total_squared_ranks = [sum_a_squared, sum_b_squared].reduce(add, 0); } if (k == 3) { for (i = 0; i < flat_data.length; i+= k) { a.push(flat_data[i]); } for (i = 1; i < flat_data.length; i+= k) { b.push(flat_data[i]); } for (i = 2; i < flat_data.length; i+= k) { c.push(flat_data[i]); } var sum_a_squared = Math.pow(a.reduce(add, 0), 2); var sum_b_squared = Math.pow(b.reduce(add, 0), 2); var sum_c_squared = Math.pow(c.reduce(add, 0), 2); total_squared_ranks = [sum_a_squared, sum_b_squared, sum_c_squared].reduce(add, 0); } if (k == 4) { for (i = 0; i < flat_data.length; i+= k) { a.push(flat_data[i]); } for (i = 1; i < flat_data.length; i+= k) { b.push(flat_data[i]); } for (i = 2; i < flat_data.length; i+= k) { c.push(flat_data[i]); } for (i = 3; i < flat_data.length; i+= k) { d.push(flat_data[i]); } var sum_a_squared = Math.pow(a.reduce(add, 0), 2); var sum_b_squared = Math.pow(b.reduce(add, 0), 2); var sum_c_squared = Math.pow(c.reduce(add, 0), 2); var sum_d_squared = Math.pow(d.reduce(add, 0), 2); total_squared_ranks = [sum_a_squared, sum_b_squared, sum_c_squared, sum_d_squared].reduce(add, 0); } if (k == 5) { for (i = 0; i < flat_data.length; i+= k) { a.push(flat_data[i]); } for (i = 1; i < flat_data.length; i+= k) { b.push(flat_data[i]); } for (i = 2; i < flat_data.length; i+= k) { c.push(flat_data[i]); } for (i = 3; i < flat_data.length; i+= k) { d.push(flat_data[i]); } for (i = 4; i < flat_data.length; i+= k) { e.push(flat_data[i]); } var sum_a_squared = Math.pow(a.reduce(add, 0), 2); var sum_b_squared = Math.pow(b.reduce(add, 0), 2); var sum_c_squared = Math.pow(c.reduce(add, 0), 2); var sum_d_squared = Math.pow(d.reduce(add, 0), 2); var sum_e_squared = Math.pow(e.reduce(add, 0), 2); total_squared_ranks = [sum_a_squared, sum_b_squared, sum_c_squared, sum_d_squared, sum_e_squared].reduce(add, 0); } //final calculations for critical value and p value q_term1 = 12 / (n*k*(k-(-1))); q_term3 = 3*n*(k-(-1)); q = (q_term1 * total_squared_ranks) - q_term3; p = 1 - jStat.chisquare.cdf(q, k-1); //output results document.getElementById('q').innerHTML = q.toFixed(5); document.getElementById('p').innerHTML = p.toFixed(5); document.getElementById('solution1').innerHTML = "(12/(nk(k+1)) * (∑R2) - 3n(k+1)"; document.getElementById('solution2').innerHTML = q_term1 + " * " + total_squared_ranks.toFixed(1) + " - " + q_term3; document.getElementById('solution3').innerHTML = q.toFixed(5); } //end calc() function