フリードマン テスト電卓
フリードマン検定は、反復測定による一元配置分散分析に代わるノンパラメトリックな検定です。従属変数が順序変数である場合に、グループ間の差異をテストするために使用されます。
特定のデータセットに対してフリードマン検定を実行するには、下のセルに最大 5 つのサンプルの値を入力し、[計算] ボタンを押すだけです。
計算機には、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