Kontinuitätskorrekturrechner
P(X = 3 ): 0,23040
P(X ≤ 3 ): 0,92196
P(X < 3 ): 0,68256
P( X≥3 ): 0,31744
P(X > 3 ): 0,08704
P( 2,5 <X < 3,5 ): 0,23040
P(X< 3,5 ): 0,92196
P(X < 2,5 ): 0,68256
P(X > 2,5 ): 0,31744
P(X > 3,5 ): 0,08704
function binomialCalc() {
//get input values var X = document.getElementById('X').value; var p = document.getElementById('p').value; var n = document.getElementById('n').value;
//calculate cumulative probabilities var probArray = []; for (var i = 0; i <= X; i++) { probArray[i] = (math.factorial(n) / (math.factorial(n-i) * math.factorial(i))) * Math.pow(p, i) * Math.pow((1-p), (n-i)); } //assign probabilities to variable names var exactProb = (math.factorial(n) / (math.factorial(n-X) * math.factorial(X))) * Math.pow(p, X) * Math.pow((1-p), (n-X)); var lessEqualProb = math.sum(probArray); var lessProb = lessEqualProb - exactProb; var greaterEqualProb = 1 - lessProb; var greaterProb = 1 - lessEqualProb; //output probabilities document.getElementById('exactProb').innerHTML = exactProb.toFixed(5); document.getElementById('lessEqualProb').innerHTML = lessEqualProb.toFixed(5); document.getElementById('lessProb').innerHTML = lessProb.toFixed(5); document.getElementById('greaterEqualProb').innerHTML = greaterEqualProb.toFixed(5); document.getElementById('greaterProb').innerHTML = greaterProb.toFixed(5); //change X to reflect value that user entered document.getElementsByClassName('user_X')[0].innerHTML = X; document.getElementsByClassName('user_X')[1].innerHTML = X; document.getElementsByClassName('user_X')[2].innerHTML = X; document.getElementsByClassName('user_X')[3].innerHTML = X; document.getElementsByClassName('user_X')[4].innerHTML = X; //find correct continuity correction values var user_X1 = X-.5; var user_X2 = X-(-.5); var user_X3 = X-(-.5); var user_X4 = X-.5; var user_X5 = X-.5; var user_X6 = X-(-.5); //apply continuity correction values document.getElementById('user_X1').innerHTML = (user_X1).toFixed(1); document.getElementById('user_X2').innerHTML = (user_X2).toFixed(1); document.getElementById('user_X3').innerHTML = (user_X3).toFixed(1); document.getElementById('user_X4').innerHTML = (user_X4).toFixed(1); document.getElementById('user_X5').innerHTML = (user_X5).toFixed(1); document.getElementById('user_X6').innerHTML = (user_X6).toFixed(1); //find z scores var mean_z = n*p; var stdev_z = Math.sqrt(n*p*(1-p)); //find z-scores var approxProb1 = jStat.normal.cdf(user_X2, mean_z, stdev_z) - jStat.normal.cdf(user_X1, mean_z, stdev_z); var approxProb2 = jStat.normal.cdf(user_X3, mean_z, stdev_z); var approxProb3 = jStat.normal.cdf(user_X4, mean_z, stdev_z); var approxProb4 = 1-jStat.normal.cdf(user_X5, mean_z, stdev_z); var approxProb5 = 1-jStat.normal.cdf(user_X6, mean_z, stdev_z); //output probabilities document.getElementById('approxProb1').innerHTML = approxProb1.toFixed(5); document.getElementById('approxProb2').innerHTML = approxProb2.toFixed(5); document.getElementById('approxProb3').innerHTML = approxProb3.toFixed(5); document.getElementById('approxProb4').innerHTML = approxProb4.toFixed(5); document.getElementById('approxProb5').innerHTML = approxProb5.toFixed(5); }