//get input values
var x = document.getElementById('x').value*1;
var n = document.getElementById('n').value*1;
var conf = (1 - document.getElementById('conf').value/100)/2;
var z = Math.abs(jStat.normal.inv(conf, 0, 1));
//find estimates
var mle = x/n;
var wilson = (x - ((-z*z)/2)) / (n - (-z*z));
var jeffrey = (x - (-.5)) / (n - (-1));
var laplace = (x - (-1)) / (n - (-2));
//find best estimate
var val = x/n;
var best = x/n;
if (val <= 0.5) {
best = wilson;
} else if (val < 0.9) {
best = mle;
} else if (val < 1) {
best = Math.min(laplace, jeffrey);
} else {
best = laplace;
}
//output results
document.getElementById('best').innerHTML = best.toFixed(5);
document.getElementById('mle').innerHTML = mle.toFixed(5);
document.getElementById('wilson').innerHTML = wilson.toFixed(5);
document.getElementById('jeffrey').innerHTML = jeffrey.toFixed(5);
document.getElementById('laplace').innerHTML = laplace.toFixed(5);
}