クラスカル・ウォリス検定電卓
このクラスカル・ウォリス検定計算ツールは、3 つ以上の独立したサンプルの中央値を比較します。これは、一元配置分散分析のノンパラメトリック バージョンです。
下のセルに最大 5 つのサンプルの値を入力し、「計算」ボタンを押すだけです。
サンプル1
サンプル2
サンプル3
サンプル4
サンプル5
H 統計: 6.59806
p値: 0.03692
//create function that performs calculations function calc() {
//get raw data for each group var group_a = document.getElementById('a').value.split(',').map(Number); var group_b = document.getElementById('b').value.split(',').map(Number); var group_c = document.getElementById('c').value.split(',').map(Number); var group_d = document.getElementById('d').value.split(',').map(Number); var group_e = document.getElementById('e').value.split(',').map(Number);
//define addition function function add(a, b) { return a + b; }
//define function to perform kruskal-wallis test function kruskal() {
var ngroups = arguments.length, groupRankSums = new Array( ngroups ), groupsIndicators = [], i, j, arg, n = [], N, x = [], ranks, ties, tieSumTerm, key, s, stat_placeholder, stat, param, pval;
if ( ngroups < 2 ) { throw new Error( 'kruskal()::invalid number of input arguments. Must provide at least two array-like arguments. Value: `' + arg + '`.' ); } for ( i = 0; i < ngroups; i++ ) { arg = arguments[ i ]; n[ i ] = arg.length; groupRankSums[ i ] = 0; for ( j = 0; j < n[ i ]; j++ ) { groupsIndicators.push( i ); x.push( arg[ j ] ); } } N = x.length; var sorted = x.slice().sort(function(a,b){return a-b}); var reversed = sorted.slice(0).reverse(); ranks = x.slice().map(function(v){ return ((sorted.indexOf(v) + 1) + (reversed.length - reversed.indexOf(v))) / 2;}); // calculate # ties for each value & rank sums per group ties = {}; for ( i = 0; i < N; i++ ) { groupRankSums[ groupsIndicators[ i ] ] += ranks[ i ]; if ( x[ i ] in ties ) { ties[ x[ i ] ] += 1; } else { ties[ x[ i ] ] = 1; } } // calculate test statistic using short-cut formula rank_squares = groupRankSums.map(function(x) { return Math.pow(x, 2); }); rank_squares_sum = (rank_squares.map(function(x, i) { return x / n[i]; })).reduce(add, 0); stat = (12/(N*(N+1))) * rank_squares_sum - 3*(N+1); param = ngroups - 1; pval = 1 - jStat.chisquare.cdf(stat, param); return { 'H': stat, 'df': param, 'pValue': pval, }; } // end FUNCTION kruskal() if (group_a.length > 1) { var flag_group_a = 1; } else { var flag_group_a = 0;}; if (group_b.length > 1) { var flag_group_b = 1; } else { var flag_group_b = 0;}; if (group_c.length > 1) { var flag_group_c = 1; } else { var flag_group_c = 0;}; if (group_d.length > 1) { var flag_group_d = 1; } else { var flag_group_d = 0;}; if (group_e.length > 1) { var flag_group_e = 1; } else { var flag_group_e = 0;};
var total_treatments = [flag_group_a, flag_group_b, flag_group_c, flag_group_d, flag_group_e].reduce(add, 0);
var out;
if (total_treatments == 2) { out = kruskal(group_a, group_b); } else if (total_treatments == 3) { out = kruskal(group_a, group_b, group_c); } else if (total_treatments == 4) { out = kruskal(group_a, group_b, group_c, group_d); } else if (total_treatments == 5){ out = kruskal(group_a, group_b, group_c, group_d, group_e); }
var H = out[Object.keys(out)[0]]; var p = out[Object.keys(out)[2]];
//--------------OUTPUT RESULTS-----------//
document.getElementById('H').innerHTML = H.toFixed(5); document.getElementById('p').innerHTML = p.toFixed(5); }