I had previously posted an app to make calculations based on gaussian curves. This post extends that to an app written in HTML and Javascript, making it cross platform without the installation of special software.
It also automatically does calculations for male and female height, bmi of children and IQ. These are based on U.S. statistics, so they may not hold for other countries. If you want it to hold for another country, you will need to change the median values. The height input can be either meters or inches, depending on the state of the checkbox.
Here is the code:
<html xmlns=’http://www.w3.org/1999/xhtml’>
<head profile=’http://gmpg.org/xfn/11′>
<title>Gauss</title>
<style type=’text/css’>
body {margin-left:0;margin-right:0;font:normal normal normal 12px Arial;}
a{ text-decoration: }
:link { color: rgb(0, 0, 255) }
:visited {color :rgb(100, 0,100) }
:hover { }
:active { }
#l1{position: absolute; left:10px ; top:10px ; width:360px ; height:240px ;background:#EEEEEE; padding: 10px; border: 4px ridge}
input{position: relative; border: 4px inset }
select{position: relative}
</style>
function calc() {
if(document.getElementById(“items”).value == “Male Height”) {
document.getElementById(“t2”).value = 69;
document.getElementById(“t3”).value = 2.8;
} else if(document.getElementById(“items”).value == “Female Height”) {
document.getElementById(“t2”).value = 64;
document.getElementById(“t3”).value = 2.8;
} else if(document.getElementById(“items”).value == “IQ”) {
document.getElementById(“t2”).value = 100;
document.getElementById(“t3”).value = 15;
} else if(document.getElementById(“items”).value == “BMI Children”) {
document.getElementById(“t2”).value = 18;
document.getElementById(“t3”).value = 3.0;
}
var wd = document.getElementById(“t3”).value;
var x = document.getElementById(“t1”).value;
if (document.getElementById(“c1”).checked) x *= 39;
var cnt = document.getElementById(“t2”).value;
var pop = document.getElementById(“t5”).value;
var pop2 = document.getElementById(“t5”).value;
var cdf = (1 – (.5 *(1 + erf((x – cnt) / (wd * Math.sqrt(2)))))) * 100;if (cdf >= 1) {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(1) + ” %”;
} else if (cdf >= .1) {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(2) + ” %”;
} else if (cdf >= .01) {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(3) + ” %”;
} else if (cdf >= .001) {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(4) + ” %”;
} else if (cdf >= .0001) {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(5) + ” %”;
} else {
document.getElementById(“t4″).value = ” ” + (100-cdf).toFixed(6) + ” %”;
}
pop = cdf/100 * pop;
document.getElementById(“t6″).value = ” ” + Math.floor(pop2 – pop);
}
function erf(z) {
var t = 1.0 / (1.0 + 0.5 * Math.abs(z));
var ans = 1 – t * Math.exp( -z*z – 1.26551223 +
t * ( 1.00002368 +
t * ( 0.37409196 +
t * ( 0.09678418 +
t * (-0.18628806 +
t * ( 0.27886807 +
t * (-1.13520398 +
t * ( 1.48851587 +
t * (-0.82215223 +
t * ( 0.17087277))))))))));
if (z >= 0) {
return ans;
} else {
return -ans;
}
}
</head>
<body>
Median
Standard Deviation
%” /> % > or % Population
#” /> # > or #
Calculate
ItemMale HeightFemale HeightIQBMI Children
Height entered in meters
</body>
</html>
The interface consists of a layer with six text input boxes, a button, a select box and a checkbox:
Median
Standard Deviation
%” /> % > or % Population
#” /> # > or #
Calculate
ItemMale HeightFemale HeightIQBMI Children
Height entered in meters
On clicking the Calculate button, the function calc() is called, which initially sets the default values:
if(document.getElementById(“items”).value == “Male Height”) {
document.getElementById(“t2”).value = 69;
document.getElementById(“t3”).value = 2.8;
} else if(document.getElementById(“items”).value == “Female Height”) {
document.getElementById(“t2”).value = 64;
document.getElementById(“t3”).value = 2.8;
} else if(document.getElementById(“items”).value == “IQ”) {
document.getElementById(“t2”).value = 100;
document.getElementById(“t3”).value = 15;
} else if(document.getElementById(“items”).value == “BMI Children”) {
document.getElementById(“t2”).value = 18;
document.getElementById(“t3”).value = 3.0;
}
It then takes the input values:
var wd = document.getElementById(“t3”).value;
var x = document.getElementById(“t1”).value;
if (document.getElementById(“c1”).checked) x *= 39;
var cnt = document.getElementById(“t2”).value;
var pop = document.getElementById(“t5”).value;
var pop2 = document.getElementById(“t5”).value;
It then performs the calculation using the return value of the function erf():
var cdf = (1 – (.5 *(1 + erf((x – cnt) / (wd * Math.sqrt(2)))))) * 100;
function erf(z) {
var t = 1.0 / (1.0 + 0.5 * Math.abs(z));
var ans = 1 – t * Math.exp( -z*z – 1.26551223 +
t * ( 1.00002368 +
t * ( 0.37409196 +
t * ( 0.09678418 +
t * (-0.18628806 +
t * ( 0.27886807 +
t * (-1.13520398 +
t * ( 1.48851587 +
t * (-0.82215223 +
t * ( 0.17087277))))))))));
if (z >= 0) {
return ans;
} else {
return -ans;
}
}
Finally, the result is outputted:
if (cdf >= 1) {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(1) + ” % > ” + (100-cdf).toFixed(1) + ” %”;
} else if (cdf >= .1) {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(2) + ” % > ” + (100-cdf).toFixed(2) + ” %”;
} else if (cdf >= .01) {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(3) + ” % > ” + (100-cdf).toFixed(3) + ” %”;
} else if (cdf >= .001) {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(4) + ” % > ” + (100-cdf).toFixed(4) + ” %”;
} else if (cdf >= .0001) {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(5) + ” % > ” + (100-cdf).toFixed(5) + ” %”;
} else {
document.getElementById(“t4″).value = ” < ” + cdf.toFixed(6) + ” % > ” + (100-cdf).toFixed(6) + ” %”;
}
pop = cdf/100 * pop;
document.getElementById(“t6″).value = ” < ” + Math.floor(pop) + ” > ” + Math.floor(pop2 – pop);
}
Here is how the app appears for a calculation of women 6 ft tall:
Click image for larger view
Here is how it appears for women 5 ft. tall:
Click image for larger view