卡方拟合优度检验计算器
卡方拟合优度检验用于确定分类变量是否遵循假设分布。
要执行卡方拟合优度检验,只需在下面的框中输入最多 10 个类别的观察值和预期值列表,然后单击“计算”按钮:
类别 | 观察到的 | 预期的 |
---|---|---|
第 1 类 | ||
第2类 | ||
第3类 | ||
第 4 类 | ||
第五类 | ||
第六类 | ||
第7类 | ||
第8类 |
检验统计量 x 2 : 4.360000
p 值: 0.359472
function calc() {
//get input data var o1 = document.getElementById('o1').value; var o2 = document.getElementById('o2').value; var o3 = document.getElementById('o3').value; var o4 = document.getElementById('o4').value; var o5 = document.getElementById('o5').value; var o6 = document.getElementById('o6').value; var o7 = document.getElementById('o7').value; var o8 = document.getElementById('o8').value;
var e1 = document.getElementById('e1').value; var e2 = document.getElementById('e2').value; var e3 = document.getElementById('e3').value; var e4 = document.getElementById('e4').value; var e5 = document.getElementById('e5').value; var e6 = document.getElementById('e6').value; var e7 = document.getElementById('e7').value; var e8 = document.getElementById('e8').value;
var obs = [o1, o2, o3, o4, o5, o6, o7, o8]; var empties = obs.length - obs.filter(String).length; var df = 7 - empties;
//do calculations var diff1 = 0; if (o1) { o1 = +o1; e1 = +e1; diff1 = Math.pow(o1-e1,2) / e1; } var diff2 = 0; if (o2) { o2 = +o2; e2 = +e2; diff2 = Math.pow(o2-e2,2) / e2; } var diff3 = 0; if (o3) { o3 = +o3; e3 = +e3; diff3 = Math.pow(o3-e3,2) / e3; } var diff4 = 0; if (o4) { o4 = +o4; e4 = +e4; diff4 = Math.pow(o4-e4,2) / e4; } var diff5 = 0; if (o5) { o5 = +o5; e5 = +e5; diff5 = Math.pow(o5-e5,2) / e5; } var diff6 = 0; if (o6) { o6 = +o6; e6 = +e6; diff6 = Math.pow(o6-e6,2) / e6; } var diff7 = 0; if (o7) { o7 = +o7; e7 = +e7; diff7 = Math.pow(o7-e7,2) / e7; } var diff8 = 0; if (o8) { o8 = +o8; e8 = +e8; diff8 = Math.pow(o8-e8,2) / e8; }
var errors = [diff1, diff2, diff3, diff4, diff5, diff6, diff7, diff8]; var X2 = math.sum(errors); var p = 1-jStat.chisquare.cdf(X2, df);
//output results document.getElementById('X2').innerHTML = X2.toFixed(6); document.getElementById('p').innerHTML = p.toFixed(6);
} //end calc function