均值差异计算器的置信区间
- x 1 , x 2 :样本 1 的平均值,样本 2 的平均值
- t:基于置信水平的 t 临界值
- sp 2 :分组方差
- n 1 , n 2 : 样本量 1, 样本量 2
95 % CI = [ -2.0049 , 3.6049 ]
function calc() {
//get input values var x1 = +document.getElementById('x1').value; var s1 = +document.getElementById('s1').value; var n1 = +document.getElementById('n1').value; var x2 = +document.getElementById('x2').value; var s2 = +document.getElementById('s2').value; var n2 = +document.getElementById('n2').value; var conf = +document.getElementById('conf').value;
var confUse = conf - (-(1-conf)/2); var confOut = conf*100; var df = n1 - (-1*n2) - 2; var s2p = ((n1-1)*(Math.pow(s1,2)) - ((-1*(n2-1))*Math.pow(s2,2))) / df;
//calculate stuff var meanDiff = x1-x2; var t = jStat.studentt.inv(confUse, df); var se = Math.sqrt((s2p/n1) - (-1*s2p/n2));
var low = meanDiff - (t*se); var high = meanDiff - (-1*t*se); console.log(s2p);
//output results document.getElementById('confOut').innerHTML = confOut; document.getElementById('confOut2').innerHTML = confOut; document.getElementById('low').innerHTML = low.toFixed(4); document.getElementById('low2').innerHTML = low.toFixed(4); document.getElementById('high').innerHTML = high.toFixed(4); document.getElementById('high2').innerHTML = high.toFixed(4); }